Introduction to HTTP : Understanding HTTP Basics

http-iconHTTP stands for hypertext transfer protocol and is used to transfer data across the Web.

The first version of the protocol had only one method, namely GET, which would request a page from a server.

The response from the server was always an HTML page.- Wiki

To give you an idea of how simple the HTTP protocol started out take a look at the Original specification ( only 1 page).



There have been several versions of HTTP starting with the original 0.9 version.

The current version is 1.1 and was last revised in 2014. See Wiki for more details.

How It Works

Like most of the Internet protocols it is a command and response text based protocol using a client server communications model.

The HTTP protocol is also a stateless protocol meaning that the server isn’t required to store session information and each request is independent of the other.- See this wiki

This means:

  • All requests originate at the client ( your browser)
  • The server responds to a request.
  • The requests(commands) and responses are in readable text.
  • The requests are independent of each other and the server doesn’t need to track the requests.

Request and Response Structure

Request and response message structures are the same and shown below:

http-request-response-structure

A request consists of:

A command or request + optional headers + optional body content.

A response consists of:

A status code + optional headers + optional body content.

A simple CRLF combination is used to delimit the parts and a single blank line (CRLF ) indicates end of the headers.

If the request or response contains a message body then this is indicated in the header.

The presence of a message body in a request is signaled by a Content-Length or Transfer-Encoding header field. Request message framing is independent of method semantics, even if the method does not define any use for a message body. – RFC 7230 section 3.3.

Note: the message body is not followed by a CRLF See RFC 7230 section 3.5

HTTP Requests

We saw the general request response format earlier now we will cover the request message in more detail.

The start line is mandatory and is structured as follows:

Method + Resource Path + protocol version

Example if we try to access the web page testpage.htm on www.testsite5.com

The the start line of the request would be

GET /test.htm HTTP/1.1

Where

  • GET is the method
  • /testpage.htm is the relative path to the resource.
  • HTTP/1.1 is the protocol version we are using

Notes:

  1. A relative path doesn’t include the domain name.
  2. The web browser uses the URL that we enter to create the relative URI of the resource.

Note: URL (uniform resource Locator) is used for web pages. It is an example of a URI (uniform resource indicator).

The actual request is not shown by the browser, and is only visible using special tools. e.g. the Firefox add-on Live HTTP headers.

HTTP Response and Codes

Each request has a response. The Response consists of a

  • STATUS code And Description
  • 1 or more optional headers
  • Optional Body message can be many lines including binary data

Response Status codes are split into 5 groups each group has a meaning and a three digit code.

  • 1xx – Informational
  • 2xx – Successful
  • 3xx -Multiple Choice
  • 4xx– Client Error
  • 5xx -Server Error

For example a successful page request will return a 200 response code and an unsuccessful a 400 response code.

You can find a complete list and their meaning here

Request Response Example

We are going to examine he requests and response when we access a simple web page (testpage.htm)

Here is what I enter in the browser address bar:

browser-request

and this is the response that the browser displays:

browser-response

and here is a screen shot of the http request-response that happens behind the scenes.

HTTP-Request-Response-example

Notice the headers that are automatically inserted by the browser and also the headers in the response which are inserted by the web server.

There is no body content in the request, and the body content in the reply, which is a web page, is shown in the browser, and not by the live headers tool.

Part 2 HTTP headers – coming  soon

Related Tutorials and Resources

Save

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *