Saturday, January 10, 2015

HTTP - Messages

HTTP operates by exchanging messages across a reliable TCP/IP connection.

Once connection is established, HTTP messages are passed. These messages are consisted of requests from client to server and responses from server to client which will have following format:

 HTTP-message   = <Request> | <Response> ; HTTP/1.1 messages

 - A Start-line
 - Zero or more header fields followed by CRLF
 - An empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields
 - Optionally a message-body

Header Fields
HTTP header fields provide required information about the request or response, or about the object sent in the message body. There are following four types of HTTP message headers:

  - General-header: These header fields have general applicability for both request and response messages.
  - Request-header: These header fields are applicability only for request messages.
  - Response-header: These header fields are applicability only for response messages.
  - Entity-header: These header fields define metainformation about the entity-body or, if no body is present.

Example:
User-Agent: curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3
Host: www.example.com
Accept-Language: en, mi
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Accept-Ranges: bytes
Content-Length: 51
Vary: Accept-Encoding
Content-Type: text/plain

Message Body

The message body part is optional for an HTTP message but if it is available then it is used to carry the entity-body associated with the request or response.
If entity body is associated then usually Content-Type and Content-Length headers lines specify the nature of the body associated.
A message body is the one which carries actual HTTP request data (including form data and uploaded etc.) and HTTP response data from the server ( including files, images etc). Following is a simple content of a message body:
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>

No comments:

Post a Comment