Basic

Headers are a small contract

The response is bytes plus a few named lines. The names are the whole contract, and the contract is short enough that writing it down is cheaper than remembering it.

What you will see

One line with cache no. The name about the request is the one that must not be stored.

About 1 min of reading

Try It

Write the header contract

1

Write the allowed headers

printf "content-type\ncache-control\nrequest-id\n" > /tmp/h.txt; wc -l < /tmp/h.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
3. Three names is the contract of the route.
2

Attempt an undeclared header

printf "server\n" | grep -c -f - /tmp/h.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
0. The header is not in the contract, which is the refusal.
3

Stamp the cached one

printf "request-id cache=no date=2026-10-10\n" > /tmp/c.txt; cat /tmp/c.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line with cache no. The name about the request is the one that must not be stored.

Data Flow

A route to a header list
1 The route declares its headers
↓
2 The handler writes the declared names
↓
3 A name not declared is refused
↓
4 The list is stamped with the run
Why this works
Why the header list is written per route

The list is the contract of the route. A contract only in the code is a contract that drifts with each edit.

The one header that must never be cached

The one that names the request. A cached copy of it is a response about a request that is not the current one.

Examples

Content type is a claim

It says what the bytes are. A claim that disagrees with the bytes is a client that parses the wrong thing.

Cache headers are a policy

They say who may store the response. The policy is a decision about a future reader, not about the present one.

Unknown headers are kept

A client ignores what it does not know. Ignoring is why a wrong header is silent rather than loud.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Shared state in a server
Previous Lesson
Shared state in a server
Next Lesson
Closing a server cleanly
Closing a server cleanly →