Learn you some HTTP for fun and glory

We all use HTTP, develop for HTTP and think that we know HTTP. But, I believe as engineers we should never take things for granted; rather we should dissect everything that comes before us, recursively as many times as possible. So, let’s keep applying this principle for HTTP.

cURLing

cURL is a great tool for sending HTTP requests. Let’s try to send one.

Hmm, okay it can do stuff. Let’s make it a bit more verbose shall we? Just add a -v flag.

Ah now things are interesting. Do you see a few lines starting with ‘>’? Well those are the headers that are SENT to the server. And the lines starting with ‘<‘? They are response headers that are received. The last part is the content itself. Of course, the < and > are there for representation only, they are not transmitted.

Telneting

telnet is a great tool to make raw socket connections and really dissect almost any TCP based protocol like HTTP. Lets try this.

Afterwards, type in a raw HTTP request yourself!

Now, press enter or return twice!

Who needs Firefox, Chrome or cURL! Looks like Telnet is all we need 😉 Okay enough jokes for now. This is serious business. You see in the end HTTP is just a plain socket connection that has some specific “lingo” to send requests and receive responses. (Protocol, duh).

Dissecting the Request

Let’s see how exactly we made the request.

Pretty straightforward. The HTTP method in caps, the path and the HTTP version in the first line. After that, the request headers follow. In our case we just mentioned the ‘Host’ header to play safe with VirtualHost-enabled systems.

Back in the days, running a website was expensive because you needed an entire box (a server computer) to host a single website. Then we invented a way to serve multiple websites from the same IP address / machine with virtual hosts in the Apache Web Server.

The internet as we know it exists for this ‘Host’ header.

The two newlines indicate we are done with our request, and the server can parse it and send back a response.

Let’s be bad

Let’s send a malformed HTTP request (muhahaha).

Afterwards, type in a malformed request yourself!

Now, press enter or return twice!

Yup 🙁 It was a Bad Request. We’ll write our own HTTP server with plain old sockets soon. Till then, why not explore the exciting world of HTTP response headers on Google 😉 Yeah and take a look at RFC 2616.

3 thoughts on “Learn you some HTTP for fun and glory”

  1. i love ur way bro , obviously i am ur follower .. i have seen u on nsu but my Soul doesn’t support to met such a guy with poor level of knowledge hats off boss!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.