Under The Hood With HTTP: Part 2 Status Codes
January 3rd, 2008You’re probably already quite familiar with the 404 Status Code for resources that aren’t found. Knowing the status codes can give you some pretty powerful insight into the server side of your app when things go wrong.All Errors fit into the following categories
- 1XX Informational Codes
- 2XX Success Codes
- 3XX Redirection
- 4XX Client Error
- 5XX Server Error
The Codes in More Depth Informational Codes 1XX Informational Codes are unique in that they return no body and terminate immediately after the headers. The most common encountered is “100 Continue”. Continue responses are roughly equivalent to the server saying I haven’t forgotten about you. They imply that everything is fine but that the server isn’t prepared to issue a response yet. If the client is still transmitting data, the client should continue to do so. If the client is done transmitting, it can ignore the response. The server is required to send a normal response in the future. Success Codes 2XX The most common code in this category is 200 OK. This is what you expect to receive in any http transaction. Some other common codes are:
- 202 Accepted: The Server has accepted the request but hasn’t finished processing. It should contain a pointer to more information but isn’t required to do so.
- 204 No Content: The Server has completed the request but there is no need to return a body entity. There may be new meta-data to transmit. Clients should not change their document view when this code is received.
- 206 Partial Content: On Get Requests, this means that the originating GET request included a Range header field and only that range is returned.
3XX Redirection CodesRedirection codes communicate that the previous request was insufficient to complete the request and further action needs to be taken by the client to do so.
- 301 Moved Permanently: The resource has been permanently relocated to a different URI. Any future references should use this new URI. The Response Body should contain a short note in HTML with a link to the new location.
- 307 Temporary Redirect: The resource is temporarily relocated at a new URI. Future references should continue to use the original URI.
4XX Client Error While we’re all familiar with the infamous 404 not found error. There are several other client errors that can be encountered on a regular basis.
- 400 Bad Request: The HTTP Request is malformed. The Client should not repeat the request without modifications
- 401 Unauthorized: Authentication is needed to access the resource
- 403 Forbidden: The Server understood the request but for some reason is refusing to fill it.
- 408 Request Timeout: The Client didn’t complete request in the time the server was willing to give it. The client may try again some other time
Error Code 402 is a unique case. It is reserved for future use and indicated Payment Required
500 Server ErrorsWhile 400 errors imply that the Client was the source of the fault, 500 errors imply a problem with the server. There are 2 that I find a need to wrangle with regularly
- 500 Internal Server Error: Something went wrong and the server is crying uncle
- 503 Service Unavailable: The Server is experiencing technical difficulties. I usually this is caused by a runaway memory leak in apache or by a sudden spike in load that overwhelms the stack.
While I in no way intend for this to be a comprehensive guide to the http response codes, there’s a much better one available from the W3C. I thought this might provide a handy refresh and reference.


