What it is
A reference for common HTTP headers and their purpose, invaluable for debugging web applications, understanding client-server interactions, and customizing HTTP requests/responses.
Installation
This is a reference document, not a software tool. No installation is required.
Core Concepts
HTTP headers are key-value pairs sent in the request or response messages. They provide metadata about the message body, the client, the server, and the transaction itself.
Commands / Usage
Request Headers (Sent by Client)
General Headers
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Indicates which content types the client can understand.qvalues specify preference.Accept-Encoding: gzip, deflate, brIndicates which content encoding algorithms the client supports.Accept-Language: en-US,en;q=0.5Indicates the natural languages that are preferred by the client.Authorization: Basic dXNlcjpwYXNzd29yZA==Contains credentials for authenticating the client with the server.Basicis a common scheme.Cache-Control: no-cache, no-store, must-revalidateSpecifies caching directives for both the client and the server.Connection: keep-aliveControls whether the network connection stays open after the current transaction completes.Cookie: sessionid=abcdef123456; csrftoken=zyxwvu987654Contains previously sent HTTP cookies.DNT: 1"Do Not Track" signal to indicate that the user does not want to be tracked.Host: www.example.comSpecifies the domain name of the server (for virtual hosting).If-Modified-Since: Tue, 15 Nov 1994 12:45:26 GMTUsed for conditional requests; the response will only be sent if the resource has changed since this date.Origin: https://www.example.comIndicates that the request originated from a particular web origin.Referer: https://www.example.com/previous-pageThe address of the previous web page from which a link to the currently requested page was followed.User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0A characteristic string that uniquely identifies the user agent (browser, crawler, etc.).
Request Body Headers
Content-Length: 1234The size of the request message body, in bytes.Content-Type: application/jsonThe media type of the body of the request message.
Response Headers (Sent by Server)
General Headers
Access-Control-Allow-Origin: https://www.example.comIndicates whether the response can be shared with the requesting code from a given origin (CORS).Connection: closeIndicates that the network connection will be closed after the transaction is complete.Date: Tue, 15 Nov 1994 08:12:31 GMTThe date and time at which the message was originated.Server: Apache/2.4.52 (Ubuntu)Contains information about the software used by the origin server to handle the request.Transfer-Encoding: chunkedSpecifies that the message is being sent in a sequence of chunks.
Response Body Headers
Content-Encoding: gzipIndicates that the resource is encoded and that this encoding must be used when decoding the entity body.Content-Length: 5678The size of the response message body, in bytes.Content-Type: application/json; charset=utf-8The media type of the body of the response message.charsetspecifies the character encoding.
Caching Headers
ETag: "33a64df551425f054c1469139ab87f11"An identifier for a specific version of a resource, often used for cache validation.Expires: Wed, 21 Oct 2015 07:28:00 GMTA date/time after which the response is considered stale.Last-Modified: Mon, 14 Nov 1994 12:30:00 GMTThe date and time at which the server believes the origin server sent the response.Vary: Accept-Encoding, User-AgentIndicates that the selection of a cached response depends on the values of the specified request headers.
Redirection Headers
Location: https://www.example.com/new-locationUsed in responses to requests for resources that have been moved to a different URI.
Client-Side Control Headers
Set-Cookie: sessionid=abcdef123456; HttpOnly; Secure; SameSite=LaxUsed by the server to send a cookie to the client.HttpOnly,Secure, andSameSiteare important security attributes.
Security Headers
Content-Security-Policy: default-src 'self'; script-src 'self' https://apis.google.comDefines a set of rules that a browser must follow for content loaded by a page.Strict-Transport-Security: max-age=31536000; includeSubDomains; preloadInstructs browsers to only connect to the server using HTTPS.X-Content-Type-Options: nosniffPrevents the browser from trying to MIME-sniff the content type if it’s different from the declared one.X-Frame-Options: DENYSpecifies whether the page can be displayed in a<frame>,<iframe>,<embed>, or<object>.X-XSS-Protection: 1; mode=blockEnables built-in cross-site scripting (XSS) protection.
Common Patterns
- Checking a specific header with
curl:curl -I https://www.example.comFetches only the headers from the server’s response. - Sending a custom header with
curl:curl -H "X-Custom-Header: MyValue" https://api.example.com/dataAdds a custom header to the request. - Inspecting request headers in a web browser: Open your browser’s developer tools (usually F12), navigate to the "Network" tab, and select a request. The "Headers" section will show both request and response headers.
- Using
curlto simulate a specificUser-Agent:curl -A "MyCustomBot/1.0" https://www.example.com/feed.xmlIdentifies your request as a specific bot. - Sending authentication credentials with
curl:curl -u "username:password" https://api.example.com/protectedUses Basic Authentication. Equivalent to-H "Authorization: Basic base64(username:password)". - Checking cacheability of a resource:
curl -I https://www.example.com/static/image.pngLook forCache-Control,Expires,ETag, andLast-Modifiedheaders.
Gotchas
- Case Insensitivity: While header names are case-insensitive according to RFCs, values are often case-sensitive. It’s best practice to treat header names as case-insensitive and values as case-sensitive.
Content-Typevs.Accept:Content-Typedescribes the body of the message being sent (request or response).Acceptdescribes what the client is willing to receive.Content-Lengthvs.Transfer-Encoding: IfTransfer-Encodingis present,Content-Lengthmust be ignored.chunkedis a common value forTransfer-Encoding.- CORS (
Access-Control-Allow-Origin): If a web page makes a cross-origin request (e.g., fromhttp://localhost:8080tohttps://api.example.com), the server must includeAccess-Control-Allow-Originin its response headers to permit the request. Set-CookieSecurity Attributes:HttpOnly: Prevents JavaScript from accessing the cookie.Secure: Ensures the cookie is only sent over HTTPS.SameSite: Controls when cookies are sent with cross-site requests (e.g.,Strict,Lax,None).
RefererHeader: TheRefererheader is not always sent for security or privacy reasons (e.g., navigating from HTTPS to HTTP, or if explicitly blocked by browser settings). Its spelling is a historical typo that has become standard.HostHeader: Essential for HTTP/1.1 and later, especially with virtual hosting where a single IP address serves multiple websites. Requests without aHostheader are often rejected.