new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Cloudflare Workers · Runtime APIs · all subjects

handlers

183 notes in this subject, read out of this brain and free to use. This is page 3 of 4.

RequestInitCfProperties: webp

The webp property is an optional boolean that enables or disables WebP image format in Polish.

cf.vary object structure

The cf.vary object has two keys: default (required) and headers (optional). The default key is required and configures behavior for any header name in the origin Vary response not included in headers. The headers key is optional and contains a map of lowercase request header names to configuration objects. If cf.vary is present, default is required. An empty cf.vary object is invalid.

cf.vary action values

Each header configuration object in cf.vary and the default object must include an action key set to one of: normalize, passthrough, or bypass.

cf.vary accept header configuration

For the 'accept' header in cf.vary headers, an additional 'media_types' key can be specified. It must contain a maximum of 10 MIME types, each 255 characters or less.

cf.vary accept-language header configuration

For the 'accept-language' header in cf.vary headers, an additional 'languages' key can be specified. It must contain a maximum of 20 language codes, each 64 characters or less.

cf.vary validation rules

In cf.vary: header names in headers must be lowercase; header names can contain lowercase letters, numbers, underscores, and hyphens; header names cannot exceed 128 characters; header names beginning with cf- or cf_ are not allowed; certain hop-by-hop, cache-control, or proxy-control headers are not allowed (examples: connection, content-length, cache-control, host, range, origin, x-forwarded-for); headers can contain up to 50 entries; accept.media_types can contain up to 10 entries; accept-language.languages can contain up to 20 entries; values in media_types and languages must be non-empty printable ASCII strings.

cf.vary example configuration

Example of cf.vary configuration that normalizes Accept and Accept-Language and bypasses cache for any other header in the origin Vary response: {"cf": {"vary": {"default": {"action": "bypass"}, "headers": {"accept": {"action": "normalize", "media_types": ["text/html", "application/json"]}, "accept-language": {"action": "normalize", "languages": ["en", "fr", "de"]}}}}}

Request properties are read-only

All properties of an incoming Request object are read-only. To modify the properties of an incoming request, create a new Request object and pass the options to modify to its constructor.

Request.body property

The body property is a read-only ReadableStream of the body contents.

Request.bodyUsed property

The bodyUsed property is a read-only boolean that declares whether the body has been used in a response yet.

Request.cf property

The cf property is a read-only object containing properties about the incoming request provided by Cloudflare's global network. This property is not available in the Cloudflare Workers dashboard or Playground preview editor. To modify its values, pass new values on the cf key of the init options argument when creating a new Request object.

Request.headers property

The headers property is a read-only Headers object. Workers imposes very few restrictions on headers. For example, a Worker can set the Cookie header, unlike browsers. If a response is a redirect with redirect mode set to follow, all headers will be forwarded to the redirect destination including sensitive headers like Cookie, Authorization, or application-specific headers even if the destination is a different hostname or domain. To prevent this, set redirect mode to manual and implement custom redirect policy.

Request.method property

The method property is a read-only string containing the request's method, for example GET, POST, etc.

Request.redirect property

The redirect property is a read-only string with values 'follow', 'error', or 'manual'. The fetch method will automatically follow redirects if redirect mode is 'follow'. If set to 'manual', the 3xx redirect response will be returned to the caller as-is. The default for a new Request object is 'follow', but the incoming Request property of a FetchEvent will have redirect mode 'manual'.

Request.signal property

The signal property is a read-only AbortSignal corresponding to this request. If the enable_request_signal compatibility flag is used, you can attach an event listener to the signal to perform cleanup tasks or write logs before the Worker's invocation ends.

Request.url property

The url property is a read-only string containing the URL of the request.

IncomingRequestCfProperties: asn

The asn property is a number representing the ASN of the incoming request, for example 395747. Available to all plans.

IncomingRequestCfProperties: asOrganization

The asOrganization property is a string representing the organization which owns the ASN of the incoming request, for example 'Google Cloud'. Available to all plans.

IncomingRequestCfProperties: botManagement

