Understanding HTTP Response Codes

As part of the HTTP Request Response cycle, When a request is made to your server for a page on your site by the browser or some other client, your server returns an HTTP status code in response to the request.This status code provides information about the status of the request. Some of the most commonly heard of Status Codes are

200 – The request sent by the client was successfully processed and the result was served back.

302 – Refers to the resource having moved Temporarily. It means, The requested resource has been found under a different URI but the client should continue to use the original URI.

404 – File not Found. This means that the document/file requested by the client was not found.

502 – The server received an invalid response from the upstream server while trying to fulfill the request.

Response headers are a way by which the browser understands what happened when the request was sent to the server. In a way, for the browser its a way to identify answer to many questions like Did the server process the request successfully? Do i need to check in some other location? Is the content being sent in ranges? Is the server available at all or not?

There are many tools available using which you can easily identify the headers being sent / received by the browser. Most popular of them are Fiddler ( mainly used for internet explorer) and Live HTTP Headers ( available as a plugin for Firefox).

Lets look at some request and response headers to understand this in more detail. Later we shall also point you to some other interesting references on this. Shown below is the request and response cycle when requesting for www.lifepal.org

REQUEST HEADERS

GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)
Host: www.lifepal.org
Connection: Keep-Alive

RESPONSE HEADERS

HTTP/1.1 200 OK
Date: Fri, 15 Aug 2008 09:56:59 GMT
Server: Apache
X-Powered-By: PHP/5.2.6
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

The above shown block, describes the header information sent and received by the browser. The first line of the Request header is GET / HTTP/1.1 which in turn refers to the process of the Browser asking the server for index.html or index.php or whatever is the default file when www.lifepal.org ( this is known using the Host header information) is asked for content. The server then responds back to the browser with the content and most importantly the response headers. Here, the first line of response headers is HTTP/1.1 200 OK which in turn refers to the server telling the browser ” Everything is OK. Here you go with the content”.

Lets assume another case, wherein the client is asking for the content which the browser doesnt have. For eg. below we tried requesting, hello.html from www.lifepal.org

REQUEST HEADERS

GET /hello.html HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)
Host: www.lifepal.org
Connection: Keep-Alive

RESPONSE HEADERS

HTTP/1.1 404 Not Found
Date: Fri, 15 Aug 2008 10:14:58 GMT
Server: Apache
X-Powered-By: PHP/5.2.6
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Last-Modified: Fri, 15 Aug 2008 10:14:58 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

Above, the server replies back with a 404 HTTP Response Code. The Content Management System or the application can be programmed to serve a specific custom page in case of a 404 is found. The default page is usually something like shown below.

404 Example Page as seen on Internet Explorer

404 Example Page as seen on Internet Explorer

At Lifepal, we have a customized page for 404 error codes. Try looking for www.lifepal.org/hello.html

In general , the Status Codes have following meanings.

1xx ( All HTTP Response Status codes beginning with 1) : Status codes that indicate a provisional response and require the requestor to take action to continue.

2xx ( All HTTP Response Status codes beginning with 2) : Status codes that indicate that the server successfully processed the request.

3xx ( All HTTP Response Status codes beginning with 3) : Further action is needed to fulfill the request. Often, these status codes are used for redirection.

4xx ( All HTTP Response Status codes beginning with 4) : These status codes indicate that there was likely an error in the request which prevented the server from being able to process it.

5xx ( All HTTP Response Status codes beginning with 5) : These status codes indicate that the server had an internal error when trying to process the request. These errors tend to be with the server itself, not with the request.

For a complete listing of all the HTTP Status Codes and what they mean, please read the W3C Page on HTTP Status Code. You can also download HTTP Status Code Information Sheet from here. Source : Suso

Also read: [How-To] Send Annonymous Emails

Learning to Disable and Enable USB Drives

Related posts:

  1. Track your Stolen Laptop for free using Adeona
  2. [How-To] Send Annonymous Emails

One Response to “Understanding HTTP Response Codes”

  1. [...] Posted on August 16, 2008 by Vaibhav Pandey Lifepal has an interesting article about HTTP Response Status Codes. The HTTP request response cycle begins with DNS Lookup and ends with the browser parsing the [...]

Leave a Reply