← Home

HTTP Headers Cheatsheet

Every HTTP header you need to know — request, response, CORS, security, caching, and content negotiation. Each with example values and clear explanations for real-world usage.

Request Headers

Acceptapplication/json, text/html;q=0.9, */*;q=0.8

Media types the client can handle. Servers use this to pick the best response format. The q parameter sets priority (0-1).

AuthorizationBearer eyJhbGciOiJIUzI1NiIs...

Credentials for authenticating the client. Common schemes: Bearer (JWT/OAuth tokens), Basic (base64 user:pass), Digest, and API key.

Cache-Controlno-cache

Directives for request caching. no-cache forces revalidation, no-store prevents caching, max-age=0 treats cached copy as stale.

Content-Typeapplication/json; charset=utf-8

Media type of the request body. Required for POST/PUT/PATCH. Common values: application/json, multipart/form-data, application/x-www-form-urlencoded.

Cookiesession_id=abc123; theme=dark; lang=en

Cookies previously set by the server via Set-Cookie. Sent automatically on every request to the matching domain and path.

Hostapi.example.com:443

The domain name (and optional port) of the target server. Required in HTTP/1.1. Enables virtual hosting (multiple sites on one IP).

Originhttps://myapp.example.com

The origin (scheme + domain + port) initiating a cross-origin request. Used by CORS and CSRF protection. Not sent for same-origin requests.

Refererhttps://example.com/products?page=2

URL of the page that linked to the current request. Useful for analytics and logging. Referrer-Policy controls what gets sent.

User-AgentMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36

Identifies the client software. Contains browser name, version, OS, and engine. Used for content negotiation and analytics.

If-None-MatchW/"abc123", "def456"

Conditional request with ETag values. Server returns 304 Not Modified if the resource matches any listed ETag, saving bandwidth.

If-Modified-SinceWed, 21 Oct 2025 07:28:00 GMT

Conditional request with a date. Server returns 304 if the resource hasn't changed since this timestamp. Used with Last-Modified.

Accept-Encodinggzip, deflate, br, zstd

Compression algorithms the client supports. Server picks one and indicates it via Content-Encoding. Brotli (br) offers best compression for web.

Accept-Languageen-US,en;q=0.9,es;q=0.8

Preferred natural languages for the response. Quality values indicate preference. Used for internationalization and localization.

X-Requested-WithXMLHttpRequest

Indicates AJAX requests (set by jQuery and other libraries). Some servers use this for CSRF detection — not a standard header.

Rangebytes=0-1023

Request only part of a resource. Enables resumable downloads and video seeking. Server responds with 206 Partial Content.

Response Headers

Content-Typetext/html; charset=utf-8

Media type of the response body. Always include charset for text types. Common: text/html, application/json, image/png, application/pdf.

Content-Length3495

Size of the response body in bytes. Enables the client to show download progress and detect truncated responses.

Content-Encodinggzip

Compression applied to the response body. Common values: gzip, br (Brotli), deflate, zstd. Client decodes transparently.

Cache-Controlpublic, max-age=31536000, immutable

Caching directives for the response. public/private controls who can cache, max-age sets TTL in seconds, immutable means it never changes.

Set-Cookiesession=abc123; Path=/; HttpOnly; Secure; SameSite=Lax; Max-Age=86400

Sets a cookie on the client. HttpOnly blocks JS access, Secure requires HTTPS, SameSite prevents CSRF (Strict, Lax, None).

ETagW/"v1.2.3-abc123"

Entity tag — a fingerprint of the resource. W/ prefix means weak (semantically equivalent). Used with If-None-Match for conditional requests.

Last-ModifiedTue, 15 Nov 2025 12:45:26 GMT

When the resource was last changed. Less precise than ETag. Used with If-Modified-Since for conditional requests.

Locationhttps://example.com/new-page

Redirect target URL. Used with 301 (permanent), 302 (found), 303 (see other), and 307 (temporary redirect) status codes.

Access-Control-Allow-Originhttps://myapp.example.com

CORS: specifies which origin can access the response. Use * for public APIs, specific origin for credentials. Single origin only per response.

X-Content-Type-Optionsnosniff

Prevents browsers from MIME-sniffing the Content-Type. Always set to nosniff. Stops attacks that exploit type confusion.

Strict-Transport-Securitymax-age=63072000; includeSubDomains; preload

Forces HTTPS for the domain. max-age in seconds, includeSubDomains applies to all subdomains, preload adds to browser preload list.

X-Request-Idreq_a1b2c3d4-e5f6-7890

Unique identifier for the request/response pair. Essential for distributed tracing, debugging, and correlating logs across services.

Retry-After120

Seconds (or date) the client should wait before retrying. Used with 429 Too Many Requests and 503 Service Unavailable responses.

WWW-AuthenticateBearer realm="api", error="invalid_token"

Sent with 401 Unauthorized. Tells the client which authentication scheme to use and provides error details for failed auth.

CORS Headers

Access-Control-Allow-Originhttps://app.example.com

Which origin is allowed. Must match the requesting Origin exactly or be *. Wildcards cannot be used when credentials (cookies) are included.

Access-Control-Allow-MethodsGET, POST, PUT, DELETE, PATCH, OPTIONS

HTTP methods allowed for cross-origin requests. Sent in preflight (OPTIONS) response. Simple methods (GET, HEAD, POST) don't trigger preflight.

Access-Control-Allow-HeadersContent-Type, Authorization, X-Request-Id

Custom headers the client can send. Simple headers (Accept, Content-Type for simple values, etc.) don't need listing. Sent in preflight response.

Access-Control-Expose-HeadersX-Total-Count, X-Request-Id, Link

Response headers the browser JS can read. By default only safe-listed headers are exposed. Custom headers must be explicitly listed here.

Access-Control-Max-Age86400

How long (in seconds) the preflight result can be cached. Reduces OPTIONS requests. Browsers cap this (Chrome: 2 hours, Firefox: 24 hours).

Access-Control-Allow-Credentialstrue

Allow cookies, Authorization headers, and TLS client certs in cross-origin requests. When true, Allow-Origin cannot be * — must be a specific origin.

Access-Control-Request-MethodPUT

Sent by the browser in preflight (OPTIONS) to indicate which method the actual request will use. Server checks this before allowing.

Access-Control-Request-HeadersContent-Type, Authorization

Sent in preflight to indicate which custom headers the actual request will include. Server responds with Access-Control-Allow-Headers.

Originhttps://app.example.com

Sent automatically by the browser with cross-origin requests and same-origin POST. The server compares this against its allowed origins list.

Vary: OriginVary: Origin

Tells caches that the response varies by Origin header. Essential when Access-Control-Allow-Origin is not * to prevent cache poisoning.

Security Headers

Content-Security-Policydefault-src 'self'; script-src 'self' 'nonce-abc123'; style-src 'self' 'unsafe-inline'; img-src * data:

Controls which resources the browser can load. Mitigates XSS, clickjacking, and data injection. Use nonces or hashes instead of unsafe-inline for scripts.

X-Frame-OptionsDENY

Controls if the page can be embedded in frames. DENY blocks all framing, SAMEORIGIN allows same-origin only. Being replaced by CSP frame-ancestors.

X-XSS-Protection0

Legacy XSS filter. Set to 0 to disable (recommended) — the built-in filter can introduce vulnerabilities. Rely on Content-Security-Policy instead.

Strict-Transport-Securitymax-age=31536000; includeSubDomains; preload

Enforces HTTPS. After first visit, browser upgrades all HTTP to HTTPS for max-age seconds. preload submits to browser preload lists for zero-trust-on-first-use.

Permissions-Policycamera=(), microphone=(), geolocation=(self), payment=(self "https://pay.example.com")

Controls browser feature access. () disables entirely, (self) allows same-origin, specific origins can be listed. Replaces Feature-Policy.

Referrer-Policystrict-origin-when-cross-origin

Controls how much referrer info is sent. strict-origin-when-cross-origin sends full URL for same-origin, origin-only cross-origin, nothing on downgrade.

X-Content-Type-Optionsnosniff

Stops browsers from guessing the MIME type. Always use nosniff. Prevents attacks where a disguised file is interpreted as an executable type.

Cross-Origin-Embedder-Policyrequire-corp

Ensures all cross-origin resources explicitly grant permission. Required (with COOP) to enable SharedArrayBuffer and high-resolution timers.

Cross-Origin-Opener-Policysame-origin

Isolates the browsing context. same-origin prevents cross-origin windows from accessing window.opener. Enables cross-origin isolation with COEP.

Cross-Origin-Resource-Policysame-site

Controls who can load a resource. same-origin, same-site, or cross-origin. Protects resources from being embedded by untrusted sites.

X-DNS-Prefetch-Controloff

Controls browser DNS prefetching. Set to off for privacy-sensitive pages to prevent DNS lookups revealing which links are on the page.

X-Permitted-Cross-Domain-Policiesnone

Controls Flash and PDF cross-domain policy files. Set to none to prevent Adobe products from loading data from your domain.

Caching Headers

Cache-Controlpublic, max-age=31536000, immutable

Primary caching directive. public: any cache can store. private: browser only. no-store: never cache. no-cache: must revalidate. stale-while-revalidate: serve stale while fetching.

Cache-Control: no-storeno-store, no-cache, must-revalidate, proxy-revalidate

Prevent all caching — for sensitive data. Combine all four directives for maximum compatibility across browsers and proxies.

Cache-Control: stale-while-revalidatemax-age=3600, stale-while-revalidate=86400

Serve stale content for up to 86400s while revalidating in background. Eliminates latency for cache refresh — great for semi-dynamic content.

ExpiresThu, 01 Dec 2025 16:00:00 GMT

Legacy cache expiration date. Superseded by Cache-Control max-age. If both present, max-age wins. Use HTTP date format only.

ETag"33a64df551425fcc55e4d42a148795d9f25f89d4"

Fingerprint of the resource content. Strong ETags must change on any byte change. Used with If-None-Match for conditional requests (304 responses).

If-None-Match"33a64df551425fcc55e4d42a148795d9f25f89d4"

Client sends previous ETag. If it matches, server responds 304 with no body — saves bandwidth. Supports multiple ETags and wildcard *.

If-Modified-SinceWed, 21 Oct 2025 07:28:00 GMT

Client sends previous Last-Modified date. If unchanged, server responds 304. Less precise than ETag (1-second resolution). Used as fallback.

VaryAccept-Encoding, Accept-Language, Origin

Lists request headers that cause the response to vary. Caches store separate copies for each combination. Critical for correct CDN behavior.

Age3600

Seconds since the response was generated by the origin server. Set by caches/CDNs. Helps clients calculate remaining freshness from max-age.

Pragmano-cache

HTTP/1.0 backward compatibility. Equivalent to Cache-Control: no-cache. Include both for legacy proxy support. Only meaningful value: no-cache.

CDN-Cache-Controlmax-age=60

CDN-specific caching directive (Cloudflare, Fastly). Overrides Cache-Control for the CDN layer while letting browsers use different TTLs.

Surrogate-Controlmax-age=3600

Caching directive for reverse proxies and CDNs (Varnish, Fastly). Stripped before reaching the client. Takes precedence over Cache-Control for the proxy.

Content Negotiation

Accepttext/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8

Client's preferred media types. Server picks the best match. Quality values (q=0-1) indicate priority. Used for format negotiation (HTML vs JSON).

Accept-Encodingbr, gzip, deflate, zstd

Compression algorithms the client supports. Server picks one and sets Content-Encoding. Brotli (br) has best ratio for text, zstd for general use.

Accept-Languageen-US,en;q=0.9,fr;q=0.8,de;q=0.7

Client's preferred languages. Server uses this for i18n content selection. Quality values set priority. Falls back to server default if no match.

Content-Encodingbr

Compression applied to the response body. Must match one of the client's Accept-Encoding values. Transparent to the application layer.

Content-Languageen-US

The natural language of the response content. Helps screen readers and translation tools. Can be a comma-separated list for multilingual content.

Content-Typeapplication/json; charset=utf-8

The media type and character encoding of the body. Tells the client how to parse the response. Always include charset for text types.

Transfer-Encodingchunked

How the message body is transferred. chunked sends data in pieces without knowing total size upfront. Mutually exclusive with Content-Length.

Accept-Rangesbytes

Indicates the server supports partial requests. bytes enables Range requests for resumable downloads and video seeking. none disables.

Content-Dispositionattachment; filename="report.pdf"

How the browser should handle the body. attachment triggers download, inline renders in browser. filename suggests the download name.

Content-Rangebytes 200-999/8000

Indicates which part of the full resource is included in the response. Sent with 206 Partial Content. Format: unit start-end/total.

VaryAccept, Accept-Encoding, Accept-Language

Tells caches which request headers affect the response. A response for Accept: text/html differs from Accept: application/json — caches must store both.

Content-NegotiationNegotiated response via Accept header

Servers can return 406 Not Acceptable when they cannot produce a response matching any of the client's Accept values. Include available types in the response.

FAQ

What is the difference between Cache-Control: no-cache and no-store?

no-cache allows the browser to store the response but requires revalidation with the server before using it (via If-None-Match or If-Modified-Since). no-store tells the browser to never store the response at all — it must be fetched fresh every time. For sensitive data like banking pages, use no-store. For content that changes often but benefits from conditional requests, use no-cache.

How do CORS preflight requests work?

When a cross-origin request uses a non-simple method (PUT, DELETE, PATCH) or custom headers, the browser first sends an OPTIONS request (preflight) with Access-Control-Request-Method and Access-Control-Request-Headers. The server must respond with appropriate Access-Control-Allow-* headers. If approved, the browser sends the actual request. Preflight results can be cached via Access-Control-Max-Age to reduce latency.

Which security headers should every site set?

At minimum: Strict-Transport-Security (force HTTPS), X-Content-Type-Options: nosniff (prevent MIME sniffing), Content-Security-Policy (control resource loading), X-Frame-Options: DENY (prevent clickjacking), and Referrer-Policy: strict-origin-when-cross-origin. Also consider Permissions-Policy to disable unused browser features and Cross-Origin-Opener-Policy for browsing context isolation.

What is the ETag header and how does conditional caching work?

An ETag is a fingerprint (hash) of a resource. On first request, the server sends the ETag. On subsequent requests, the browser sends If-None-Match with the cached ETag. If the resource hasn't changed, the server returns 304 Not Modified with no body — saving bandwidth. This is more reliable than Last-Modified/If-Modified-Since which only has 1-second resolution and can miss changes.

Related Resources