The botManagement property is an object or null, only set when using Cloudflare Bot Management. The object contains properties: score, verifiedBot, signedAgent, staticResource, ja3Hash, ja4, and detectionIds. Refer to Bot Management Variables documentation for more details.

IncomingRequestCfProperties: clientAcceptEncoding

The clientAcceptEncoding property is a string or null. If Cloudflare replaces the value of the Accept-Encoding header, the original value is stored here, for example 'gzip, deflate, br'. Available to all plans.

IncomingRequestCfProperties: clientTcpRtt

The clientTcpRtt property is a number or undefined representing the smoothed round-trip time (RTT) between the client and Cloudflare for TCP connections, in milliseconds. Only present when the client connected over TCP (HTTP/1 and HTTP/2), for example 22.

IncomingRequestCfProperties: colo

The colo property is a string representing the three-letter IATA airport code of the data center that the request hit, for example 'DFW'. Available to all plans.

IncomingRequestCfProperties: country

The country property is a string or null representing the two-letter country code of the incoming request. This is the same value as provided in the CF-IPCountry header, for example 'US'. Available to all plans.

IncomingRequestCfProperties: edgeL4

The edgeL4 property is an object or undefined representing layer 4 transport statistics for the connection between the client and Cloudflare. It contains the property: deliveryRate (number) - the most recent data delivery rate estimate for the connection, in bytes per second, for example 123456.

IncomingRequestCfProperties: isEUCountry

The isEUCountry property is a string or null. If the country of the incoming request is in the EU, it returns '1'. Otherwise, this property is either omitted or false. Available to all plans.

IncomingRequestCfProperties: httpProtocol

The httpProtocol property is a string representing the HTTP Protocol, for example 'HTTP/2'. Available to all plans.

IncomingRequestCfProperties: hostMetadata

The hostMetadata property is an object or undefined, only populated when the incoming request is from a zone with custom hostname metadata. Refer to Cloudflare for Platforms documentation for details on custom hostname metadata.

IncomingRequestCfProperties: requestPriority

The requestPriority property is a string or null representing browser-requested prioritization information in the request object, for example 'weight=192;exclusive=0;group=3;group-weight=127'. Available to all plans.

IncomingRequestCfProperties: tlsCipher

The tlsCipher property is a string representing the cipher for the connection to Cloudflare, for example 'AEAD-AES128-GCM-SHA256'. Available to all plans.

IncomingRequestCfProperties: tlsClientAuth

The tlsClientAuth property is an object or null containing various details about the client certificate for mTLS connections. Refer to Client certificate variables documentation for more details.

IncomingRequestCfProperties: tlsClientExtensionsSha1Le

The tlsClientExtensionsSha1Le property is a string representing the SHA-1 hash (Base64-encoded) of the TLS client extensions sent during the handshake, encoded in little-endian format, for example '7zIpdDU5pvFPPBI2/PCzqbaXnRA='. Available to all plans.

IncomingRequestCfProperties: tlsClientHelloLength

The tlsClientHelloLength property is a string representing the length of the client hello message sent in a TLS handshake, for example '508'. Specifically, the length of the bytestring of the client hello. Available to all plans.

IncomingRequestCfProperties: tlsClientRandom

The tlsClientRandom property is a string representing the value of the 32-byte random value provided by the client in a TLS handshake. Refer to RFC 8446 section 4.1.2 for more details. Available to all plans.

IncomingRequestCfProperties: tlsVersion

The tlsVersion property is a string representing the TLS version of the connection to Cloudflare, for example 'TLSv1.3'. Available to all plans.

IncomingRequestCfProperties: city

The city property is a string or null representing the city of the incoming request, for example 'Austin'. Available to all plans.

IncomingRequestCfProperties: continent

The continent property is a string or null representing the continent of the incoming request, for example 'NA'. Available to all plans.

IncomingRequestCfProperties: latitude

The latitude property is a string or null representing the latitude of the incoming request, for example '30.27130'. Available to all plans.

IncomingRequestCfProperties: longitude

