What are HTTP headers

HTTP headers are additional pieces of information sent along with a request or response between a client (usually a web browser) and a server. They provide metadata that governs how the requested content is handled, interpreted, and displayed.

We distinguish two categories of HTTP headers: 1) the headers that are sent with the HTTP requests (request headers) and the headers that are sent with the response (response headers).

Request HTTP Headers:

  • User-Agent: Identifies the browser and operating system of the user.
  • Accept: Indicates the media types that the client can process.
  • Cookie: Sends any relevant cookies stored for the domain.
  • Authorization: Includes credentials for accessing restricted resources (if applicable).
  • Referer: Specifies the URL of the previous web page from which the current request originated.

Response HTTP Headers:

  • Content-Type: The Content-Type header informs the client about the media type of the response data. For instance, text/html for HTML documents, application/json for JSON data, etc.
  • Cache-Control: Directs how the content should be cached by the browser or intermediate caches.
  • Content-Encoding: Indicates any compression applied to the response body.
  • Set-Cookie: Instructs the browser to set cookies for future requests.
  • Location: Utilized in redirects, specifying the new URL to which the client should navigate.