HTTP Headers Cheatsheet

Common request + response headers, what they do, and when they matter.

1 credit

Request headers

9 items
Accept
Media type client wants back (`application/json`)
Accept-Language
Preferred languages (`en-US,en;q=0.9`)
Authorization
`Bearer <token>` or `Basic base64(user:pass)`
Content-Type
Body media type (needed for POST/PUT JSON)
Content-Length
Bytes in body (set automatically)
Cookie
`k1=v1; k2=v2`
If-None-Match
ETag from prior response — enables 304 Not Modified
User-Agent
Client string (don't parse in business logic)
X-Forwarded-For
Client IP chain behind proxies — trust carefully

Response headers

10 items
Content-Type
Body media type; charset for text
Cache-Control
`public, max-age=31536000, immutable` for hashed static
ETag
Opaque version token for conditional requests
Last-Modified
Fallback for ETag — weaker
Location
Where redirects go (for 3xx) or created resource (201)
Set-Cookie
`name=v; Path=/; HttpOnly; Secure; SameSite=Lax`
Access-Control-Allow-Origin
CORS — `*` or specific origin
Strict-Transport-Security
`max-age=31536000; includeSubDomains` — forces HTTPS
Content-Security-Policy
Allowed sources for scripts/styles/media
X-Frame-Options
`DENY` or `SAMEORIGIN` to block clickjacking

Caching decision tree

  • HTML pages: `Cache-Control: no-cache` + ETag — always revalidate, cheap 304.
  • Hashed assets (`app.abc123.js`): `Cache-Control: public, max-age=31536000, immutable` — cache forever.
  • User-specific data: `Cache-Control: private, no-store` — never cache on CDN.
  • API reads rarely changing: `Cache-Control: public, max-age=60, stale-while-revalidate=300`.

Further reading