Skip to content

Commit 539aca3

Browse files
vicbdaisyfaithauma
authored andcommitted
Add references to the global_fetch_strictly_public compatibility flag (#22205)
1 parent b3a9120 commit 539aca3

File tree

3 files changed

+67
-75
lines changed

3 files changed

+67
-75
lines changed

src/content/docs/support/troubleshooting/http-status-codes/cloudflare-5xx-errors/error-522.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Two different timeouts cause HTTP error `522` depending on when they occur betwe
2727

2828
- If you are using [Cloudflare Pages](/pages/), verify that you have a custom domain set up and that your CNAME record is pointed to your [custom Pages domain](/pages/configuration/custom-domains/#add-a-custom-domain).
2929

30-
- If you are using [Workers with a Custom Domain](/workers/configuration/routing/custom-domains/), performing a `fetch` to its own hostname will cause a `522` error. Consider using a [Route](/workers/configuration/routing/) or target another hostname instead.
30+
- If you are using [Workers with a Custom Domain](/workers/configuration/routing/custom-domains/), performing a `fetch` to its own hostname will cause a `522` error. Consider using a [Route](/workers/configuration/routing/), targeting another hostname, or enabling the [`global_fetch_strictly_public` compatibility flag](/workers/configuration/compatibility-flags/#global-fetch-strictly-public) instead.
3131

3232
- If none of the above leads to a resolution, request the following information from your hosting provider or site administrator before [contacting Cloudflare support](/support/contacting-cloudflare-support/):
3333

3434
- An [MTR or traceroute](/support/troubleshooting/general-troubleshooting/gathering-information-for-troubleshooting-sites/#perform-a-traceroute) from your origin web server to a [Cloudflare IP address](http://www.cloudflare.com/ips) that most commonly connected to your origin web server before the issue occurred. Identify a connecting Cloudflare IP recorded in the origin web server logs.
35-
- Details from the hosting provider's investigation, such as pertinent logs or conversations with the hosting provider.
35+
- Details from the hosting provider's investigation, such as pertinent logs or conversations with the hosting provider.

src/content/docs/workers/observability/errors.mdx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ Review Workers errors and exceptions.
1313

1414
When a Worker running in production has an error that prevents it from returning a response, the client will receive an error page with an error code, defined as follows:
1515

16-
| Error code | Meaning |
17-
| ---------- | ----------------------------------------------------------------------------------------------------------------- |
18-
| `1101` | Worker threw a JavaScript exception. |
19-
| `1102` | Worker exceeded [CPU time limit](/workers/platform/limits/#cpu-time). |
20-
| `1103` | The owner of this worker needs to contact [Cloudflare Support](/support/contacting-cloudflare-support/) |
21-
| `1015` | Worker hit the [burst rate limit](/workers/platform/limits/#burst-rate). |
22-
| `1019` | Worker hit [loop limit](#loop-limit). |
23-
| `1021` | Worker has requested a host it cannot access. |
24-
| `1022` | Cloudflare has failed to route the request to the Worker. |
25-
| `1024` | Worker cannot make a subrequest to a Cloudflare-owned IP address. |
26-
| `1027` | Worker exceeded free tier [daily request limit](/workers/platform/limits/#daily-request). |
27-
| `1042` | Worker tried to fetch from another Worker on the same zone, which is [unsupported](/workers/runtime-apis/fetch/). |
16+
| Error code | Meaning |
17+
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
18+
| `1101` | Worker threw a JavaScript exception. |
19+
| `1102` | Worker exceeded [CPU time limit](/workers/platform/limits/#cpu-time). |
20+
| `1103` | The owner of this worker needs to contact [Cloudflare Support](/support/contacting-cloudflare-support/) |
21+
| `1015` | Worker hit the [burst rate limit](/workers/platform/limits/#burst-rate). |
22+
| `1019` | Worker hit [loop limit](#loop-limit). |
23+
| `1021` | Worker has requested a host it cannot access. |
24+
| `1022` | Cloudflare has failed to route the request to the Worker. |
25+
| `1024` | Worker cannot make a subrequest to a Cloudflare-owned IP address. |
26+
| `1027` | Worker exceeded free tier [daily request limit](/workers/platform/limits/#daily-request). |
27+
| `1042` | Worker tried to fetch from another Worker on the same zone, which is only [supported](/workers/runtime-apis/fetch/) when the [`global_fetch_strictly_public` compatibility flag](/workers/configuration/compatibility-flags/#global-fetch-strictly-public) is used. |
2828

2929
Other `11xx` errors generally indicate a problem with the Workers runtime itself. Refer to the [status page](https://www.cloudflarestatus.com) if you are experiencing an error.
3030

@@ -255,10 +255,10 @@ The **Errors by invocation status** chart shows the number of errors broken down
255255

256256
The **Client disconnected by type** chart shows the number of client disconnect errors broken down into the following categories:
257257

258-
| Client Disconnects | Meaning |
259-
| ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
258+
| Client Disconnects | Meaning |
259+
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
260260
| `Response Stream Disconnected` | Connection was terminated during the deferred proxying stage of a Worker request flow. It commonly appears for longer lived connections such as [WebSockets](/workers/runtime-apis/websockets/). |
261-
| `Cancelled` | The Client disconnected before the Worker completed its response. |
261+
| `Cancelled` | The Client disconnected before the Worker completed its response. |
262262

263263
## Debug exceptions with Workers Logs
264264

src/content/docs/workers/runtime-apis/fetch.mdx

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@ title: Fetch
44
head: []
55
description: An interface for asynchronously fetching resources via HTTP
66
requests inside of a Worker.
7-
87
---
98

10-
import { TabItem, Tabs } from "~/components"
9+
import { TabItem, Tabs } from "~/components";
1110

1211
The [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) provides an interface for asynchronously fetching resources via HTTP requests inside of a Worker.
1312

1413
:::note
1514

16-
1715
Asynchronous tasks such as `fetch` must be executed within a [handler](/workers/runtime-apis/handlers/). If you try to call `fetch()` within [global scope](https://developer.mozilla.org/en-US/docs/Glossary/Global_scope), your Worker will throw an error. Learn more about [the Request context](/workers/runtime-apis/request/#the-request-context).
1816

19-
2017
:::
2118

2219
:::caution[Worker to Worker]
2320

24-
25-
Worker-to-Worker `fetch` requests are possible with [Service bindings](/workers/runtime-apis/bindings/service-bindings/).
26-
21+
Worker-to-Worker `fetch` requests are possible with [Service bindings](/workers/runtime-apis/bindings/service-bindings/) or by enabling the [`global_fetch_strictly_public` compatibility flag](/workers/configuration/compatibility-flags/#global-fetch-strictly-public).
2722

2823
:::
2924

@@ -33,28 +28,28 @@ Worker-to-Worker `fetch` requests are possible with [Service bindings](/workers/
3328

3429
```js null {3-7}
3530
export default {
36-
async scheduled(controller, env, ctx) {
37-
return await fetch("https://example.com", {
38-
headers: {
39-
"X-Source": "Cloudflare-Workers",
40-
},
41-
});
42-
},
31+
async scheduled(controller, env, ctx) {
32+
return await fetch("https://example.com", {
33+
headers: {
34+
"X-Source": "Cloudflare-Workers",
35+
},
36+
});
37+
},
4338
};
4439
```
4540

4641
</TabItem> <TabItem label="Service Worker" icon="seti:javascript">
4742

4843
```js null {8}
49-
addEventListener('fetch', event => {
50-
// NOTE: can’t use fetch here, as we’re not in an async scope yet
51-
event.respondWith(eventHandler(event));
44+
addEventListener("fetch", (event) => {
45+
// NOTE: can’t use fetch here, as we’re not in an async scope yet
46+
event.respondWith(eventHandler(event));
5247
});
5348

5449
async function eventHandler(event) {
55-
// fetch can be awaited here since `event.respondWith()` waits for the Promise it receives to settle
56-
const resp = await fetch(event.request);
57-
return resp;
50+
// fetch can be awaited here since `event.respondWith()` waits for the Promise it receives to settle
51+
const resp = await fetch(event.request);
52+
return resp;
5853
}
5954
```
6055

@@ -70,29 +65,23 @@ async def on_scheduled(controller, env, ctx):
7065

7166
</TabItem></Tabs>
7267

68+
- <code>fetch(resource, options optional)</code> : Promise`<Response>`
7369

74-
75-
* <code>fetch(resource, options optional)</code> : Promise`<Response>`
76-
77-
* Fetch returns a promise to a Response.
78-
79-
70+
- Fetch returns a promise to a Response.
8071

8172
### Parameters
8273

74+
- [`resource`](https://developer.mozilla.org/en-US/docs/Web/API/fetch#resource) Request | string | URL
8375

76+
- `options` options
77+
- `cache` `undefined | 'no-store'` optional
78+
- Standard HTTP `cache` header. Only `cache: 'no-store'` is supported.
79+
Any other `cache` header will result in a `TypeError` with the message `Unsupported cache mode: <attempted-cache-mode>`.
80+
_ For all requests this forwards the `Pragma: no-cache` and `Cache-Control: no-cache` headers to the origin.
81+
_ For requests to origins not hosted by Cloudflare, `no-store` bypasses the use of Cloudflare's caches.
82+
- An object that defines the content and behavior of the request.
8483

85-
* [`resource`](https://developer.mozilla.org/en-US/docs/Web/API/fetch#resource) Request | string | URL
86-
87-
* `options` options
88-
* `cache` `undefined | 'no-store'` optional
89-
* Standard HTTP `cache` header. Only `cache: 'no-store'` is supported.
90-
Any other `cache` header will result in a `TypeError` with the message `Unsupported cache mode: <attempted-cache-mode>`.
91-
* For all requests this forwards the `Pragma: no-cache` and `Cache-Control: no-cache` headers to the origin.
92-
* For requests to origins not hosted by Cloudflare, `no-store` bypasses the use of Cloudflare's caches.
93-
* An object that defines the content and behavior of the request.
94-
95-
***
84+
---
9685

9786
## How the `Accept-Encoding` header is handled
9887

@@ -110,28 +99,31 @@ In addition to a change in the content encoding, recompression is also needed wh
11099

111100
```typescript
112101
export default {
113-
async fetch(request) {
114-
// Accept brotli or gzip compression
115-
const headers = new Headers({
116-
'Accept-Encoding': "br, gzip"
117-
});
118-
let response = await fetch("https://developers.cloudflare.com", {method: "GET", headers});
119-
120-
// As long as the original response body is returned and the Content-Encoding header is
121-
// preserved, the same encoded data will be returned without needing to be compressed again.
122-
return new Response(response.body, {
123-
status: response.status,
124-
statusText: response.statusText,
125-
headers: response.headers,
126-
});
127-
}
128-
}
102+
async fetch(request) {
103+
// Accept brotli or gzip compression
104+
const headers = new Headers({
105+
"Accept-Encoding": "br, gzip",
106+
});
107+
let response = await fetch("https://developers.cloudflare.com", {
108+
method: "GET",
109+
headers,
110+
});
111+
112+
// As long as the original response body is returned and the Content-Encoding header is
113+
// preserved, the same encoded data will be returned without needing to be compressed again.
114+
return new Response(response.body, {
115+
status: response.status,
116+
statusText: response.statusText,
117+
headers: response.headers,
118+
});
119+
},
120+
};
129121
```
130122

131123
## Related resources
132124

133-
* [Example: use `fetch` to respond with another site](/workers/examples/respond-with-another-site/)
134-
* [Example: Fetch HTML](/workers/examples/fetch-html/)
135-
* [Example: Fetch JSON](/workers/examples/fetch-json/)
136-
* [Example: cache using Fetch](/workers/examples/cache-using-fetch/)
137-
* Write your Worker code in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.
125+
- [Example: use `fetch` to respond with another site](/workers/examples/respond-with-another-site/)
126+
- [Example: Fetch HTML](/workers/examples/fetch-html/)
127+
- [Example: Fetch JSON](/workers/examples/fetch-json/)
128+
- [Example: cache using Fetch](/workers/examples/cache-using-fetch/)
129+
- Write your Worker code in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.

0 commit comments

Comments
 (0)