HTTP Headers Cheatsheet
httpEssential HTTP headers for web developers — security, caching, CORS.
Request Headers
Accept: <MIME_type>/<MIME_subtype>Specifies the media types the client can process in the response
Accept: application/json, text/html;q=0.9, */*;q=0.8Authorization: <auth-scheme> <credentials>Contains credentials to authenticate the client with the server
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...Content-Type: <media-type>; charset=<charset>Indicates the media type of the request body being sent
Content-Type: application/json; charset=utf-8Cookie: <name>=<value>; <name2>=<value2>Sends stored cookies from the client to the server
Cookie: sessionId=abc123; theme=dark; lang=enUser-Agent: <product>/<version> (<system-info>)Identifies the client application, operating system, and version
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0If-Modified-Since: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMTMakes request conditional; returns 304 if resource unchanged since date
If-Modified-Since: Wed, 21 Oct 2024 07:28:00 GMTIf-None-Match: "<etag_value>"Makes request conditional; returns 304 if ETag matches cached version
If-None-Match: "33a64df551425fcc55e4d42a148795d9"Origin: <scheme>://<hostname>:<port>Indicates the origin of the request; used for CORS and security
Origin: https://www.example.comReferer: <url>Contains the URL of the page that linked to the current request
Referer: https://www.google.com/search?q=http+headersResponse Headers
Content-Type: <media-type>; charset=<charset>; boundary=<boundary>Indicates the media type of the response body
Content-Type: text/html; charset=UTF-8Content-Length: <length-in-bytes>Indicates the size of the response body in bytes
Content-Length: 3495Cache-Control: <directive>, <directive>Specifies caching directives for both requests and responses
Cache-Control: public, max-age=31536000, immutableETag: "<etag_value>" | W/"<etag_value>"Unique identifier for a specific version of a resource
ETag: "33a64df551425fcc55e4d42a148795d9f8f"Last-Modified: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMTDate and time the resource was last modified on the server
Last-Modified: Tue, 15 Nov 2024 12:45:26 GMTLocation: <url>Indicates the URL to redirect a page to; used with 3xx or 201 status
Location: https://www.example.com/new-pageSet-Cookie: <name>=<value>; <attributes>Sends a cookie from the server to be stored on the client
Set-Cookie: sessionId=abc123; HttpOnly; Secure; SameSite=Strict; Max-Age=86400Vary: <header-name>, <header-name>Indicates which request headers affect the response content for caching
Vary: Accept-Encoding, Accept-Language, OriginSecurity Headers
Content-Security-Policy: <directive> <source>; <directive> <source>Controls resources the browser is allowed to load for the page
Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.example.com; style-src 'self' 'unsafe-inline'X-Frame-Options: DENY | SAMEORIGINPrevents the page from being embedded in iframes to stop clickjacking
X-Frame-Options: DENYX-Content-Type-Options: nosniffPrevents browsers from MIME-sniffing a response from declared content-type
X-Content-Type-Options: nosniffStrict-Transport-Security: max-age=<seconds>; includeSubDomains; preloadForces browsers to use HTTPS for all future requests to the domain
Strict-Transport-Security: max-age=31536000; includeSubDomains; preloadReferrer-Policy: <policy>Controls how much referrer information is sent with requests
Referrer-Policy: strict-origin-when-cross-originPermissions-Policy: <feature>=(<allowlist>)Controls which browser features and APIs can be used on the page
Permissions-Policy: geolocation=(self), camera=(), microphone=()CORS Headers
Access-Control-Allow-Origin: <origin> | *Specifies which origins are allowed to access the resource
Access-Control-Allow-Origin: https://www.example.comAccess-Control-Allow-Methods: <method>, <method>Specifies allowed HTTP methods when accessing the resource
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONSAccess-Control-Allow-Headers: <header-name>, <header-name>Specifies allowed request headers for cross-origin requests
Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-WithAccess-Control-Allow-Credentials: trueIndicates whether the response can be shared when credentials are included
Access-Control-Allow-Credentials: trueAccess-Control-Max-Age: <delta-seconds>Indicates how long preflight request results can be cached
Access-Control-Max-Age: 86400Access-Control-Expose-Headers: <header-name>, <header-name>Specifies which headers can be exposed to JavaScript in the browser
Access-Control-Expose-Headers: X-Custom-Header, Content-LengthCommon Cache-Control Directives
Cache-Control: max-age=<seconds>Maximum time a resource is considered fresh in seconds
Cache-Control: max-age=3600Cache-Control: no-cacheMust revalidate with server before using cached response
Cache-Control: no-cacheCache-Control: no-storeResponse must not be stored in any cache; always fetch fresh
Cache-Control: no-storeCache-Control: publicResponse can be cached by any cache including CDNs and proxies
Cache-Control: public, max-age=86400Cache-Control: privateResponse is intended for a single user and must not be cached by shared caches
Cache-Control: private, max-age=3600Cache-Control: immutableIndicates the response body will not change over time
Cache-Control: public, max-age=31536000, immutableCache-Control: stale-while-revalidate=<seconds>Serve stale content while revalidating in the background
Cache-Control: max-age=3600, stale-while-revalidate=86400Content-Security-Policy Directives
Content-Security-Policy: default-src <source>Fallback policy for all resource types not explicitly defined
Content-Security-Policy: default-src 'self'Content-Security-Policy: script-src <source>Controls valid sources for JavaScript execution
Content-Security-Policy: script-src 'self' 'unsafe-inline' https://cdn.example.comContent-Security-Policy: style-src <source>Controls valid sources for stylesheets
Content-Security-Policy: style-src 'self' 'unsafe-inline'Content-Security-Policy: img-src <source>Controls valid sources for images and favicons
Content-Security-Policy: img-src 'self' data: https:Content-Security-Policy: connect-src <source>Controls URLs that can be loaded using fetch, XHR, and WebSocket
Content-Security-Policy: connect-src 'self' https://api.example.com wss://ws.example.comContent-Security-Policy: frame-ancestors <source>Specifies valid parents that may embed the page in frames
Content-Security-Policy: frame-ancestors 'self' https://trusted.comContent-Security-Policy: upgrade-insecure-requestsInstructs browsers to upgrade HTTP requests to HTTPS
Content-Security-Policy: upgrade-insecure-requests