================================================================================ |It's suprisingly easy to use gopher and http without a proper client. | | | |To access gopher: | | | |The default port is 70, so use that if one is not specified. | |To access gopher://host:port/0,1/path in your terminal, type this: | ================================================================================ telnet host port /path ================================================================================ |Then, the document should show up on your terminal. You may also type path | |without the slash, which will also work. | | | |to access gopher://host:port/7/path?query (a search query), type this: | ================================================================================ telnet host port /path<tab>query ================================================================================ |<tab> is the tab key (You can also use a "?" instead in some cases.). | | | |To access HTTP: | | | |The default port is 80, so use that if one is not specified. | |to access http://host:port/path?query in your terminal, type this: | ================================================================================ telnet host port GET /path?query ================================================================================ |You have to press enter twice after typing the last line, but then you will | |get the file you asked the web server for. | | | |You can also use the "long format" which lets you send headers. Headers are | |little pieces of information about how the connection is carried out. For | |example, you could send "Connection: keep-alive", which will tell the server | |that you want to make another request without closing the connection (You | |wouldn't need to reopen telnet to start with a new request to the same server)| |(It's there just to make things go faster under the hood.) | | | |The one header that is required is "Host: host", where "host" is the same as | |the host you put as the first argument to telnet. It might seem crazy that the| |server doesn't know it's own name, but sometimes one server will serve | |multiple websites at once, so it needs to know which one is which. | | | |Headers are case-insensitive, and spacing doesn't matter, though one space | |is preferred. The standard says "any LWS," so you don't need space characters | |specifically. | | | |A request might look something like this: | ================================================================================ telnet host port GET /path?query HTTP/1.0 Host: host ================================================================================ |Make sure you press enter twice after typing your header (or headers if you | |have multiple). | | | |You can also use HTTP/1.1, which gives you more stuff you can do, but is more | |complicated. It also does "Connection: keep-alive" by default, and to remove | |it, you do "Connection: close", which is the default in HTTP/1.0. The server | |will occasionally decide it doesn't like your header, and do what it wants. | |Not every server cares about your headers. It's a mean world out there. | | | |Let's do a HTTP/1.1 example: | ================================================================================ telnet dread.life 80 GET / HTTP/1.1 Host: dread.life ============================================================ | <-- Press enter twice. The following is from the server. | HTTP/1.1 200 OK ============================================================ Connection: keep-alive Content-Length: 1104 Content-Type: text/html Date: Sun, 15 Apr 2018 20:06:57 GMT Last-Modified: Sun, 15 Apr 2018 19:48:13 GMT Server: OpenBSD httpd =========================================== | <-- Headers end here. File starts here. | <!DOCTYPE=html> =========================================== <html> <head> <meta charset="utf-8"> <title>Homepage of the Dabmancer</title> <link rel="stylesheet" href="/style.css"> <body> <ul class="navbar"> <li class="navbar"><a href="/">Home</a></li> <li class="navbar"> <a href="http://gopher.floodgap.com/gopher/gw.lite?gopher://dread.life:70/1/"> Gopherhole</a></li> <li class="navbar"><a href="/links.html">Links</a></li> </ul> <h3>Welcome to my website.</h3> <p>The "Gopherhole" tab will take you to my gopherhole, which is like a website, but is on the gopher protocol, rather than http. It will get you there through a http-to-gopher proxy, so you can just use your regular web browser instead of a special gopher client.</p> <p>"Links" is a page that has links to websites I find useful or interesting. If I keep going back to it, it will end up on that page.</p> </body> </html> ================================================================================ |Make sure that you press enter twice after every HTTP request. | | | |The first thing a server gives you is an error code. It worked right, so it | |gave us an "OK." | | | |As you can see, the server returns headers, too, before giving you your html | |file. You know what a connection header is. Content-length is the length of | |the file, in bytes. The alternative to content-length is "Transfer-Encoding: | |Chunked", which is where the file is transmitted in increments, with the size | |of the increment on its own line above the increment. It's useful for files | |that are generated on-the-fly. "Content-Type:" is usually "text/html" or | |"text/plain", but there are special content types for images and video. | |"Date" and "Last-Modified" are pretty self-explanatory. "Server" is the | |HTTP server you're using to transmit things. Usually, you'll see nginx or | |Apache, but Google has it's own server. The server can transmit whatever kind | |of wacky headers it wants, so don't be suprised if you see something that | |is completely nonstandard. | | | |If you want to use ssl/tls (e.g. like you need to for https), replace "telnet | |host port" with "openssl s_client -connect host:port" This will work with | |http, but should work with gopher over ssl or tls as well. I just haven't seen| |a server that uses gopher+tls, and I don't know what the port would be. | | | |The gopher part of this tutorial was pretty comprehensive, but I only covered | |HTTP's GET requests, even though there are POST, DELETE, PUT, etc. | ================================================================================