Cheat sheetWeb

HTTP headers

The HTTP headers you'll actually read or set — request, response, CORS and security — each translated into one plain-English line.

Last updated

Request headers

HeaderWhat it does
AuthorizationCarries the credential proving who's asking — a bearer token, API key, or Basic auth pair.
Content-TypeTells the server how the request body is encoded, e.g. application/json.
AcceptTells the server which response formats the client can handle.
User-AgentIdentifies the client software making the request — browser, bot, or app.
CookieSends back the cookies the server previously set for this domain.
If-None-MatchSends a cached ETag so the server can reply 304 if nothing changed.
OriginThe scheme+host+port the request came from — what CORS checks are based on.
RefererThe page the request was linked or triggered from (yes, misspelled in the spec).

Response headers

HeaderWhat it does
Content-TypeTells the client how to interpret the response body, e.g. text/html or image/png.
Cache-ControlSets how long, and under what conditions, this response may be cached.
ETagA fingerprint of the response body, used to check for changes without resending it.
LocationWhere to go instead — used with redirects and after creating a resource.
Set-CookieStores a cookie in the client for future requests to this domain.
Content-DispositionSuggests the browser download the response as a file, with a given name.
Retry-AfterTells the client how long to wait before trying again, usually with a 429 or 503.

CORS

HeaderWhat it does
Access-Control-Allow-OriginLists which origins may read this response from a cross-origin request.
Access-Control-Allow-MethodsLists which HTTP methods a cross-origin request is allowed to use.
Access-Control-Allow-HeadersLists which request headers a cross-origin request is allowed to send.
Access-Control-Allow-CredentialsPermits cookies and auth headers to be included in a cross-origin request.
The preflightBefore certain cross-origin requests, the browser sends an OPTIONS request to check permission first.

Security

HeaderWhat it does
Strict-Transport-SecurityForces the browser to use HTTPS for this domain, even if a link says http://.
Content-Security-PolicyRestricts which sources scripts, styles and other resources may load from.
X-Content-Type-OptionsSet to nosniff, stops the browser guessing a file's type from its content.
X-Frame-OptionsControls whether this page may be embedded in an iframe, preventing clickjacking.
Referrer-PolicyControls how much of the current URL is sent as Referer on outgoing requests.

Worth remembering

  • A CORS failure is a browser-side block, not a server error — the request usually succeeded, the browser just won't hand the response to your script.
  • Access-Control-Allow-Origin can't be "*" alongside Access-Control-Allow-Credentials — credentialed requests require an exact origin to be named.

Related in Cheat sheets