Hyper Text Transfer Protocol

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:

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.

Request-Response Pattern

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.

Request-Response Pattern

HTTP Requests

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:

Key: Value

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

HTTP version denotes the version of the protocol the browser (or other user-agent) is employing (currently HTTP/1.1).

Request Headers

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

The body of the request may contain data that accompanies the request. The most common form of request body would be form data - either using form encoding or javascript. The form data could also be empty (typical of a GET request), or multipart (consisting of multiple representations, i.e. when uploading files as part of a form).

HTTP Responses

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

Key: Value

Terminated by a blank line (just the newline character).

HTTP Version

Just like with the request, the server indicates which version of HTTP it is using (typically http/1.1)

Status Code

The status code indicates the status of the response, like 200 (everything's okay) or 404 (couldn't find the resource requested).

Reason Phrase

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:

Category Meaning
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
Response Headers

As with the request head, the response head can contain an arbitrary number of single-line key-value headers in the format:

Key: Value
Entity Headers

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: text/html, image/jpeg).

Other entity headers specify attributes of the entity, like language (Content-Language) or encoding (Content-Encoding).

The response header is terminated with an empty line (a line containing only a newline character).

The Response Body

The body contains the entity, if one was specified in the entity headers. This can be any kind of digital information, but is most commonly html, css, javascript, or a media file.