The longitude property is a string or null representing the longitude of the incoming request, for example '-97.74260'. Available to all plans.

IncomingRequestCfProperties: postalCode

The postalCode property is a string or null representing the postal code of the incoming request, for example '78701'. Available to all plans.

IncomingRequestCfProperties: metroCode

The metroCode property is a string or null representing the metro code (DMA) of the incoming request, for example '635'. Available to all plans.

IncomingRequestCfProperties: region

The region property is a string or null representing the ISO 3166-2 name for the first level region associated with the IP address of the incoming request if known, for example 'Texas'. Available to all plans.

IncomingRequestCfProperties: regionCode

The regionCode property is a string or null representing the ISO 3166-2 code for the first-level region associated with the IP address of the incoming request if known, for example 'TX'. Available to all plans.

IncomingRequestCfProperties: timezone

The timezone property is a string representing the timezone of the incoming request, for example 'America/Chicago'. Available to all plans.

Request.clone() method

The clone() instance method creates a copy of the Request object and returns a Request.

Request.arrayBuffer() method

The arrayBuffer() instance method returns a promise that resolves with an ArrayBuffer representation of the request body.

Request.formData() method

The formData() instance method returns a promise that resolves with a FormData representation of the request body.

Request.json() method

The json() instance method returns a promise that resolves with a JSON representation of the request body.

Request.text() method

The text() instance method returns a promise that resolves with a string (text) representation of the request body.

Request context lifecycle

The Request context starts when the fetch() handler is called. Asynchronous tasks such as making a subrequest using the fetch() API can only be run inside the Request context. When passing a Response promise to the fetch event .respondWith() method, the request context is active during any asynchronous tasks which run before the Response promise has settled.

Request context availability with fetch event

If you pass a Response promise to the fetch event .respondWith() method and pass the event to an async handler, the request context is available within that async handler function.

Request context errors at script startup

Any attempt to use APIs such as fetch() or access the Request context during script startup will throw an exception. For example, calling fetch() at the module level will throw during script startup and the fetch event listener will never be registered.

Content-Length header automatic setting

The Content-Length header will be automatically set by the runtime based on the data source for the Request. Any value manually set by user code in the Headers will be ignored. To have a Content-Length header with a specific value, the body must be either a FixedLengthStream or a fixed-length value such as a string or TypedArray.

FixedLengthStream for Content-Length

A FixedLengthStream is an identity TransformStream that permits only a fixed number of bytes to be written to it. Example: const { writable, readable } = new FixedLengthStream(11); const enc = new TextEncoder(); const writer = writable.getWriter(); writer.write(enc.encode('hello world')); writer.end(); const req = new Request('https://example.org', { method: 'POST', body: readable });

Workers Request cf property is non-standard

Workers adds a cf property to the Request object that contains Cloudflare-specific metadata about the incoming request. This property is not part of the web standard and is only available in the Workers runtime.

Workers Headers implementation differs from web standard

The headers property returns a Workers-specific Headers object that includes additional methods like getAll() for Set-Cookie headers. The Workers Headers implementation differs from the web standard.

Request immutability requirement

Incoming Request objects passed to the fetch() handler are immutable. To modify properties of an incoming request, you must create a new Request object.

Modifying incoming request example

To modify an incoming request, create a new Request object: export default { async fetch(request, env, ctx) { const url = 'https://example.com'; const modifiedRequest = new Request(url, request); // ... } };

Request instance from fetch handler

The most common way to encounter a Request object is as a property of an incoming request in the fetch handler: export default { async fetch(request, env, ctx) { return new Response('Hello World!'); } };

TypeScript type compatibility for Request

Workers type definitions define a Request type that includes Workers-specific properties like cf. This type is not directly compatible with the standard Request type from lib.dom.d.ts. If working with code that uses both Workers types and standard web types, you may need to use type assertions or create a new Request object.

Request.cf object unavailable in dashboard and playground

The request.cf object is not available in the Cloudflare Workers dashboard or Playground preview editor.

Give your agent this brain