HTTP is the protocol which powers the Internet. I’m a web developer (allegedly), but I didn’t really know much about HTTP until I read the HTTP Pocket Reference. HTTP is simple, text based and stateless. A client (web browser) issues a request, and the server issues a response.
If you want to see the full gore of what’s going install Fiddler. It lets you inspect all the traffic going between your browser and the server, measure performance, and lots of other stuff. Using fiddler I’ve captured a typical http request and response hitting the front page of this website.
First the request:
The first line of the request is the really important one. It consists of the Method, URI and HTTP version. The two main request methods are GET and POST. GET requests a document from the server, POST submits information to the server. Other request methods are: HEAD, PUT, LINK, UNLINK, DELETE, OPTIONS and TRACE. In practice these aren’t used much by web developers. The URI is the location you want to send the request too, in this case “/” means the root of the web site. HTTP/1.1 is the norm, and you are extremely unlikely to see anything else. HTTP 1.0 is archaic, and HTTP 1.2 never got out of committee.
Next the response:
The response has three sections: header, blank line and content. The type of the content is indicated by the “Content-type” line in the header, in this case it is HTML. Another common content-type is gzip, which the browser would decompress before rendering. The first line of the header has three parts: http-version, status-code and reason phrase. In this case the status code is 200 which means OK. The status codes are split into ranges which define their general meaning:
101 Switching Protocols
|300-399||Redirect||301 Permanent Redirect
304 Not Modified
|400-499||Request Incomplete||403 Forbidden
404 Not Found
|500-599||Server Error||500 Internal Server Error|
So that’s the basics of http. The plain text of the protocol makes it easy to see what’s going on. You can imagine parsing the response and implementing a primitive web browser. More than that though, the bit which really bowls me over, is the blank line in the response message. A stroke of genius.