3

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?

1 Answer 1

6

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.