This is called by processInputBuffer() when an inline request is processed * with Gopher mode enabled, and the request happens to have zero or just one * argument. In such case we get the relevant key and reply using the Gopher * protocol. */
| 49 | * argument. In such case we get the relevant key and reply using the Gopher |
| 50 | * protocol. */ |
| 51 | void processGopherRequest(client *c) { |
| 52 | robj *keyname = c->argc == 0 ? createStringObject("/",1) : c->argv[0]; |
| 53 | robj *o = lookupKeyRead(c->db,keyname); |
| 54 | |
| 55 | /* If there is no such key, return with a Gopher error. */ |
| 56 | if (o == NULL || o->type != OBJ_STRING) { |
| 57 | char *errstr; |
| 58 | if (o == NULL) |
| 59 | errstr = "Error: no content at the specified key"; |
| 60 | else |
| 61 | errstr = "Error: selected key type is invalid " |
| 62 | "for Gopher output"; |
| 63 | addReplyGopherItem(c,"i",errstr,NULL,NULL,0); |
| 64 | addReplyGopherItem(c,"i","Redis Gopher server",NULL,NULL,0); |
| 65 | } else { |
| 66 | addReply(c,o); |
| 67 | } |
| 68 | |
| 69 | /* Cleanup, also make sure to emit the final ".CRLF" line. Note that |
| 70 | * the connection will be closed immediately after this because the client |
| 71 | * will be flagged with CLIENT_CLOSE_AFTER_REPLY, in accordance with the |
| 72 | * Gopher protocol. */ |
| 73 | if (c->argc == 0) decrRefCount(keyname); |
| 74 | |
| 75 | /* Note that in theory we should terminate the Gopher request with |
| 76 | * ".<CR><LF>" (called Lastline in the RFC) like that: |
| 77 | * |
| 78 | * addReplyProto(c,".\r\n",3); |
| 79 | * |
| 80 | * However after examining the current clients landscape, it's probably |
| 81 | * going to do more harm than good for several reasons: |
| 82 | * |
| 83 | * 1. Clients should not have any issue with missing .<CR><LF> as for |
| 84 | * specification, and in the real world indeed certain servers |
| 85 | * implementations never used to send the terminator. |
| 86 | * |
| 87 | * 2. Redis does not know if it's serving a text file or a binary file: |
| 88 | * at the same time clients will not remove the ".<CR><LF>" bytes at |
| 89 | * tne end when downloading a binary file from the server, so adding |
| 90 | * the "Lastline" terminator without knowing the content is just |
| 91 | * dangerous. |
| 92 | * |
| 93 | * 3. The utility gopher2redis.rb that we provide for Redis, and any |
| 94 | * other similar tool you may use as Gopher authoring system for |
| 95 | * Redis, can just add the "Lastline" when needed. |
| 96 | */ |
| 97 | } |
no test coverage detected