Veelgebruikte HTTP-headers
HTTP-headers zijn sleutel-waardeparen die aan het begin van elk verzoek en antwoord worden meegestuurd. Ze dragen metadata zoals contenttype, cacheregels en authenticatie. Gebruik dit blad om de meest voorkomende headers te herkennen bij het bouwen of debuggen van webverkeer.
| Header | Richting | Doel |
|---|---|---|
| Host | request | Identifies the server's host and port (from the URL). |
| User-Agent | request | Reports the client software (browser, OS, bot) making the request. |
| Accept | request | Lists the response media types (MIME) the client can handle. |
| Authorization | request | Carries credentials (token, Basic auth) to authenticate the client. |
| Content-Type | request/response | States the media type of the request or response body. |
| Content-Length | request/response | Gives the size in bytes of the request or response body. |
| Cookie | request | Sends stored key/value pairs from a previous response back to the server. |
| Set-Cookie | response | Server instructs the client to store a cookie for later requests. |
| Cache-Control | request/response | Directs caching behaviour: no-cache, max-age, private, etc. |
| ETag | response | Opaque identifier for a resource version, used for revalidation. |
| If-None-Match | request | Sends an ETag; server returns 304 if the resource is unchanged. |
| Location | response | Points the client to a new URL for redirects (3xx) or created resources. |
| Access-Control-Allow-Origin | response | Permits a browser to share a response across origins (CORS). |
| X-Forwarded-For | request | Records the client IP as seen through a proxy or load balancer. |
| Referer | request | Indicates the URL of the page that linked to the requested resource. |
Opmerkingen
- Headernamen zijn niet hoofdlettergevoelig; volgens conventie schrijf je ze in Title-Case (bv. Content-Type).
- Request-headers beschrijven de client; response-headers de antwoord van de server.
- De browser stelt veel headers (zoals Host en Referer) automatisch in — vervals ze niet.
Veelgestelde vragen
- Wat is het verschil tussen een request- en een response-header?
- Request-headers worden door de client (browser of app) naar de server gestuurd; response-headers komen van de server met het antwoord. Sommige, zoals Content-Type, komen aan beide kanten voor.
- Zijn HTTP-headernamen hoofdlettergevoelig?
- Nee. Volgens de specificatie maken headernamen geen onderscheid in hoofdletters, dus Content-Type en content-type zijn hetzelfde. Title-Case is slechts een conventie.
- Wat doet de Host-header?
- Host vertelt de server welk domein de aanvraag bedoelt. In HTTP/1.1 verplicht en laat één server veel sites op naam hosten.
- Hoe werkt caching met headers?
- Cache-Control bepaalt hoe lang een antwoord gecached mag worden; ETag en If-None-Match laten de client vragen 'veranderd?' en goedkoop 304 Not Modified ontvangen.