HTTP Response

HTTP Response Messages

When a request arrives, the server returns a response message like the following.

HTTP/1.1 200 OK
Date: Sun, 11 Jan 2014 16:06:23 GMT
Server: Apache/1.3.22 (Unix) (Red-Hat/Linux)
Last-Modified: Sun, 07 Dec 2013 12:34:18 GMT
ETag: "1dba6-131b-3fd31e4a"
Accept-Ranges: bytes
Content-Length: 4891
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html

<!DOCTYPE html>
<html>
  :
</html>

A response message consists of a response line (status line), HTTP response headers, a blank line that marks the end of headers, and an HTTP body.

Line breaks use the Windows-style CR LF("\r\n"). The first line is the request or response line, headers can span multiple lines, the blank line is one line, and the message body can span multiple lines.

Start Line

The start line (status line) of an HTTP response has the following three elements.

  • HTTP protocol version, the same as an HTTP request message
  • Response status code
  • Status text

The response start line is displayed in the following format.

[HTTP protocol version] [response status code] [status text]

The status text returns a message that supplements the meaning and details of a status number, such as OK or Not Found.

Example:

% curl http://google.com/ --head
HTTP/1.1 301 Moved Permanently
  • HTTP protocol version: HTTP/1.1
  • Response status code: 301
  • Status text: Moved Permanently

HTTP Protocol Version

Indicates the HTTP version, the same as an HTTP request message. Usually HTTP/1.1 or 2.0.

Response Status Code and Status Text

HTTP/1.1 status code definitions are specified in RFC 2616. In summary:

Response code Meaning Description
1xx Informational Information
2xx Successful Successful response
3xx Redirection Additional action (redirection)
4xx Client Error Client-side error
5xx Server Error Server-side error

1xx, 2xx, and 3xx codes indicate states between the server and user agent, so general users usually do not see their contents. 4xx and 5xx codes are commonly seen by general users.

If a web page does not appear normally in a browser for any reason, it corresponds to a 3xx or 4xx error. To understand and recover from the cause of an error, it is useful to know roughly what the error code means.

Response code Meaning Description
100 Continue The server has received part of the request and asks the client to continue sending the rest.
101 Switching protocols Protocol switching. The requester asked the server to switch protocols, and the server is approving it.
200 OK The request was successfully performed.
201 Created The request succeeded, and the server created a new resource.
202 Accepted The web server accepted the request but has not processed it yet.
203 Non-authoritative information The server successfully processed the request but is providing information received from another source.
204 No content The server successfully processed the request but provides no content.
205 Reset Content The server successfully processed the request but provides no content.
206 Partial content The server successfully processed part of a GET request.
300 Multiple Choices Several options exist for obtaining the content.
301 Moved permanently The requested data has moved to another URL.
302 Found temporarily The requested data was found at a temporary URL.
304 Not modified The resource was not updated, so local cache information was used.
305 Use Proxy Uses the proxy specified in the Location header.
306 (Unused) Unused.
307 Temporary Redirect Temporarily moving to another location.
400 Bad request The request is invalid. The user’s invalid request cannot be processed.
401 Unauthorized Not authenticated. Occurs when requesting a page that requires authentication.
402 Payment required Reserved. Payment is required.
403 Forbidden Access is not allowed.
404 Not found The requested page does not exist.
405 Method not allowed An unsupported HTTP method was used.
407 Proxy authentication required Proxy authentication is required.
408 Request timeout The request timed out.
410 Gone Permanently unavailable. The requested content has disappeared.
411 Length Required Add a Content-Length header to the request.
412 Precondition failed The condition specified in an If-* header was not met.
414 Request-URI too long The request URL is too long.
415 Unsupported Media Type The media type is not supported.
416 Requested Range Not Satisfiable The requested range is invalid.
417 Expectation Failed The extension request specified in the Expect header failed.
500 Internal server error An unexpected server error occurred.
501 Not implemented The web server cannot process the request.
502 Bad Gateway The gateway is invalid.
503 Service unavailable Service unavailable.
504 Gateway timeout The gateway timed out.
505 HTTP version not supported The HTTP version is not supported.

HTTP Header

Response headers have the following three types.

Header type Description Examples
Response header Header not related to response body data - Location
General header Resource to retrieve - Date
- Cache-Control
Entity header Applies to the response body - Content-Type
- Content-Length
- Expires

HTTP Body

Contains the contents of the resource (file).

% curl http://www.devkuma.com
<!DOCTYPE html>
<html lang="ko">
<head>