HTTP Message is used to show how data is exchanged between the client and the server. It is based on client-server architecture. An HTTP client is a program that establishes a connection to a server to send one or more HTTP request messages. An HTTP server is a program that accepts connections to serve HTTP requests by sending an HTTP response messages.
The HTTP Messages can be classified as follows:
HTTP message consists of an initial request line and an initial response line.
1) Initial Request Line
The initial line is different for the request and for the response. A request-line consists of three parts: a method name, requested resource’s local path, and the HTTP version being used. All these parts are separated by spaces.
- GET is the most common HTTP method.
- The path shows the part of the URL after the host name. It is also called a request URI.
- The version of HTTP always takes the form “HTTP/x.x”, uppercase.
2) Initial Response Line
The initial Response line is also known as the status line. It also has three parts: the HTTP version, a response status code that gives the result of the request, and the English reason phrase describing the status code.
The HTTP version of the response line and request line are the same as “HTTP/x.x”.
The Message header provides information about the request and response. It also provides information about the object which is sent in the message body. Message Headers are of four types:
- General Header: It has general applicability for both request messages and response messages.
- Request Header: It has applicability only for the request messages.
- Response Header: It has applicability only for the response messages.
- Entity Header: It defines meta-information about the entity-body, and about the resource identified by request.
All the above headers follow the same generic format. Each of the header fields consists of a name followed by a colon and the field values as follows:
The message body of an HTTP message is used to carry the entire body associated with the request and response. The message-body differs from the entire-body only when a transfer-coding has been applied, as indicated by the Transfer-Encoding header field.
Transfer-Encoding MUST be used to indicate any transfer-codings which is applied by an application to ensure safe and proper transfer of the message. Transfer-Encoding is a property of the message.
The transfer-length of a message is the length of the message-body, and it appears in the message.
In a message, when a message body is allowed, and Content-Length is given, its field value MUST exactly match the number of OCTETs in the message-body. When an invalid length is received and detected, the HTTP/1.1 user agents MUST notify the user.
General Header Fields
Some header fields have the applicability for both the request and response messages. These header fields apply only when the message is transmitted.