Track 01 · Lesson 5 of 9How the web works

Track 01 · How the web works

Headers

Lesson 5 of 9· 6 min

Every request and response carries headers: short Name: value lines that say who a message is for, what's inside and how to treat it. Some are added by your browser, some by servers along the way, and some can be typed by absolutely anyone.

Follow the stickers

Then switch to a hand-made request

Step 1 of 4

Step 1

The client builds the request

Your browser adds headers on its own: the host, what kind of browser it is, your language, and any cookies for this site. You never typed any of them.

Headers on the request so far

  • Host: shop.example.comBrowser
  • User-Agent: Mozilla/5.0 (Windows NT 10.0)Browser
  • Accept-Language: en-GBBrowser
  • Cookie: session=7f3a9cBrowser

Dashed tag: set by the client, so anyone can fake it. Solid tag: set by your own servers.

Headers you'll see everywhere#

  • Host: which site the request is for. One server often hosts many.
  • Content-Type: what the body is, like text/html or application/json.
  • Accept-Language: which languages the visitor prefers.
  • Cookie and Set-Cookie: how the site remembers you. That's the next lesson.
  • Authorization: a token or password proving who's asking.
  • Cache-Control: how long a response may be reused.
  • Location: where to go next, used by redirects and by 201 Created.

A header is a claim, not a fact#

A browser fills in headers for you, but nothing forces a request to come from a browser. With curl or a few lines of code, anyone can send any header with any value. So every header that arrives from the client is just what the client says.

Headers set by your own servers are different: a CDN or reverse proxy that overwrites a header, like CF-Connecting-IP in the demo, gives you a value the client couldn't choose. That only holds if nobody can reach your app without going through that proxy, which is a lesson for Shipping safely.

Check yourself

An app rate-limits each visitor by the first IP address in X-Forwarded-For. What can an attacker do?