Esteban Clouthier
Esteban Clouthier

Reputation: 177

The use of HTTP headers

In developer.mozilla.org says:

HTTP headers allow the client and the server to pass additional information with the request or the response

but I don't understand what is the use of that? What is the need to pass additional information with the request or the response?

Upvotes: 3

Views: 2317

Answers (1)

Kate Hanahoe
Kate Hanahoe

Reputation: 156

This is a hard question to answer concisely because of the many different types of HTTP headers and what they do, but here's an attempt at a one-line answer:

HTTP headers allow a client and server to understand each other better, meaning they can communicate more effectively.

So then if you look at individual headers, it becomes clearer why each is needed:

User-Agent header

  • Sent by the client
  • Tells the server about the client's setup (browser, OS etc.)
  • Mostly used to improve client experience, e.g. tailoring responses for mobile devices or dealing with browser compatibility issues

set-cookie header

  • Sent by the server
  • Tells the browser to set a cookie

host header

  • Sent by the client
  • Specifies the exact domain name of the site the client wants to reach, this is used when a single server hosts multiple websites (a.k.a. virtual hosting)

Upvotes: 6

Related Questions