Headers are key-value pairs sent in both requests and responses. Names are case-insensitive. Values are strings. Multiple values can be comma-separated or sent as multiple header lines.
Header-Name: value
Header-Name: value1, value2
Headers are grouped by purpose, not by whether they appear in requests or responses.
Request Headers
Sent by the client to provide context about the request, the client, and what it will accept.
Identity & Routing
Header
Example
Description
Host
Host: api.example.com
Target host and port. Mandatory in HTTP/1.1. Enables virtual hosting (multiple sites on one IP).
User-Agent
User-Agent: Mozilla/5.0 ...
Client software identity. Browser, version, OS.
Referer
Referer: https://example.com/page
URL of the page that initiated the request. Note: intentionally misspelled in the spec.
Origin
Origin: https://app.example.com
Origin of the request. Used in CORS. Does not include path.
Cookie not sent on cross-site sub-resource requests, but sent on top-level navigation. Default in modern browsers.
SameSite=None
Cookie sent on all cross-site requests. Requires Secure.
⚠️
SameSite=None requires the Secure attribute. Browsers silently reject SameSite=None cookies that are not also marked Secure.
Rate Limiting (Common Conventions)
Not standardized in HTTP/1.1; widely adopted by APIs.
Header
Example
Description
X-RateLimit-Limit
X-RateLimit-Limit: 1000
Max requests allowed in the window.
X-RateLimit-Remaining
X-RateLimit-Remaining: 42
Requests remaining in the current window.
X-RateLimit-Reset
X-RateLimit-Reset: 1706745600
Unix timestamp when the window resets.
Retry-After
Retry-After: 30
Seconds to wait before retrying. Used with 429 and 503. Can be a date instead of seconds.
Caching Headers
Caching headers control how responses are stored and reused by browsers, CDNs, and proxies.
Header
Direction
Description
Cache-Control
Both
Primary cache directive. See directives below.
Expires
Response
Absolute expiry date. Overridden by Cache-Control: max-age. Legacy.
ETag
Response
Version identifier. Client sends back in If-None-Match.
Last-Modified
Response
Modification timestamp. Client sends back in If-Modified-Since.
Pragma
Both
Legacy no-cache directive for HTTP/1.0 proxies. Effectively replaced by Cache-Control.
Cache-Control Directives
ℹ️
Cache-Control: no-cache does not mean “don’t cache.” It means “store it, but revalidate with the server before every use.” Use no-store to actually prevent caching.
Directive
Description
max-age=N
Cache for N seconds from the response date.
s-maxage=N
Override max-age for shared caches (CDNs, proxies).
no-store
Never cache. Response must not be stored anywhere.
no-cache
Store but always revalidate with server before using.
private
Only browser cache; not shared caches (CDNs). Suitable for user-specific content.
public
Any cache may store the response.
must-revalidate
Cache must not serve stale content; must revalidate with server when expired.
immutable
Resource will never change during max-age. Browser won’t revalidate even on reload. For content-hashed assets.
stale-while-revalidate=N
Serve stale content for N seconds while revalidating in the background.
Directive
Description
no-cache
Force revalidation for this request even if cached copy is fresh.
no-store
Do not store any part of this request or response.
max-age=0
Treat any cached copy as stale; require fresh response.
max-stale=N
Client will accept a stale response up to N seconds past expiry.
Common Cache Patterns
Use Case
Cache-Control Value
Content-hashed static assets (JS, CSS)
public, max-age=31536000, immutable
HTML pages
no-cache (revalidate every time)
Private user data
private, no-store
API responses (short TTL)
private, max-age=60
CDN-cached API responses
public, s-maxage=300, max-age=0
Security Headers
Set by the server to instruct the browser on security policies.
Header
Example
Description
Strict-Transport-Security (HSTS)
max-age=31536000; includeSubDomains; preload
Forces browser to use HTTPS for the domain for max-age seconds. preload submits to browser preload lists.
Controls which sources the browser may load resources from. Primary defense against XSS.
X-Content-Type-Options
nosniff
Prevents browser from MIME-sniffing. Forces use of declared Content-Type.
X-Frame-Options
DENY or SAMEORIGIN
Controls iframe embedding. Replaced by CSP frame-ancestors but still widely used.
Referrer-Policy
strict-origin-when-cross-origin
Controls how much of the Referer URL is sent on navigation.
Permissions-Policy
camera=(), microphone=()
Controls which browser APIs the page may use. Replaces Feature-Policy.
Cross-Origin-Opener-Policy (COOP)
same-origin
Isolates browsing context from cross-origin windows. Required to enable SharedArrayBuffer.
Cross-Origin-Embedder-Policy (COEP)
require-corp
Requires all sub-resources to opt in to cross-origin loading. Also required for SharedArrayBuffer.
Cross-Origin-Resource-Policy (CORP)
same-site
Restricts who can load the resource.
CORS Headers
Cross-Origin Resource Sharing — allows controlled cross-origin requests from browsers.
Response headers (set by server):
Header
Example
Description
Access-Control-Allow-Origin
* or https://app.example.com
Which origins may access the resource. * disallows credentials.
Access-Control-Allow-Methods
GET, POST, PUT
Allowed HTTP methods for cross-origin requests.
Access-Control-Allow-Headers
Content-Type, Authorization
Allowed request headers.
Access-Control-Allow-Credentials
true
Whether cookies/auth headers are included. Cannot be used with * origin.
Access-Control-Max-Age
86400
Seconds the preflight response may be cached.
Access-Control-Expose-Headers
X-Request-Id
Response headers the browser JS may read beyond the safe defaults.
⚠️
Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true are mutually exclusive. Browsers will block the response if both are set. Use an explicit origin (e.g., https://app.example.com) when credentials are required.
Preflight flow (for non-simple requests):
sequenceDiagram
participant B as Browser
participant S as Server
B->>S: OPTIONS /api/data (preflight)
Note right of B: Origin: https://app.example.com
S->>B: 204 No Content
Note left of S: Access-Control-Allow-Origin: https://app.example.com
Note left of S: Access-Control-Allow-Methods: POST
B->>S: POST /api/data (actual request)
S->>B: 200 OK
Custom / Vendor Headers
ℹ️
The X- prefix convention was deprecated by RFC 6648 in 2012. New custom headers should not use X-. Existing ones (X-Forwarded-For, X-Request-Id, etc.) remain in widespread use and are not going away.
Header
Description
X-Request-Id
Unique identifier for the request. Used for distributed tracing and log correlation.
X-Correlation-Id
Similar to X-Request-Id. Common in microservice architectures.
X-Real-IP
Original client IP as set by Nginx. Simpler alternative to X-Forwarded-For.
X-Api-Version
API version indicator. Some APIs use this instead of URL versioning.