wiki/articles/gopher.md

4.2 KiB

Gopher

Gopher is an hypertext protocol, similar to HTTP but far more simpler and KISS.

Pages using the Gopher protocol are known as "Gopherholes". As of writing this, there are about 200~300 active gopherholes.

Protocol

Compared to other protocols, like HTTP, Gopher is a simple text-based protocol, described in RFC 1436. Gopher does not use encryption, but extensions to it add optional encryption, see below.

Gopher has the port 70 assigned to for its use, and the gopher:// URI protocol. To request a document to a Gopher server, first a TCP connection is opened at port 70 and the called selector string is sent along with a CRLF (\r\n) at the end (servers may also accept a simple \n), then the server should reply with the requested document. The selector is the path of the document on the server. When no selector is specified (so only a CRLF is sent), a default selector is sent to the client, usually a menu (gophermap).

With just netcat, printf and a pipe we can have a minimal client as a proof of concept, like this:

printf '\r\n' | nc 'khzae.net' 70

Gophermap

A Gopher menu (also called Gophermap) follows a basic format, lines with tab separated fields:

type	text	selector	hostname	port

Here is an example of a line describing a selector:

Type Text Selector Hostname Port
1 Bitreich Projects /scm bitreich.org 70

The type field can be any of the following:

Type Description
0 File
1 Directory
2 CSO phonebook server (?)
3 Error
4 BinHex Machintosh (?)
5 DOS binary
6 uuencoded file
7 Index-search server
8 Text Telnet session
9 Binary file (EOF when server closes the connection)
+ Redundant server
T Telnet 3270
g GIF image
I Image, file format unspecified.

And some common extension types:

Type Description
d .doc file
h HTML document
i Informational message
p PNG image
r RTF document
s Sound file, usually .wav
P PDF document
X XML document

A relative link to a document in the same server:

1About	/about	khzae.net	70

Paragraphs can be made with the i type:

i___[ News Aggregator ]	Err	bitreich.org	70

The selector (marked here with a placeholder "Err"), server address and port are ignored.

Finally, a gophermap must end in a . followed by a CRLF on its own line.

Protocol extensions

TODO list extensions

Accessing

"Modern" web browsers are so advanced that can't bother implementing such a trivial protocol, so if you're using a web browser you can use a proxy like https://gopher.floodgap.com/gopher/ that works over HTTP. But for the true experience, you want a text based browser with native support for Gopher such as Lynx or Bitreich's sacc browser.

Notable Gopherholes