HTTP & Headers

In notebook:
FrontEndMasters Networking and Streams
Created at:
backend Fundamentals

hypertext transfer protocol

It's an easy protocol to type out. It's fairly readable and tolerant text based commands.

http verbs

HTTP requests begin with a VERB. Here are some things each VERB is used for:

  • GET - fetch a document
  • POST - submit a form
  • HEAD - fetch metadata about a document
  • PUT - upload a file

These are typical examples, of how you would them. For example POST is often used to upload a file, because of network proxies that won't allow PUT. You also have DELETE etc. that are less used.

http headers

Next come the headers.

Headers have a key followed by a colon followed by a value:

key: value

So for example, this would look like this


using netcat:

$ nc 80
GET / HTTP/1.0

So we have the Host: header. It tells what domain you want to access. A server can host multiple domains or a load balancer scenario.

Make sure to hit return twice after Host: This is how the server knows that you are done You can have multiple headers and then you close it by two newlines to tell the server you are done.

Then you get back your response:

The body is separated from the headers by an empty line:

HTTP/1.0 301 Moved Permanently
Location:  ☛ just set up like this
Content-Type: text/html; charset=UTF-8 ☛ type of content (html)
Date: Mon, 12 Jan 2015 01:26:19 GMT ☛ for cache control (When to fetch new version)
Expires: Wed, 11 Feb 2015 01:26:19 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219 ☛ tells you how long the body will be
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic,p=0.02

<HTML><HEAD><meta http-equiv="content-type"
<H1>301 Moved</H1>
The document has moved
<A HREF="">here</A>.

301 moves permanent move...

if you want to fetch other types of documents

$ nc 80
GET /favicon.ico HTTP/1.0

☛ double enter

(he gets a 404...)