Skip to content

Commit 1fd12b5

Browse files
authored
[Speed] Notes about the Content-Length header in responses (cloudflare#18539)
1 parent c3a8251 commit 1fd12b5

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/content/docs/rules/reference/troubleshooting.mdx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ head:
77
- tag: title
88
content: Rules troubleshooting
99
description: Review common troubleshooting scenarios for Rules features.
10-
1110
---
1211

13-
import { Example, Render } from "~/components"
12+
import { Example, Render } from "~/components";
1413

1514
## Interaction between Cloudflare challenges and Rules features
1615

@@ -28,6 +27,10 @@ For example, define a compound expression for your rule using the `and` operator
2827

2928
If you are using [HTTP DCV](/ssl/edge-certificates/changing-dcv-method/methods/http/) and also have [Single Redirects](/rules/url-forwarding/single-redirects/) set up in your zone, consider excluding the `/.well-known/*` path from your rule to avoid DCV issues. For details and other resources refer to the [SSL/TLS documentation](/ssl/edge-certificates/changing-dcv-method/).
3029

30+
## Content-Length header removed from response
31+
32+
Cloudflare may remove the `Content-Length` header from responses delivered to website visitors. If the visitor must receive the `Content-Length` header, configure the origin server to include a `cache-control: no-transform` HTTP header in the response.
33+
3134
## URL rewrites affect other Rules features executed later
3235

3336
If you rewrite a URI path using a [URL rewrite](/rules/transform/url-rewrite/), this may affect other Rules features executed later — such as [Origin Rules](/rules/origin-rules/) — if they include the URI path in their filter expression.
@@ -36,17 +39,17 @@ Consider the following origin rule configuration:
3639

3740
<Example>
3841

39-
* Rule expression: `http.host == "example.com" and starts_with(http.request.uri.path, "/downloads/")`
40-
* **Host header** > **Rewrite to**: `assets.example.com`
42+
- Rule expression: `http.host == "example.com" and starts_with(http.request.uri.path, "/downloads/")`
43+
- **Host header** > **Rewrite to**: `assets.example.com`
4144

4245
</Example>
4346

4447
If you configure a new URL rewrite with the following configuration:
4548

4649
<Example>
4750

48-
* Rule expression: `http.host == "example.com" and starts_with(http.request.uri.path, "/downloads/")`
49-
* **Path** > **Rewrite to** > **Dynamic**: `regex_replace(http.request.uri.path, "^/downloads/", "/")`
51+
- Rule expression: `http.host == "example.com" and starts_with(http.request.uri.path, "/downloads/")`
52+
- **Path** > **Rewrite to** > **Dynamic**: `regex_replace(http.request.uri.path, "^/downloads/", "/")`
5053

5154
</Example>
5255

@@ -62,17 +65,17 @@ In the current example, you could use the `raw.http.request.uri.path` field in b
6265

6366
<Example>
6467

65-
* Rule expression: `http.host == "example.com" and starts_with(raw.http.request.uri.path, "/downloads/")`
66-
* **Path** > **Rewrite to** > **Dynamic**: `regex_replace(raw.http.request.uri.path, "^/downloads/", "/")`
68+
- Rule expression: `http.host == "example.com" and starts_with(raw.http.request.uri.path, "/downloads/")`
69+
- **Path** > **Rewrite to** > **Dynamic**: `regex_replace(raw.http.request.uri.path, "^/downloads/", "/")`
6770

6871
</Example>
6972

7073
**Origin rule**
7174

7275
<Example>
7376

74-
* Rule expression: `http.host == "example.com" and starts_with(raw.http.request.uri.path, "/downloads/")`
75-
* **Host header** > **Rewrite to**: `assets.example.com`
77+
- Rule expression: `http.host == "example.com" and starts_with(raw.http.request.uri.path, "/downloads/")`
78+
- **Host header** > **Rewrite to**: `assets.example.com`
7679

7780
</Example>
7881

src/content/docs/speed/optimization/content/compression.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ Smaller responses will not be compressed, regardless of their content type.
112112

113113
:::
114114

115+
### Content-Length header handling
116+
117+
When Cloudflare compresses a response sent to the website visitor, it may omit the `Content-Length` HTTP header to avoid delivering incorrect length information caused by dynamic transformations. To preserve the `Content-Length` header set by the origin server, add `cache-control: no-transform` to the origin server's response. This directive prevents Cloudflare from altering compression on responses, allowing the `Content-Length` header to pass through as-is. The `cache-control: no-transform` header must be set by the origin — it cannot be added in client requests.
118+
115119
---
116120

117121
## Content compression from origin servers to the Cloudflare network
@@ -155,7 +159,7 @@ Cloudflare will take into consideration the `accept-encoding` header value in we
155159

156160
<Render file="brotli-compression-warning" />
157161

158-
## Compression methods by plan
162+
## Compression methods by plan
159163

160164
### Between visitors and Cloudflare
161165

@@ -167,4 +171,4 @@ By default, Cloudflare uses the following compression methods for content delive
167171

168172
### Between Cloudflare and the origin server
169173

170-
On all plans, Cloudflare requests content from the origin server using the `accept-encoding: br, gzip` header. This means that Cloudflare asks the origin to send the content compressed using Brotli or Gzip, depending on which method the origin server supports.
174+
On all plans, Cloudflare requests content from the origin server using the `accept-encoding: br, gzip` header. This means that Cloudflare asks the origin to send the content compressed using Brotli or Gzip, depending on which method the origin server supports.

src/content/partials/speed/brotli-compression-warning.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## Notes about end-to-end compression
66

7+
### Content recompression due to dynamic transformations
8+
79
Even when using the same compression algorithm end to end (between your origin server and Cloudflare, and between the Cloudflare global network and your website visitor), Cloudflare will need to decompress the response and compress it again if you enable any of the following settings for the request:
810

911
- [Automatic HTTPS Rewrites](/ssl/edge-certificates/additional-options/automatic-https-rewrites/)
@@ -20,3 +22,7 @@ To disable these settings for specific URI paths, create a [configuration rule](
2022
:::note
2123
Additionally, the [Replace insecure JS libraries](/waf/tools/replace-insecure-js-libraries/) setting also requires Cloudflare to decompress the response and compress it again. At this time, you cannot turn it off using Configuration Rules.
2224
:::
25+
26+
### Content-Length header
27+
28+
Cloudflare may remove the `Content-Length` HTTP header of responses delivered to website visitors. To ensure that the header is preserved, add a `cache-control: no-transform` HTTP header to the response at the origin server.

0 commit comments

Comments
 (0)