HTTP Protocol
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).
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.
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.
The HTTP mainly uses the services of the TCP on the well-known port that
is port 80.
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 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.
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
Let us take a look at the format of the request message and response message:
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.
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
Actions
Method
URL
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.
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:
4. HTTP is platform-independent.
Disadvanatges of HTTP
There are some drawbacks of using the HTTP protocol:
This protocol does not offer reliable exchange without the retry logic.
The 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
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.
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.
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.