« Brainstorming of virtualization possibilities | Main | Pride and Prejudice »

September 23, 2005

Manually Experimenting with HTTP 1.1

I'm taking the "Large-scale Distributed System Design" from Dr. Windley. In teaching us about HTTP he used a telnet session to manually interact with the protocol to illustrate the complete lack of magic and simplicity of the protocol. Here's how he did it.

Using a unix style command line, the session looks something like this:

[devlin@peacemaker]$ telnet host.com 80
Trying 66.239.30.206...
Connected to host.com (66.239.30.204).
Escape character is '^]'.
GET / HTTP/1.0 [return]
               [return]
HTTP/1.1 200 OK
Date: Fri, 23 Sep 2005 23:27:19 GMT
Server: Apache/2.0.52 (Fedora)
Last-Modified: Fri, 23 Sep 2005 23:26:59 GMT
ETag: "1046c6-7f-bf0016c0"
Accept-Ranges: bytes
Content-Length: 85
Connection: close
Content-Type: text/html; charset=UTF-8

Learning about http

Lots of good stuff to talk about here.
Connection closed by foreign host.
[devlin@peacemaker]$

Very cool. So I thought, why not try HTTP/1.1? I first tried by just replacing the HTTP version of the above GET command to HTTP/1.1. This does not work however.

One great feature of HTTP 1.1 is that of virtual hosts. This enables one to have multiple sites hosted on a single IP address. Depending on the hostname of the request, the web server can send back any number of different domains. In order for the server to know which virtual host to respond with, you must specify this in the HTTP request.

The GET request now looks like this:

GET / HTTP/1.1 [return]
Host: foo.com  [return]
               [return]

Another feature of HTTP 1.1 is that a client can issue multiple requests using a single common connection. HTTP 1.0 had to make a separate connection for each request. This is a serious performance issue, a connection would be necessary for each page and for each separate linked element in the page as well, like each image, media sound clip and such. Connections are not cheap to create and have quite a bit of overhead. Some numbers I have seen is that by keeping the connection open, performance for pages with embedded links improved 25%.

According to the Apache documentation, these persistent connections are the default if the client identifies itself as being able to communicate HTTP 1.1. I discovered however, that on Fedora Core 3, the Apache2 http packages shipped with the distro have this option disabled. To enable it, just modify your http.conf file (usually in /etc/httpd/conf/) and change "KeepAlive" directive to:

KeepAlive On

Then, when experimenting with telnet, after you issue the GET command above, the server will not immediately disconnect but will wait a short amount of time to see if you will issue any more requests. This way, you can submit multiple requests using a single connection.

Posted by Devlin at September 23, 2005 05:16 PM

Comments