跳转到主要内容

HTTP headers

HTTP headers let the client and the server pass additional information with a message in a request or response. In HTTP/1.X, a header is a case-insensitive name followed by a colon, then optional whitespace which will be ignored, and finally by its value (for example: Allow: POST). In HTTP/2 and above, headers are displayed in lowercase when viewed in developer tools (accept: */*), and prefixed with a colon for a special group of pseudo-headers (:status: 200). You can find more information on the syntax in each protocol version in the HTTP messages page.

Custom proprietary headers have historically been used with an X- prefix, but this convention was deprecated in 2012 because of the inconveniences it caused when nonstandard fields became standard in RFC 6648; others are listed in the IANA HTTP Field Name Registry, whose original content was defined in RFC 4229. The IANA registry lists headers, including information about their status.

Headers can be grouped according to their contexts:

Headers can also be grouped according to how {{Glossary("Proxy_server", "proxies")}}proxies handle them:

  • End-to-end headers
    • : These headers must be transmitted to the final recipient of the message: the server for a request, or the client for a response. Intermediate proxies must retransmit these headers unmodified and caches must store them.
  • Hop-by-hop headers
    • : These headers are meaningful only for a single transport-level connection, and must not be retransmitted by proxies or cached. Note that only hop-by-hop headers may be set using the {{HTTPHeader("Connection")}}Connection header.

Authentication

Caching

  • {{HTTPHeader("Age")}}Age
    • : The time, in seconds, that the object has been in a proxy cache.
  • {{HTTPHeader("Cache-Control")}}Control
    • : Directives for caching mechanisms in both requests and responses.
  • {{HTTPHeader("Clear-Site-Data")}}Data
    • : Clears browsing data (e.g., cookies, storage, cache) associated with the requesting website.
  • {{HTTPHeader("Expires")}}Expires
    • : The date/time after which the response is considered stale.
  • {{HTTPHeader("No-Vary-Search")}} {{experimental_inline}}Search
    • : Specifies a set of rules that define how a URL's query parameters will affect cache matching. These rules dictate whether the same URL with different URL parameters should be saved as separate browser cache entries.

Conditionals

  • {{HTTPHeader("Last-Modified")}}Modified
    • : The last modification date of the resource, used to compare several versions of the same resource. It is less accurate than {{HTTPHeader("ETag")}}ETag, but easier to calculate in some environments. Conditional requests using {{HTTPHeader("If-Modified-Since")}}Since and {{HTTPHeader("If-Unmodified-Since")}}Since use this value to change the behavior of the request.
  • {{HTTPHeader("ETag")}}ETag
    • : A unique string identifying the version of the resource. Conditional requests using {{HTTPHeader("If-Match")}}Match and {{HTTPHeader("If-None-Match")}}Match use this value to change the behavior of the request.
  • {{HTTPHeader("If-Match")}}Match
    • : Makes the request conditional, and applies the method only if the stored resource matches one of the given ETags.
  • {{HTTPHeader("If-None-Match")}}Match
    • : Makes the request conditional, and applies the method only if the stored resource doesn't match any of the given ETags. This is used to update caches (for safe requests), or to prevent uploading a new resource when one already exists.
  • {{HTTPHeader("If-Modified-Since")}}Since
    • : Makes the request conditional, and expects the resource to be transmitted only if it has been modified after the given date. This is used to transmit data only when the cache is out of date.
  • {{HTTPHeader("If-Unmodified-Since")}}Since
    • : Makes the request conditional, and expects the resource to be transmitted only if it has not been modified after the given date. This ensures the coherence of a new fragment of a specific range with previous ones, or to implement an optimistic concurrency control system when modifying existing documents.
  • {{HTTPHeader("Vary")}}Vary
    • : Determines how to match request headers to decide whether a cached response can be used rather than requesting a fresh one from the origin server.

Connection management

  • {{HTTPHeader("Connection")}}Connection
    • : Controls whether the network connection stays open after the current transaction finishes.
  • {{HTTPHeader("Keep-Alive")}}Alive
    • : Controls how long a persistent connection should stay open.

Content negotiation

For more details, refer to the Content negotiation article.

  • {{HTTPHeader("Accept")}}Accept
    • : Informs the server about the {{Glossary("MIME_type", "types")}}types of data that can be sent back.
  • {{HTTPHeader("Accept-Encoding")}}Encoding
  • {{HTTPHeader("Accept-Language")}}Language
    • : Informs the server about the human language the server is expected to send back. This is a hint and is not necessarily under the full control of the user: the server should always pay attention not to override an explicit user choice (like selecting a language from a dropdown).
  • {{HTTPHeader("Accept-Patch")}}Patch
    • : A request content negotiation response header that advertises which media type the server is able to understand in a {{HTTPMethod("PATCH")}}PATCH request.
  • {{HTTPHeader("Accept-Post")}}Post
    • : A request content negotiation response header that advertises which media type the server is able to understand in a {{HTTPMethod("POST")}}POST request.
  • {{HTTPHeader("Accept-Query")}}Query
    • : A request content negotiation response header that advertises which media type the server is able to understand in a {{HTTPMethod("QUERY")}}QUERY request.

Controls

  • {{HTTPHeader("Expect")}}Expect
    • : Indicates expectations that need to be fulfilled by the server to properly handle the request.
  • {{HTTPHeader("Max-Forwards")}}Forwards
    • : When using TRACE, indicates the maximum number of hops the request can do before being reflected to the sender.

Cookies

CORS

For more information, refer to the CORS documentation.

Downloads

  • {{HTTPHeader("Content-Disposition")}}Disposition
    • : Indicates if the resource transmitted should be displayed inline (default behavior without the header), or if it should be handled like a download and the browser should present a "Save As" dialog.

Integrity digests

Integrity policy

Message body information

Message signatures

  • {{HTTPHeader("Accept-Signature")}}Signature
    • : The Accept-Signature header requests a signed response or subsequent request, specifying the components to sign and signature parameters.
  • {{HTTPHeader("Signature")}}Signature
    • : The Signature header contains one or more labeled signature values. Each label corresponds to an entry in Signature-Input.
  • {{HTTPHeader("Signature-Input")}}Input
    • : The Signature-Input header identifies the ordered list of message components covered by each signature and its metadata, such as the creation time and key identifier.

[!NOTE]NOTE: These definitions follow RFC 9421. The Signed HTTP Exchanges (SXG) draft also defines Accept-Signature and Signature with incompatible semantics, plus a distinct Signed-Headers header. However, the only browser SXG implementation, Chromium, does not support these as HTTP headers.

Preferences

Preferences can be sent by clients in requests to indicate optional behaviors for requests and responses. The server response may indicate if a preference is applied, in cases where it would otherwise be ambiguous for the client. Browsers have no native handling for sending preferences via these headers; they are used in custom, implementation-specific clients.

  • {{HTTPHeader("Prefer")}}Prefer
    • : Indicates preferences for specific server behaviors during request processing. For example, it can request minimal response content (return=minimal) or asynchronous processing (respond-async). The server processes the request normally if the header is unsupported.
  • {{HTTPHeader("Preference-Applied")}}Applied
    • : Informs the client which preferences specified in the Prefer header were applied by the server. It is a response-only header providing transparency about preference handling.

Proxies

  • {{HTTPHeader("Forwarded")}}Forwarded
    • : Contains information from the client-facing side of proxy servers that is altered or lost when a proxy is involved in the path of the request.
  • {{HTTPHeader("Via")}}Via
    • : Added by proxies, both forward and reverse proxies, and can appear in the request headers and the response headers.

Range requests

HTTP range requests allow the client to request a portion of a resource from the server. Range requests are useful for applications like media players that support random access, data tools that know they need only part of a large file, and download managers that let the user pause and resume a download.

  • {{HTTPHeader("Accept-Ranges")}}Ranges
    • : Indicates if the server supports range requests, and if so in which unit the range can be expressed.
  • {{HTTPHeader("Range")}}Range
    • : Indicates the part of a document that the server should return.
  • {{HTTPHeader("If-Range")}}Range
    • : Creates a conditional range request that is only fulfilled if the given etag or date matches the remote resource. Used to prevent downloading two ranges from incompatible version of the resource.
  • {{HTTPHeader("Content-Range")}}Range
    • : Indicates where in a full body message a partial message belongs.

Redirects

  • {{HTTPHeader("Location")}}Location
    • : Indicates the URL to redirect a page to.
  • {{HTTPHeader("Refresh")}}Refresh
    • : Directs the browser to reload the page or redirect to another. Takes the same value as the meta element with http-equiv="refresh".

Request context

  • {{HTTPHeader("From")}}From
    • : Contains an Internet email address for a human user who controls the requesting user agent.
  • {{HTTPHeader("Host")}}Host
    • : Specifies the domain name of the server (for virtual hosting), and (optionally) the TCP port number on which the server is listening.
  • {{HTTPHeader("Referer")}}Referer
    • : The address of the previous web page from which a link to the currently requested page was followed.
  • {{HTTPHeader("Referrer-Policy")}}Policy
    • : Governs which referrer information sent in the {{HTTPHeader("Referer")}}Referer header should be included with requests made.
  • {{HTTPHeader("User-Agent")}}Agent
    • : Contains a characteristic string that allows the network protocol peers to identify the application type, operating system, software vendor or software version of the requesting software user agent.

Response context

  • {{HTTPHeader("Allow")}}Allow
    • : Lists the set of HTTP request methods supported by a resource.
  • {{HTTPHeader("Server")}}Server
    • : Contains information about the software used by the origin server to handle the request.

Security

Fetch metadata request headers

{{Glossary("Fetch metadata request header", "Fetch metadata request headers")}}headers provide information about the context from which the request originated. A server can use them to make decisions about whether a request should be allowed, based on where the request came from and how the resource will be used.

  • {{HTTPHeader("Sec-Fetch-Site")}}Site
    • : Indicates the relationship between a request initiator's origin and its target's origin. It is a Structured Header whose value is a token with possible values cross-site, same-origin, same-site, and none.
  • {{HTTPHeader("Sec-Fetch-Mode")}}Mode
    • : Indicates the request's mode to a server. It is a Structured Header whose value is a token with possible values cors, navigate, no-cors, same-origin, and websocket.
  • {{HTTPHeader("Sec-Fetch-User")}}User
    • : Indicates whether or not a navigation request was triggered by user activation. It is a Structured Header whose value is a boolean so possible values are ?0 for false and ?1 for true.
  • {{HTTPHeader("Sec-Fetch-Dest")}}Dest
    • : Indicates the request's destination. It is a Structured Header whose value is a token with possible values audio, audioworklet, document, embed, empty, font, image, manifest, object, paintworklet, report, script, serviceworker, sharedworker, style, track, video, worker, and xslt.

The following request headers are not strictly "fetch metadata request headers", but similarly provide information about the context of how a resource will be used. A server might use them to modify its caching behavior, or the information that is returned:

  • {{HTTPHeader("Sec-Purpose")}}Purpose
    • : Indicates the purpose of the request, when the purpose is something other than immediate use by the user-agent. The header currently has one possible value, prefetch, which indicates that the resource is being fetched preemptively for a possible future navigation.
  • {{HTTPHeader("Service-Worker-Navigation-Preload")}}Preload
    • : A request header sent in preemptive request to {{domxref("Window/fetch", "fetch()")}} a resource during service worker boot. The value, which is set with {{domxref("NavigationPreloadManager.setHeaderValue()")}}, can be used to inform a server that a different resource should be returned than in a normal fetch() operation.

Fetch storage access headers

These headers enable an enhanced workflow for the Storage Access API.

  • {{HTTPHeader("Sec-Fetch-Storage-Access")}}Access
    • : Indicates the "storage access status" for the current fetch context, which will be one of none, inactive, or active. The server may respond with Activate-Storage-Access to request that the browser activate an inactive permission and retry the request, or to load a resource with access to its third-party cookies if the status is active.
  • {{HTTPHeader("Activate-Storage-Access")}}Access
    • : Used in response to Sec-Fetch-Storage-Access to indicate that the browser can activate an existing permission for secure access and retry the request with cookies, or load a resource with cookie access if it already has an activated permission.

Server-sent events

Transfer coding

  • {{HTTPHeader("Transfer-Encoding")}}Encoding
    • : Specifies the form of encoding used to safely transfer the resource to the user.
  • {{HTTPHeader("TE")}}TE
    • : Specifies the transfer encodings the user agent is willing to accept.
  • {{HTTPHeader("Trailer")}}Trailer
    • : Allows the sender to include additional fields at the end of chunked message.

WebSockets

Headers used by the WebSockets API in the WebSocket handshake:

  • {{HTTPHeader("Sec-WebSocket-Accept")}}Accept
    • : Response header that indicates that the server is willing to upgrade to a WebSocket connection.
  • {{HTTPHeader("Sec-WebSocket-Extensions")}}Extensions
    • : In requests, this header indicates the WebSocket extensions supported by the client in preferred order. In responses, it indicates the extension selected by the server from the client's preferences.
  • {{HTTPHeader("Sec-WebSocket-Key")}}Key
    • : Request header containing a key that verifies that the client explicitly intends to open a WebSocket.
  • {{HTTPHeader("Sec-WebSocket-Protocol")}}Protocol
    • : In requests, this header indicates the sub-protocols supported by the client in preferred order. In responses, it indicates the sub-protocol selected by the server from the client's preferences.
  • {{HTTPHeader("Sec-WebSocket-Version")}}Version
    • : In requests, this header indicates the version of the WebSocket protocol used by the client. In responses, it is sent only if the requested protocol version is not supported by the server, and lists the versions that the server supports.

Other

  • {{HTTPHeader("Alt-Svc")}}Svc
    • : Used to list alternate ways to reach this service.
  • {{HTTPHeader("Alt-Used")}}Used
    • : Used to identify the alternative service in use.
  • {{HTTPHeader("Date")}}Date
    • : Contains the date and time at which the message was originated.
  • {{HTTPHeader("Link")}}Link
    • : This entity-header field provides a means for serializing one or more links in HTTP headers. It is semantically equivalent to the HTML {{HTMLElement("link")}}link element.
  • {{HTTPHeader("Retry-After")}}After
    • : Indicates how long the user agent should wait before making a follow-up request.
  • {{HTTPHeader("Server-Timing")}}Timing
    • : Communicates one or more metrics and descriptions for the given request-response cycle.
  • {{HTTPHeader("Service-Worker")}}Worker
    • : Included in fetches for a service worker's script resource. This header helps administrators log service worker script requests for monitoring purposes.
  • {{HTTPHeader("Service-Worker-Allowed")}}Allowed
  • {{HTTPHeader("SourceMap")}}SourceMap
    • : Links to a {{Glossary("source map")}}map so that debuggers can step through original source code instead of generated or transformed code.
  • {{HTTPHeader("Upgrade")}}Upgrade
    • : This HTTP/1.1 (only) header can be used to upgrade an already established client/server connection to a different protocol (over the same transport protocol). For example, it can be used by a client to upgrade a connection from HTTP 1.1 to HTTP 2.0, or an HTTP or HTTPS connection into a WebSocket.
  • {{HTTPHeader("Priority")}}Priority
    • : Provides a hint from about the priority of a particular resource request on a particular connection. The value can be sent in a request to indicate the client priority, or in a response if the server chooses to reprioritize the request.

Experimental headers

Attribution reporting headers

The Attribution Reporting API enables developers to measure conversions — for example when a user clicks an ad embedded on one site and then proceeds to purchase the item over on the vendor's site — and then access reports on those conversions. It does this without relying on third-party tracking cookies, instead relying on various headers to register sources and triggers that are matched to indicate a conversion.

Client hints

HTTP Client hints are a set of request headers that provide useful information about the client such as device type and network conditions, and allow servers to optimize what is served for those conditions.

Servers proactively requests the client hint headers they are interested in from the client using {{HTTPHeader("Accept-CH")}}CH. The client may then choose to include the requested headers in subsequent requests.

The different categories of client hints are listed below.

User agent client hints

The UA client hints are request headers that provide information about the user agent, the platform/architecture it is running on, and user preferences set on the user agent or platform:

[!NOTE]NOTE: User-agent client hints are not available inside fenced frames because they rely on permissions policy delegation, which could be used to leak data.

Device and responsive image client hints

Deprecated device and responsive image client hints

Network client hints

Network client hints allow a server to choose what information is sent based on the user choice and network bandwidth and latency.

Compression Dictionary Transport

Compression Dictionary Transport is a way of using a shared compression dictionary to reduce the transport size of HTTP responses rather than using the standard static dictionary in {{glossary("Brotli compression")}}compression or {{glossary("Zstandard compression")}}compression.

Privacy

  • {{HTTPHeader("DNT")}} {{deprecated_inline}} {{non-standard_inline}}DNT
  • {{HTTPHeader("Tk")}} {{deprecated_inline}} {{non-standard_inline}}Tk
    • : Response header that indicates the tracking status that applied to the corresponding request. Used in conjunction with DNT.
  • {{HTTPHeader("Sec-GPC")}} {{non-standard_inline}} {{experimental_inline}}GPC
    • : Indicates whether the user consents to a website or service selling or sharing their personal information with third parties.

Security

Server-sent events

  • {{HTTPHeader("NEL")}} {{experimental_inline}}NEL
    • : Defines a mechanism that enables developers to declare a network error reporting policy.

Topics API

The Topics API provides a mechanism for developers to implement use cases such as interest-based advertising (IBA). See the Topics API documentation for more information.

Other

Non-standard headers

Deprecated headers

  • {{HTTPHeader("Pragma")}} {{deprecated_inline}}Pragma
    • : Implementation-specific header that may have various effects anywhere along the request-response chain. Used for backwards compatibility with HTTP/1.0 caches where the Cache-Control header is not yet present.
  • {{HTTPHeader("Warning")}} {{deprecated_inline}}Warning
    • : General warning information about possible problems.

See also