Tuesday, January 11, 2022

HTTP | HTTP Transaction | HTTP Connection | HTTP Headers | Persistent vs Non-Persistent HTTP

Introduction of HTTP

HTTP is a standard web transfer protocol for fetching resources like HTML documents, images, videos. HTTP stands for Hyper Text Transfer Protocol. HTTP is an application layer protocol. HTTP is standard. HTTP uses port no 80. HTTP is a client-server protocol. HTTP behaviour is request-response.

Figure: HTTP Request - Response

HTTP Transaction - Click here for video

An HTTP transaction has the following components:

Connection: The client makes a connection to the server.

Request: The client requests information from the server.

Response: The server either provides the information to the client or refuses to provide the information.

Close: Either or both parties terminate the transaction.

Let us discuss all the components of HTTP Transaction one by one in this post.

Figure: Components of HTTP Transaction

Connection

The first part of an HTTP transaction is the connection. The translation of the name address into IP address is done by DNS. The client program connects to the server by a TCP connection at the address specified in the URL. Example: http://www.facebook.com


Request

There are two different types of requests: Simple Request, Full Request

HTTP Simple Request - Click here for video

A simple request is just a single GET line naming the page desired, without the protocol version. The response is just the raw page with no headers, no MIME, and no encoding.


HTTP Full Request - Click here for video

Full request is indicated by the presence of the protocol version on the GET request line. The first word on the full request line is simply the name of the method to be executed on the web page. Full request contains the command, the page desired, and the protocol/version. The names are case sensitive, so, GET is a valid method but get is invalid.

Request Line

Below figure shows the format of request message.

Figure: Format of Request message

Request line contains following things: Request type, Resources, HTTP version. Example of request line is as below:

Request type: It categorizes the request message into several methods for HTTP version 1.1. i.e., GET, POST, DELETE, PUT, COPY, MOVE, LINK, UNLINK

Resource: URL is used access information from internet. The URL defines four things 1. Method 2. Host 3. Port 4. Path.

Example, Protocol://Host:Port/Path http://192.168.1.1:80/home.html

HTTP Version: HTTP Version 1.1 is used here because of full request.

Realtime example of http request message


Response

Below figure shows the format of response message.

Figure: Format of Response Message

The status line is the first line in the response message. It consists of three items: The HTTP version number, showing the HTTP specification to which, the server has tried to make the message comply. A status code, which is a three-digit number indicating the result of the request.

Example of status line is as below,

HTTP Version: HTTP Version 1.1 is used here because of full request.

Status Code & Phrase: There are some of the status codes meaning:

200 OK: Request succeeded.

301 Moved Permanently: Requested object moved.

400 Bad Request: Request message not understood by server.

404 Not Found: Requested document not found on this server.

505 HTTP Version Not Supported: Requested http version not support.

Realtime example of http response message


Close

After the client and server have exchanged information by sending requests and responses, both parties may end the transaction by closing the connection. This is done by terminating the TCP connection (usually to port 80) that was set up in the connection stage.

 

HTTP Header - Click Here for Video

Header can be one or more header lines. Each header line is made of a header name, a colon, a space and a header value. The header exchange additional information between the client and the server. Below figure shows the HTTP header structure.

Figure: HTTP Header Structure

A four different header are used: general header, response header (in response message), entity header, request header (in request message). Below figure shows the difference between response and request header.

Figure: Format of Request and Response message

General header: General header includes general information about the message. Request and a response both contains general header.

Response header: Response header can be present only in a response message. It specifies the server’s configuration and special information about the request.

Request header: Request header can be present only in a request message. It specifies the client’s configuration and the client preferred document format.

Entity header: Entity header gives information about the body of the document. It is mostly present in response messages, some request message, such as POST and PUT methods, that contain a body also use this type of header.

Realtime example of http header

Date: It indicates the time and date when the HTTP response was created and sent by the server.

Server: It indicates the message was generated by an Apache Web server.

Last-Modified: It indicates the time and date when the object was created or last modified.

Content-Length: It indicates the number of bytes in the object being sent.

Content-Type: It indicates object in the entity body is HTML text.


HTTP Connection - Click here for video

The HTTP CONNECT method starts two-way communications with the requested resource. It can be used to open a tunnel. 

There are two types of HTTP Connection: Non-Persistent HTTP and Persistent HTTP. Let’s discuss HTTP response time and RTT (round trip time). Below figure shows the HTTP response time and RTT.

Figure: HTTP Connection

RTT (round-trip time): A time for a small packet to travel from client to server and server to client.

HTTP response time: 1-RTT to initiate TCP connection, 1-RTT for HTTP request-response and File transmission time.

HTTP Response Time = No. of RTT + file transmit time

Non-persistent HTTP

Non-persistent connections are the default mode for HTTP/1.0. A non-persistent connection is closed after the server sends the requested object to the client. The connection is used exactly for one request and one response. For downloading multiple objects, it required multiple connections.

Non-Persistent HTTP = 2 RTT + 1 file-transmit time

Figure: Non-persistent HTTP Connection

Example: Transferring a webpage from server to client, webpage consists of a base HTML file and 10 JPEG images. Total 11 object are resided on server.

11 objects = 22 RTT + 11 file-transmit time

 

Persistent HTTP

HTTP 1.1 made persistent connections the default mode. The server now keeps the TCP connection open for a certain period of time after sending a response. This enables the client to make multiple requests over the same TCP.

There are two types of Persistent HTTP Connection: Persistent HTTP without pipelining and Persistent HTTP with pipelining.

Persistent HTTP without pipelining

The client issues a new request only when the previous response has been received. The client experiences one RTT in order to request and receive each of the referenced objects. TCP connection is idle. i.e., does nothing while it waits for another request to arrive. This idle situation wastes server resources.

Figure: Persistent HTTP Connection without pipelining

In above figure, new object request sends after receive previous object.

Persistent HTTP with Pipelining

Default mode of HTTP 1.1 uses persistent connections with pipelining. Client issues a request as soon as it encounter a reference. The HTTP client can make back-to-back requests for the referenced objects. It can make a new request before the back-to-back requests; it sends the objects back-to-back. Pipelined TCP connection remains idle for a smaller fraction of time.

 

Figure: Persistent HTTP Connection with pipelining

In above figure, new object request sends receive previous object, but all the objects are received in a sequence because this method uses pipelining concepts.


Persistent HTTP Vs Non-Persistent HTTP - Click here for video



To learn more about HTTP, Click here

Watch more videos click here.

No comments:

Post a Comment