HTTP headers

SECTIONS

IntroductionDifference between Accept and Content-Type

A very important part of HTTP (Hypertext Transfer Protocol) is HTTP header and it plays a crucial role in sending additional information in HTTP request or response. We discussed earlier that data is sent to the browser through the web server corresponding to the website. The two components, i.e., server and browser manage the exchange of information related to the document through HTTP header.

Every HTTP request has a header area which carries information like the date of the request, the referrer and the language preference.  A similar header field is present in the HTTP response as well through which the server sends information to the browser of the user. The end user is also able to see this process of exchange of information.

These HTTP headers have one- line fields, each line carrying a pair of names or a value. This is called as key-value-pair which is separated using a colon and terminated with a line break. The name of the header is not case sensitive. At the end of the header, there is an empty field header. Some of the headers fields have comments while some can have quality (q) key value pair which is separated using an equal (=) sign.

RFC (Request for Comments) is where the values which are used for HTTP header are defined. Apart from this, there could be some non-standard headers (prefixed with -X) which are useful while adding user defined information.

Headers can be categorized into four categories namely-

  • General header: These are headers which are usually applicable to request as well as response messages.
  • Client Request header: These are headers which are applicable just for request messages.
  • Server Response header: These are headers which are applicable just for response messages.
  • Entity header: These are headers which are responsible for defining meta information regarding the entity- body and in the absence of body, regarding the resource which is identified by the request.

The below mentioned diagram represents HTTP Header.

Difference between Accept and Content-Type

HTTP Accept header is a type of request header which carries information from the client to the server regarding the content type can be understood by the client and is expressed as MIME types. Values are set for this header by the browser and this depends on the context where the request is made.

On the other hand, the Content type header acts like a negotiator wherein the server chooses a proposed content type and sends the information to the client through the content-type header.  It is like a string describing the format of the file which is sent with the file.

In the absence of a Accept type header in the request, it is automatically assumed by the server that all types of media are accepted by the client.