Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

HTTP Protocol

In this tutorial, we will be covering the HTTP that is the protocol in the Application layer of the OSI Model.

HTTP stands for Hypertext Transfer Protocol and is mainly used to access the data on the world wide web i.e (WWW). The HTTP mainly functions as the combination of FTP(File Transfer Protocol) and SMTP(Simple Mail Transfer Protocol).

  • HTTP is one of the protocols used at the Application Layer.

  • The HTTP is similar to FTP because HTTP is used to transfer the files and it mainly uses the services of TCP.

  • Also, HTTP is much simpler than FTP because there is only one TCP connection.

  • In HTTP, there is no separate control connection, as only data is transferred between the client and the server.

  • The HTTP is like SMTP because the transfer of data between the client and server simply looks like SMTP messages. But there is a difference unlike SMTP, the HTTP messages are not destined to be read by humans as they are read and interpreted by HTPP Client(that is browser) and HTTP server.

  • Also, SMTP messages are stored and then forwarded while the HTTP messages are delivered immediately.

  • The HTTP mainly uses the services of the TCP on the well-known port that is port 80.

  • HTTP is a stateless protocol.

  • In HTTP, the client initializes the transaction by sending a request message, and the server replies by sending a response.

  • This protocol is used to transfer the data in the form of plain text, hypertext, audio as well as video, and so on.

Working of HTTP

The HTTP makes use of Client-server architecture. As we have already told you that the browser acts as the HTTP client and this client mainly communicates with the webserver that is hosting the website.

The figure shows the HTTP transaction

The format of the request and the response message is similar. The Request Message mainly consists of a request line, a header, and a body sometimes. A Response message consists of the status line, a header, and sometimes a body.

At the time when a client makes a request for some information (say client clicks on the hyperlink) to the webserver. The browser then sends a request message to the HTTP server for the requested objects.

After that the following things happen:

  • There is a connection that becomes open between the client and the webserver through the TCP.

  • After that, the HTTP sends a request to the server that mainly collects the requested data.

  • The response with the objects is sent back to the client by HTTP

  • At last, HTTP closes the connection.

Let us take a look at the format of the request message and response message:

Request Line and Status line

The first line in the Request message is known as the request line, while the first line in the Response message is known as the Status line.

Figure: Request Line and Status Line

where,

Request Type

This field is used in the request line. The are several request types that are defined and these are mentioned in the table given below;

Name of Method Actions
GET This method is used to request a document from the server.
HEAD This method mainly requests information about a document and not the document itself
POST This method sends some information from the client to the server.
PUT This method sends a document from the server to the client.
TRACE This method echoes the incoming request.
CONNECT This method means reserved
OPTION In order to inquire about the available options.

URL

URL is a Uniform Resource locator and it is mainly a standard way of specifying any kind of information on the Internet.

HTTP Version

The current version of the HTTP is 1.1.

Status Code

The status code is the field of the response message.The status code consists of three digits.

Status Phrase

This field is also used in the response message and it is used to explain the status code in the form of text.

Header

The header is used to exchange the additional information between the client and the server. The header mainly consists of one or more header lines. Each header line has a header name, a colon, space, and a header value.

The header line is further categorized into four:

  • General Header
    It provides general information about the message and it can be present in both request and response.
  • Request Header
    It is only present in the request message and is used to specify the configuration of the client and the format of the document preferred by the client
  • Response Header
    This header is only present in the response header and mainly specifies the configuration of the server and also the special information about the request.
  • Entity Header
    It is used to provide information about the body of the document.

Body

It can be present in the request message or in the response message. The body part mainly contains the document to be sent or received.

Features of HTTP

The HTTP offers various features and these are as follows:

  1. HTTP is simple
    The HTTP protocol is designed to be plain and human-readable.

  2. HTTP is stateless
    Hypertext transfer protocol(HTTP) is a stateless protocol, which simply means that there is no connection among two requests that are being consecutively carried out on the same connection. Also, both the client and the server know each other only during the current requests and thus the core of the HTTP is itself a stateless one, On the other hand, the HTTP cookies provide in making use of stateful sessions.

  3. HTTP is extensible
    The HTTP can be integrated easily with the new functionality by providing a simple agreement between the client and the server.

  4. HTTP is connectionless
    As the HTTP request is initiated by the browser (HTTP client) and as per the request information by the user, after that the server processes the request of the client and then responds back to the client

Advantages of HTTP

Given below are the benefits of using HTTP:

  1. There is no runtime support required to run properly.

  2. As it is connectionless so there is no overhead in order to create and maintain the state and information of the session.

  3. HTTP is usable over the firewalls and global application is possible.

  4. HTTP is platform-independent.

  5. HTTP reports the errors without closing the TCP connection.

  6. Offers Reduced Network congestions.

Disadvanatges of HTTP

There are some drawbacks of using the HTTP protocol:

  • HTTP is not optimized for mobile.

  • HTTP is too verbose.

  • It can be only used for point-to-point connections.

  • This protocol does not have push capabilities.

  • This protocol does not offer reliable exchange without the retry logic.

enlightenedThe HTTP supports proxy servers. A proxy server is basically a computer that keeps the copies of the responses to recent requests. The proxy server mainly reduces the load on the originals server.In order to use the proxy server, the client must be configured in order to access the proxy instead of the target server.

HTTP Connections

HTTP connections can be further classified into two:

  • Persistent Connection

  • Nonpersistent Connection

Let us discuss them one by one:

1.Persistent Connection

In the persistent HTTP connection, all the requests and their corresponding responses are sent over the same TCP connections. The 1.1 version of the HTTP specifies a persistent connection by default.

In this type of connection, the server leaves the connection open for more requests after sending a response. Also, the server can close the connection at the request of the client or upon reaching the time-out.

In a Persistent connection, a single TCP connection is mainly used for sending multiple objects one after the other.

Usually, the length of the data is sent along with each response. There are some cases when the server does not know the length of the data this happens when the document is created dynamically and in such cases, the server informs the client that length is not known and closes the connection after sending the data so in order let the client Inform about the end of the data.

2.Nonpersistent Connection

In the Nonpersistent HTTP connection, one TCP connection is made for each request/response; it means there is a separate for each object.

Following are the steps used;

  • The client opens a TCP connection and then sends a request.

  • After that, the server sends the response and then closes the connection.

  • Then the client reads the data and until it encounters an end-of-file marker then it closes the connection.

This connection imposes a high overhead on the server because N different buffers are required by the server, and the start procedure is slow each time when a connection is opened.

The nonpersistent connection is supported by the HTTP 1.0 version.