- Compatibility flags·续5
- Global fetch() strictly public
- Handle cross-request promise resolution correctly
- Upper-case HTTP methods
- Automatically set the Symbol.toStringTag for Workers API objects
- Enable node:zlib module
- Allow specifying a custom port when making a subrequest with the fetch() API
- WritableStream abort clears pending write queue
- Properly extract blob MIME type from content-type headers
- Use standard URL parsing in fetch()
- Returning empty Uint8Array on final BYOB read
Compatibility flags·续5
function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
>
> If the `queue_consumer_no_wait_for_wait_until` flag is enabled, Queues consumers will no longer wait for promises passed to `ctx.waitUntil()` to resolve before acknowledging messages. This can improve the performance of queue consumers which utilize `ctx.waitUntil()`. With the flag enabled, in the above example, the consumer Worker will acknowledge the batch without waiting for the sleep function to resolve.
>
> Using this flag will not affect the behavior of `ctx.waitUntil()`. `ctx.waitUntil()` will continue to extend the lifetime of your consumer Worker to continue to work even after the batch of messages has been acknowledged.
>
> ### Apply TransformStream backpressure fix
>
> | **Default as of** | 2024-12-16 |
> | --- | --- |
> | **Flag to enable** | `fixup-transform-stream-backpressure` |
> | **Flag to disable** | `original-transform-stream-backpressure` |
>
> The original implementation of `TransformStream` included a bug that would cause backpressure signaling to fail after the first write to the transform. Unfortunately, the fix can cause existing code written to address the bug to fail. Therefore, the `fixup-transform-stream-backpressure` compat flag is provided to enable the fix.
>
> The fix is enabled by default with compatibility dates of 2024-12-16 or later.
>
> To restore the original backpressure logic, disable the fix using the `original-transform-stream-backpressure` flag.
>
> ### Disable top-level await in require(...)
>
> | **Default as of** | 2024-12-02 |
> | --- | --- |
> | **Flag to enable** | `disable_top_level_await_in_require` |
> | **Flag to disable** | `enable_top_level_await_in_require` |
>
> Workers implements the ability to use the Node.js style `require(...)` method to import modules in the Worker bundle. Historically, this mechanism allowed required modules to use top-level await. This, however, is not Node.js compatible.
>
> The `disable_top_level_await_in_require` compat flag will cause `require()` to fail if the module uses a top-level await. This flag is default enabled with a compatibility date of 2024-12-02 or later.
>
> To restore the original behavior allowing top-level await, use the `enable_top_level_await_in_require` compatibility flag.
>
> ### Enable `cache: no-store` HTTP standard API
>
> | **Default as of** | 2024-11-11 |
> | --- | --- |
> | **Flag to enable** | `cache_option_enabled` |
> | **Flag to disable** | `cache_option_disabled` |
>
> When you enable the `cache_option_enabled` compatibility flag, you can specify a value for the `cache` property of the Request interface. When this compatibility flag is not enabled, or `cache_option_disabled` is set, the Workers runtime will throw an `Error` saying `The 'cache' field on 'RequestInitializerDict' is not implemented.`
>
> When this flag is enabled you can instruct Cloudflare not to cache the response from a subrequest you make from your Worker using the [`fetch()` API](https://developers.cloudflare.com/workers/runtime-apis/fetch/):
>
> The only cache option enabled with `cache_option_enabled` is `'no-store'`. Specifying any other value will cause the Workers runtime to throw a `TypeError` with the message `Unsupported cache mode: <the-mode-you-specified>`.
>
> When `no-store` is specified:
>
> - All requests have the headers `Pragma: no-cache` and `Cache-Control: no-cache` are set on them.
> - Subrequests to origins not hosted by Cloudflare bypass Cloudflare's cache.
>
> Examples using `cache: 'no-store'`:
>
```js
const response = await fetch("https://example.com", { cache: "no-store" });
The cache value can also be set on a
Requestobject.
const request = new Request("https://example.com", { cache: "no-store" });
const response = await fetch(request);
Global fetch() strictly public
Flag to enable global_fetch_strictly_publicFlag to disable global_fetch_private_originWhen the
global_fetch_strictly_publiccompatibility flag is enabled, the globalfetch()function will strictly route requests as if they were made on the public Internet.This means requests to a Worker's own zone will loop back to the "front door" of Cloudflare and will be treated like a request from the Internet, possibly even looping back to the same Worker again.
When the
global_fetch_strictly_publicis not enabled, such requests are routed to the zone's origin server, ignoring any Workers mapped to the URL and also bypassing Cloudflare security settings.Handle cross-request promise resolution correctly
Default as of 2024-10-14 Flag to enable handle_cross_request_promise_resolutionFlag to disable no_handle_cross_request_promise_resolutionHistorically, it was possible to resolve a promise from an incorrect request context, which could lead to promise continuations being scheduled in the wrong context, causing errors and difficult-to-diagnose bugs.
With
handle_cross_request_promise_resolutionenabled, promise continuations are scheduled to run in the correct request context if it is still alive, or dropped with a warning if the correct context has already ended.Upper-case HTTP methods
Default as of 2024-10-14 Flag to enable upper_case_all_http_methodsFlag to disable no_upper_case_all_http_methodsHTTP methods are expected to be upper-cased. Per the fetch spec, if the method is specified as
get,post,put,delete,head, oroptions, implementations are expected to uppercase the method. All other method names would generally be expected to throw as unrecognized (for example,patchwould be an error whilePATCHis accepted). This is a bit restrictive, even if it is in the spec. This flag modifies the behavior to uppercase all methods prior to parsing so that the method is always recognized if it is a known method.To restore the standard behavior, use the
no_upper_case_all_http_methodscompatibility flag.Automatically set the Symbol.toStringTag for Workers API objects
Default as of 2024-09-26 Flag to enable set_tostring_tagFlag to disable do_not_set_tostring_tagA change was made to set the Symbol.toStringTag on all Workers API objects in order to fix several spec compliance bugs. Unfortunately, this change was more breaking than anticipated. The
do_not_set_tostring_tagcompat flag restores the original behavior with compatibility dates of 2024-09-26 or earlier.Enable
node:zlibmodule
Default as of 2024-09-23 Flag to enable nodejs_zlibFlag to disable no_nodejs_zlibThe
nodejs_zlibflag enables thenode:zlibmodule in Workers.This flag is automatically enabled for Workers using a compatibility date of 2024-09-23 or later when
nodejs_compatis enabled.See the Node.js documentation ↗︎ for more details about the
node:zlibAPI.Allow specifying a custom port when making a subrequest with the fetch() API
Default as of 2024-09-02 Flag to enable allow_custom_portsFlag to disable ignore_custom_portsWhen this flag is enabled, and you specify a port when making a subrequest with the
fetch()API, the port number you specify will be used.When you make a subrequest to a website that uses Cloudflare ("Orange Clouded") — only ports supported by Cloudflare's reverse proxy can be specified. If you attempt to specify an unsupported port, it will be ignored.
When you make a subrequest to a website that does not use Cloudflare ("Grey Clouded") - any port can be specified.
For example:
const response = await fetch("https://example.com:8000");
With allow_custom_ports the above example would fetch
https://example.com:8000rather thanhttps://example.com:443.Note that creating a WebSocket client with a call to
new WebSocket(url)will also obey this flag.WritableStream abort clears pending write queue
Default as of 2024-09-02 Flag to enable internal_writable_stream_abort_clears_queueFlag to disable internal_writable_stream_abort_does_not_clear_queueWhen using the original WritableStream implementation ("internal" streams), the
abort()operation was previously handled lazily, meaning that the queue of pending writes would not be cleared until the next time the queue was processed. This behavior could cause the stream to hang if the consumer stopped consuming.With
internal_writable_stream_abort_clears_queueenabled, the queue is cleared immediately uponabort(), preventing hangs in cases where the consumer has stopped processing writes.Properly extract blob MIME type from
content-typeheaders
Default as of 2024-06-03 Flag to enable blob_standard_mime_typeFlag to disable blob_legacy_mime_typeWhen calling
response.blob.type(), the MIME type will now be properly extracted fromcontent-typeheaders, per the WHATWG spec ↗︎.Use standard URL parsing in
fetch()
Default as of 2024-06-03 Flag to enable fetch_standard_urlFlag to disable fetch_legacy_urlThe
fetch_standard_urlflag makesfetch()use WHATWG URL Standard ↗︎ parsing rules. The original implementation would throwTypeError: Fetch API cannot loaderrors with some URLs where standard parsing does not, for instance with the inclusion of whitespace before the URL. URL errors will now be thrown immediately upon callingnew Request()with an improper URL. Previously, URL errors were thrown only oncefetch()was called.Returning empty Uint8Array on final BYOB read
Default as of 2024-05-13 Flag to enable internal_stream_byob_return_viewFlag to disable internal_stream_byob_return_undefinedIn the original implementation of BYOB ("Bring your own buffer")
ReadableStreams, theread()method would returnundefinedwhen the stream was closed and there was no more data to read. This behavior was inconsistent with the standardReadableStreambehavior, which returns an emptyUint8Arraywhen the stream is closed.When the
internal_stream_byob_return_viewflag is used, the BYOBread()will implement standard behavior.```js const resp = await fetch('https://example.org'); const reader = resp.body.getReader({ mode: 'byob' }); await result = await reader.read(new Uint8Array(10));
if (result.done) { // The result gives us an empty Uint8Array... console.log(result.value.byteLength); // 0
