HTTP (Hypertext Transfer Protocol) is a method that allows the transfer of
Following the client/server model, HTTP functions on the application layer, allow the data to be sent/received on TCP connections established between the client and server.
Note: To learn more about HTTP, refer to this Answer
For starters, HTTP works entirely through HTTP messages. There are two types of HTTP messages:
We can see that exchanging these messages in a request/response cycle enables data exchange between a client and server.
Figure 2 below illustrates the outline of a typical HTTP message. It's divided into three fields: start line, headers, and body. However, keep in mind that the request and response messages have a few key differences in the content that go into each of these fields that will be discussed in their respective sections.
Figure 3 depicts the structure of a typical HTTP request message and the data it contains in its fields.
As shown in Figure 3, the start line for the request messages contains the following:
The HTTP method is a command that tells the server what type of request the client is making.
There are multiple methods, namely the following:
Note: To learn about these methods in detail, refer to this Answer.
The request target, which is most often a URL, contains the location of the resource corresponding to the request message. For example, the request-target in a GET message would include the URL for a file the client wants from the server.
HTTP response messages don't contain a request-target as they already contain the client's requested resource.
This is the version of HTTP that the message is structured with. The following are HTTP versions as formatted for an HTTP message:
The headers for both request and response messages are in the form of one or more name:value pairs. These pairs can be divided into several groups:
The body for the request messages is often empty since most HTTP methods (such as GET and DELETE) are requesting a resource from the server. Request methods such as PUT include the resource to be stored on the server.
Figure 3 depicts the structure of a typical HTTP response message and the data it contains in its fields.
As shown in Figure 4, the start line for the response messages contains the following:
It has the same purpose as described for HTTP request messages.
The status code indicates the success/failure of the request sent in the HTTP request message. Multiple status codes can be divided into the following groups, as illustrated in Figure 5.
These headers follow the same structure as those in HTTP request messages but differ in their types. Response messages can be divided into the following groups:
The response message body contains the resource requested in the request message. For example, a response message sent to a GET request message will have the requested resource in the message's body.
The communication in persistent and non-persistent HTTP follows the exact mechanism as aforementioned: the message types, structures, and request/response cycle are identical. However, there's one critical difference.
In non-persistent HTTP, the client opens a TCP connection to the server, sends at most one object over the connection using the request/response, and then closes the connection. Thereby, downloading multiple objects requires multiple connections.
In persistent HTTP, the client opens a TCP connection to the server. Multiple objects can then be transferred over this connection if needed through individual request/response cycles, and then the connection closes the connection.
Note: To learn more about persistent vs non-persistent HTTP, refer to the following Answer.
Free Resources