One of the key technology of the world-wide-web is hyper-text transfer protocol, http provides a well-defined interface for multimedia communications between http clients to http servers. The full specification can be found in rfc7231 Some important characteristics of http:
- It uses the request-response pattern
- It is a stateless protocol
- It is part of the Internet Protocol Suite, and must run on a transport layer protocol (Typically, TCP)
Each of these characteristics helps make http a fast, efficient, and able to serve a large client pool from a relatively small number of servers. Let’s break that down into more detail.
HTTP clients make requests from a HTTP server, which then returns a response. Both the request and response structure are defined by the http protocol.
A request consists of two parts, a head and a body.
The Request Head
The head consists of a stream of text terminated with a newline conforming to this pattern:
Method Request-URI HTTP-Version
And followed by single-line request headers in the pattern:
And finally terminated with a empty line (only a line end character).
The http method token (also known as a verb) which identifies the type of request - GET and POST being the two most common. GET indicates we want to retrieve a resource from the server, and POST indicates that we want to upload a resource to the server.
Other methods are: PUT and DELETE for modifying or deleting a resource, and HEAD, TRACE, and CONNECT. Most browsers only implement GET and POST.
The Request URI is the full Universal Resource Identifier for the resource being requested. This is in the form:
Host is the fully quantified domain name (i.e. Google.com or cs.ksu.edu), IP4, or IP6 address. Path is the path to the resource, similar to a file path. The Query String and the
? proceeding it are optional, and consist of key-value pairs in the form
key=value separated by pipe characters (
HTTP version denotes the version of the protocol the browser (or other user-agent) is employing (currently
Request headers take the form of key-value pairs on a single line, i.e.:
Accepts: gzip deflate
This particular key-value pair indicates the browser accepts responses compressed with either the gzip or deflate algorithms.
There can be as many headers as needed. Official headers need to be registered (see rfc7231, but unofficial headers can be added as well, provided they follow the format. Servers will ignore headers they don't recognize.
Finally, an empty line (one containing only an end-of-line character) signals the end of the headers and the request head.
The Request Body
Responses also consist of two parts, a head and a body.
The Response Head
The head consists of a stream of text terminated by a newline conforming to this pattern:
HTTP-Version Status-Code Reason-Phrase
Followed by a series of single-line key-value headers
Terminated by a blank line (just the newline character).
Just like with the request, the server indicates which version of HTTP it is using (typically
The status code indicates the status of the response, like 200 (everything's okay) or 404 (couldn't find the resource requested).
The reason phrase provides a brief plain-english explantation of the status code. Standard status codes are found in RFP, and status codes may be added as needed, but the first digit indicates the category of status:
|1xx||Informational - Request received, continuing process|
|2xx||Success - The action was successfully received, understood, and accepted|
|3xx||Redirection - Further action must be taken in order to complete the request|
|4xx||Client Error - The request contains bad syntax or cannot be fulfilled|
|5xx||Server Error - The server failed to fulfill an apparently valid request|
As with the request head, the response head can contain an arbitrary number of single-line key-value headers in the format:
Following the response headers is an optional series of entity headers following the same format. These contain metadata corresponding to the response body, when it contains an entity.
One of the most important of these is the
Content-Type, which indicates what kind of data is included in the response body. This corresponds to a internet media type - commonly referred to as a mime-type (for example:
Other entity headers specify attributes of the entity, like language (
Content-Language) or encoding (
The response header is terminated with an empty line (a line containing only a newline character).
The Response Body