5 This proposal will use many terms as used in the original Gopher RFC
10 All strings sent have to be in UTF‐8, except for »binary« or »data«.
11 These are binary data streams and should be handled like that. No Byte-
12 Order-Mark (BOM) must be sent.
16 URIs do not allow full UTF‐8 encoding. If for example punycode is used,
17 then the client has to convert them into UTF‐8, so new gopher servers
18 will understand it. UTF-8 should be enforced there.
20 Because of the different type behaviour do the URIs operate without a
21 item type. See the section on how to determine the file type below for
26 Requests can be sent over every transport protocol, which can guarantee
27 the data stream to be correct. No error detection is done in this proto‐
28 col. The main intention for this protocol is it to be used over TCP/IP,
29 using mandatory TLS encryption. TLS should be used over other transport
35 S->C: $size\t$mime-type\r\n
38 The $size line is defining the number of bytes that will follow after
39 the »$size\t$mime‐type\r\n« line. If $size is »‐1«, then the client
40 should listen until the connection is closed.
42 The $mime-type is defining what data will follow.
46 C->S: selector\tsearch\trange\r\n
49 S->C: $size\t$mime-type\r\n
50 [menu/binary/metadata]
52 In a complex request the »\t« in the first retrieve line is seen as flag
53 to retrieve a further line that will tell the server how much data the
54 client will send and what kind of data this will be ($mime‐type). The
55 server may apply rules or selector‐specific rules how much data is al‐
56 lowed to be retrieved by a client.
58 The $size line is defining the number of bytes that will follow after
59 the »$size\t$mime‐type\r\n« line. If $size is »‐1«, then the client
60 should listen until the connection is closed. When clients are sending
61 data, then they are required to specify a valid size.
63 Adding another »\t« to the request allows the client to specify a range
64 of bytes to be retrieved. See the section about ranges for further de‐
69 Every connection to a server could be used for many requests. Servers
70 should implement this, but can apply rules upon how many requests and
71 what requests are allowed when pipelining multiple requests.
73 It is possible for simple servers to close the connection after each re‐
74 quest. Simple clients can close the connection after simple requests
75 too. This may disable certain interactive sessions for these kind of
78 One exception in pipelining is when a selector is has an undefined size.
79 Then the connection must be closed after all data has been sent to the
80 client. Both sides of the connection can close the connection, when a
81 certain rule maximum of bytes is reached.
85 Selectors are UTF‐8 strings. They must not contain the »\0« or »\t«
86 charac‐ ters, to avoid parsing errors. Servers need »\t« for determin‐
87 ing, if the request is a complex request. See the sections below for
90 Selectors must use »/« as path delimiter. This definition is required
91 for automagic file type recognition.
93 Relative selectors (containing a »..« or ».« path element) must not be
94 handled by a server and answered with an error.
98 If a »search« part is given in a request, then this is used when some
99 form of magic script will handle the answer. See the CGI section for how
104 The default value of if »range« part is »‐«, which means to retrieve the
105 selector from its beginning to the end. If the »range« part has a zero
106 length, then the default value is assumed.
110 As seen, $beginning and $end can be of zero length and will be replaced
111 by »0« ($beginning) or the size of the selector data ($end).
113 Both, $beginning and $end must be positive natural numbers.
118 These are possible formats and mean, that the client is requesting in
119 the first case the byte range from the first byte of the data (byte 0)
120 to byte $end; including byte $end. The second example will send to the
121 client byte $beginning to the end of the data.
123 Multiple byte ranges are best served using pipelining and multiple range
124 requests. There is no support for them in one request.
126 If a range cannot be satisfied, see the section about Error Handling how
129 A range of zero bytes can be used to determine the size and mime‐type of
134 There are some special MIME types required for this document.
137 application/x-interactive – interactive
139 The short forms of menu item types must not be used when sending or re‐
144 Each menu item consists of one line. The line must be valid UTF‐8 and
145 consists of the following form.
147 $mime-type\t$name\t$selector\t$searchstring\t$host\t$port\r\n
149 $mime‐type and $name are mandatory for every line. The other parts can
150 be left out, if unspecified and will result in the below specified de‐
151 faults to be applied. If a menu type does not have any use for a menu
152 item part, then it can be left out and ignored.
154 For $mime-type see the section about them below.
156 $name is referring to the text that should be displayed at this position
159 $selector specifies the selector that should be sent to the server, then
160 this is a line pointing back to a server implementing this protocol.
161 See the different menu item types below for exceptions.
163 $searchstring is what should be sent to the server in a complex query as
164 the »search« part. This implies the client to implement complex re‐
167 $host and $port are used when this item type is referring to a server
168 implementing this protocol. If they are empty, then the host or port
169 used to retrieve this menu is used as a replacement.
171 ### Menu Item MIME types
173 The used $mime‐type fields in this protocol can refer not just to MIME
174 types. The history of gopher has shown short item types to be more prac‐
175 tical, but insufficent to handle modern needs. This proposal here is a
176 mix out of both worlds.
178 If the length of the $mime‐type is just one char, then the following
179 item types are assumed:
188 If the $mime‐type is longer than one char, then this is a true MIME type
189 and will be used like that.
193 This type is describing text in the $name field that should be displayed
194 at that position in the menu.
198 The selector of this item will lead to another menu.
200 When requesting this selector, then the $mime‐type of »text/x‐menu« must
205 See the section about search / interactive sessions how to handle these.
207 When requesting this selector, then the $mime‐type of »application/x‐in‐
208 teractive« must be used.
213 When displaying this menu item issuing/clicking it should lead to the
214 URI mentioned in the $selector field and the text in the $name field
215 should be displayed as a description. Handling URIs must be done on the
220 This menu item is describing an error message. The item must be the
221 first item in the menu. See the section on error handling for more de‐
226 Implementing this menu item can be done on server or client side. If the
227 server supports this, then it should parse the menus before sending them
228 and try to determine the real MIME type of the file the selector is re‐
229 ferring to. If this is not possible, then the client has to decide.
231 If the client is supporting this menu type and the »b« type appears,
232 then it should assume this to be of type »application/octet‐stream« and
233 simply store the file.
235 ### Search / Interactive
237 The client is retrieving the selector where the interactive sessions be‐
242 s\tPlease Register!\t/register\r\n
244 A client not willing to interpret this as an interactive session will
245 just retrieve the raw data. Clients willing to interact interpret the
246 following in a new request:
250 s\tNext register step\t/register2\t$metadata\r\n
254 [The user is now shown its favourite text editor, which shows
255 all the given back text, except for the first line. ]
257 The first line of the output is a menu item, which the client should
258 follow after the user applied its changed to the data below it.
260 Data following this first line can be binary and application‐dependent,
261 but it must be valid UTF‐8, if it is text. See the section about sim‐
262 plicity below for how to handle this.
264 When showing the data to the user and it is a text interaction, then
265 filters could apply on the application side or the client side, to add
266 some more descriptive text, that tells the user, that it is possible to
267 abort everything by changing nothing and just leaving the editor. Other
268 binary applications may have different rules.
270 Base on the example, another sub standard could be used to assume the
271 form of »Field: Value« to be a form entry, which is shown in a more
272 graphical way, so users won’t change the key text.
274 Clients should apply filters on redirects to menu items away from the
275 server the interactive session started. It is adviced to not follow them
280 C->S: /register2\t$metadata\r\n
284 E-Mail: me@somewhere.com\n
286 i\tWelcome to this service!\r\n
289 When sending the answer, the client is not sending a line for the redi‐
290 rect. It is sending back the changed data from the user.
292 Interactive sessions may end from the client or server side. The server
293 side must guide the user to a sane end whenever possible.
297 Authors creating interactive sessions are encouraged to keep them sim‐
298 ple. It should be possible to access them using commandline tools. The
299 best way to ensure this is to keep all interaction in valid UTF‐8 and an
300 understandable form. Binary formats make things hard to parse and use
301 without specialized tools.
305 When an error occurs, then the server is sending back a menu with the
306 first element being of type »e«.
308 Upon errors the server is not required to close the connection, if it is
309 not a fatal error that would prevent further serving.
311 Error messages must not be localized and should contain at least some
312 standard messages. The parsing is done using simple string operations.
314 Some predefined error messages that should be used are:
318 Range cannot be satisfied
322 If the server encounters a relative selector:
324 Relative selectors are not allowed
326 When the client did not send enough data:
330 The chameleon of error messages is
332 Internal server error
334 Sending out this error message is allowed but should be avoided at all
339 C->S: /someselector\r\n
341 e\tFile not found\r\n
342 m\tBack to the index\t/\r\n
346 If just a server and selector is given to a client and it tries to de‐
347 termine how to handle the data behind this selector, following algorithm
350 1. See if the mime-type is cached somewhere.
351 2. If the selector is the root of the server, just fetch it and abort,
352 if this is not a type of »m«.
353 3. Use a request with the range of »0-0« to determine the MIME type
355 4. If the MIME type is still »b«, then assume »application/octet-stream«.
360 If scripts are called within a server or a request the following envi‐
361 ronment variables should be provided in the operating system specific
364 By default all variables are unset. Only if relevant information is
365 available they should be set.
367 The value of these variables should be in UTF‐8, unless the operating
368 system would make using this default impractical. Then the possible de‐
369 velopers must be informed about this new assumption.
373 The size of the data sent by the client.
377 The mime‐type the client sent for the request. The default mediatype is
378 UTF‐8. This incompatibility to HTTP CGI is intentional.
380 ### GATEWAY_INTERFACE
382 »CGI/1.1«. This is not really used.
386 This is the selector given by the client.
390 This si the PATH_INFO mapped to the storage where the server is getting
391 the script from. It does not need to be a valid physical path.
395 This should be the »search« part of a complex request.
399 This must be the address of the client requesting an answer in the com‐
400 mon used representation for such an address. If the protocol has no no‐
401 tion of an address, it can be left blank.
405 REMOTE_HOST can contain the fually qualified host of the REMOTE_ADDR.
406 The limitations of the used protocol are applied, so it can be left
411 If the client is providing data, then this is seen as a »POST« request.
412 If no data is provided, then it is a »GET« request.
417 This is the filename or leading path component of the PATH_INFO.
421 SERVER_NAME is the hostname or address of the server. If the protocol
422 this protocol is used on has no notion of address, it must be set to a
427 This is the port on which the request was received. It should be left
428 blank, if no port notion is known in the underlying protocol.
436 This variable describes the server and must include the server software
437 name and version. If no version is known, a funny name must be added.