HTTP STATUS CODES – By a tale of a man, a refrigerator and an ice cream!
Basics of HTTP protocol
HTTP is a request response protocol where, a client (usually an internet browser) sends a request to a server (Usually running a web-server application like Apache, NGINX) and the server replies back with the requested content. Now, the client server communication is of-course not in plain English like we humans do instead, they speak in a language/protocol called as Hyper Text Transfer Protocol or simply HTTP. When the client sends a HTTP GET request to the server, the server replies back with an HTTP status code in the response. For keeping it short and to the point, I am leaving low level details of this HTTP transaction between the client and a server (Things like HTTP request and response headers, HTTP request methods etc.).
So, we are going to discuss some of the frequently seen HTTP status codes and what do they mean in as simple way, as possible. In the below examples, think of man as the client (Your internet browser), refrigerator as the server (Running web-server application) and ice cream as the resource (A file or any resource on the server’s file system).
HTTP 2xx – Success/All Okay
This status code means that the request from the client was successfully received, understood and accepted.
This is the standard response for successful HTTP requests. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.
HTTP 3xx – Redirection
This status code means that the client needs to take some additional actions to successfully complete the request.
301 Moved Permanently
This request as well as all the future requests should be directed to the new location of the resource communicated to the client, by the server. The server is sends a 301, will always send the new location where the resource can be found.
302 Found, 303 See Other, 307 Temporary Redirect
Tells the client to look at (browse to) another URL. 302 has been superseded by 303 and 307. 303 means that the redirect will be done due to a reason which is not defined and 307 is a temporary redirect and client making subsequent requests for this resource should use the old URI. This SO answer explains it well.
304 Not Modified
This indicates that the resource was not modified on the server since what was initially communicated to the client. This information is handled by two request headers which are known as If-Modified-Since or If-None-Match.
HTTP 4xx – Client Errors
The server will send 4xx error codes if the problem seems to be at the client’s end.
400 Bad Request
The server cannot or will not process the request due to an apparent client error (e.g., malformed request syntax, size too large, invalid request message framing, or deceptive request routing).
This status is received when either the client is not able to prove it’s identity at all, or the client has failed the authentication. It is in a way similar to 403 mentioned below with these differences.
The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account of some sort.
404 Not Found
The resource which the client requested is not actually available on the server, or the client has misspelled the resource name.
407 Proxy Authentication Required
The client must first authenticate itself with the proxy.
This status code is returned when the current state of the resource which was requested by the client does not allow the processing of the request itself.
The resource is no more on the server, and will never exist in the future. Clients such as search engines should remove the resource from their indices and the client should not request the resource in the future.
HTTP 5xx – Server Errors
Response status codes beginning with the digit “5” indicate cases in which the server is aware that it has encountered an error or is otherwise incapable of performing the request.
500 Internal Server Error
The 500 Internal Server Error is a very general HTTP status code that means something has gone wrong on the web site’s server but the server could not be more specific on what the exact problem is.
502 Bad Gateway
The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server. The upstream server can be referred to as any component/entity on which the server depends to perform it’s work and send a response to the client.
503 Temporarily Unavailable
This means that the server is temporarily unavailable to process any request. The causes for this condition could be overloading, maintenance or any other disruption. This is a temporary condition. Please note that if does not always mean that the server will reply with 503 if it’s overloaded however, some servers can simply chose to refuse the connection.
504 Gateway Timeout
The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other server (e.g. DNS) on which the server has to depend in order to complete the request. I have troubleshot a 504 in my this blog post.
Please note that the above pictures (In some cases) might not explain all the HTTP status codes since they are so many. I have tried to explain the most common HTTP status codes with a hope to give the bigger picture!
Hope this helps! I love to hear the feedback! Please comment and share.