← All cheat sheets

Web

HTTP Headers Cheat Sheet — Request, Response, and Security Headers

Headers carry the metadata that makes HTTP work — what format the body is in, how long it can be cached, who may read it. This reference covers the ones you meet most often.

Put it into practice with the matching tool.

Look up a status code →

Advertisement

Request headers

AcceptFormats the client can handle, e.g. application/json
Accept-EncodingCompression the client supports, e.g. gzip, br
Accept-LanguagePreferred languages
AuthorizationCredentials, e.g. Bearer <token> or Basic <base64>
Content-TypeFormat of the request body being sent
CookieCookies previously set by the server
HostTarget hostname — required in HTTP/1.1
OriginOrigin of the page making the request — drives CORS
RefererPage the request came from (spelling is historic)
User-AgentIdentifies the client software
If-None-MatchSend the saved ETag to revalidate a cached copy
If-Modified-SinceRevalidate by timestamp instead
RangeRequest only part of a resource

Response headers

Content-TypeFormat of the response body — include charset for text
Content-LengthSize of the body in bytes
Content-EncodingCompression applied, e.g. gzip or br
Content-Dispositionattachment; filename="x.pdf" triggers a download
LocationWhere to go — used with 3xx redirects
Set-CookieSets a cookie on the client
Retry-AfterWhen to try again — used with 429 and 503
ServerServer software — often best omitted
VaryWhich request headers change the response, for caches

Caching

Cache-Control: no-storeNever cache — for sensitive responses
Cache-Control: no-cacheCache, but revalidate before each use
Cache-Control: max-age=3600Fresh for one hour
Cache-Control: public, max-age=31536000, immutableFor fingerprinted static assets
Cache-Control: privateOnly the browser may cache, not shared caches
s-maxage=600Separate lifetime for CDNs and shared caches
stale-while-revalidate=60Serve stale briefly while refreshing in the background
ETagVersion identifier used for revalidation
Last-ModifiedTimestamp used for revalidation

CORS

Access-Control-Allow-OriginWhich origin may read the response
Access-Control-Allow-MethodsMethods allowed — answers the preflight
Access-Control-Allow-HeadersRequest headers the client may send
Access-Control-Allow-CredentialsPermit cookies — cannot combine with *
Access-Control-Expose-HeadersResponse headers JavaScript may read
Access-Control-Max-AgeHow long the preflight result can be cached

Cookie attributes

HttpOnlyHidden from JavaScript — blocks theft via XSS
SecureOnly sent over HTTPS
SameSite=LaxSent on top-level navigation only — a good default
SameSite=StrictNever sent on cross-site requests
SameSite=NoneSent cross-site — requires Secure
Max-Age=3600Lifetime in seconds
Path=/ ; Domain=Scope of the cookie

Security headers

Content-Security-PolicyRestricts where scripts, styles, and frames may load from
Strict-Transport-Securitymax-age=31536000 forces HTTPS on future visits
X-Content-Type-Options: nosniffStops the browser guessing content types
X-Frame-Options: DENYBlocks framing — superseded by frame-ancestors
Referrer-PolicyHow much referrer information to leak
Permissions-PolicyDisables browser features such as camera or geolocation
Cross-Origin-Opener-PolicyIsolates the browsing context from cross-origin windows

HTTP Headers in practice

Headers you will debug most

Content-Type tells the receiver how to parse a body; a JSON API receiving text/plain may ignore the body entirely. Accept says what the client wants back. Authorization carries credentials, and a missing or malformed one usually produces a 401. Location accompanies redirects and newly created resources. Retry-After on a 429 or 503 tells clients how long to wait. When an integration misbehaves, compare the headers actually sent with what the API documents — the browser's network panel or curl -v shows them.

Caching in practice

For files with a content hash in their name, such as app.3f9a1c.js, send Cache-Control: public, max-age=31536000, immutable: they can be cached for a year because a new version gets a new name. For HTML, use Cache-Control: no-cache, which means "revalidate before use", not "do not cache"; combined with an ETag, the browser gets a cheap 304 response when nothing changed. Use no-store only for genuinely sensitive responses. private keeps personalised pages out of shared caches and CDNs.

CORS headers

Access-Control-Allow-Origin must name the requesting origin, or * for public data without credentials. Requests with credentials also need Access-Control-Allow-Credentials: true and an exact origin. Preflight OPTIONS requests need Access-Control-Allow-Methods and Access-Control-Allow-Headers covering what the real request will use. When echoing the origin dynamically, add Vary: Origin so caches do not serve one origin's answer to another.

Cookies done safely

Session cookies should be Secure (HTTPS only), HttpOnly (not readable by JavaScript) and SameSite=Lax or Strict, which blocks most cross-site request forgery. SameSite=None is needed only for cookies used across sites, such as embedded widgets, and requires Secure. Prefix names with __Host- to force a cookie to be secure, host-only and path /. Set Max-Age or Expires deliberately; without them, a cookie lasts only for the browser session.

A baseline of security headers

Strict-Transport-Security: max-age=31536000; includeSubDomains keeps browsers on HTTPS. Content-Security-Policy restricts where scripts and other resources can load from and is the strongest defence against XSS. X-Content-Type-Options: nosniff stops browsers guessing content types. Referrer-Policy: strict-origin-when-cross-origin limits what URLs leak to other sites. frame-ancestors in CSP, or X-Frame-Options, prevents clickjacking. Scanners such as Mozilla Observatory check a site against this list.

Related guides

More cheat sheets