Headers
All HTTP request and response headers are available through the Headers API ↗.
When a header name possesses multiple values, those values will be concatenated as a single, comma-delimited string value. This means that Headers.get
will always return a string or a null
value. This applies to all header names except for Set-Cookie
, which requires Headers.getAll
. This is documented below in Differences.
-
Despite the fact that the
Headers.getAll
method has been made obsolete, Cloudflare still offers this method but only for use with theSet-Cookie
header. This is because cookies will often contain date strings, which include commas. This can make parsing multiple values in aSet-Cookie
header more difficult. Any attempts to useHeaders.getAll
with other header names will throw an error. A brief historyHeaders.getAll
is available in this GitHub issue ↗. -
Due to RFC 6265 ↗ prohibiting folding multiple
Set-Cookie
headers into a single header, theHeaders.append
method will allow you to set multipleSet-Cookie
response headers instead of appending the value onto the existing header.
- In Cloudflare Workers, the
Headers.get
method returns aUSVString
↗ instead of aByteString
↗, which is specified by the spec. For most scenarios, this should have no noticeable effect. To compare the differences between these two string classes, refer to this Playground example ↗.
Cloudflare sets a number of its own custom headers on incoming requests and outgoing responses. While some may be used for its own tracking and bookkeeping, many of these can be useful to your own applications – or Workers – too.
For a list of documented Cloudflare request headers, refer to HTTP request headers.
- Logging headers to console - Review how to log headers in the console.
- HTTP request headers - A list of specific headers Cloudflare adds.