HTTP HTTP responses Basic response format


Example

When an HTTP server receives a well-formed HTTP request, it must process the information that request contains and return a response to the client. A simple HTTP 1.1 response, may look like any of the following, usually followed by a number of header fields, and possibly a response body:

HTTP/1.1 200 OK \r\n
HTTP/1.1 404 Not Found \r\n
HTTP/1.1 503 Service Unavailable \r\n

A simple HTTP 1.1 response has this format:

HTTP-Version Status-Code Reason-Phrase CRLF

As in a request, HTTP-Version indicates the version of the HTTP protocol in use; for HTTP 1.1 this must always be the string HTTP/1.1.

Status-Code is a three-digit code that indicates the status of the client's request. The first digit of this code is the status class, which places the status code into one of 5 categories of response [1]:

  • 1xx Informational - the server has received the request and processing is continuing
  • 2xx Success - the server has accepted and processed the request
  • 3xx Redirection - further action is necessary on the client's part to complete the request
  • 4xx Client Errors - the client sent a request that was malformed or cannot be fulfilled
  • 5xx Server Errors - the request was valid, but the server cannot fulfil it at present

Reason-Phrase is a short description of the status code. For example, code 200 has a reason phrase of OK; code 404 has a phrase of Not Found. A full list of reason phrases is available in Parameters, below, or in the HTTP specification.

The line ends with a carriage return—line feed pair, usually represented by \r\n.