Skip to content

Commit

Permalink
[Speed] Update Accept-Encoding header values (Cloudflare -> Origin se…
Browse files Browse the repository at this point in the history
…rver) (#17581)


---------

Co-authored-by: Pedro Sousa <680496+pedrosousa@users.noreply.github.com>
  • Loading branch information
seaneustace and pedrosousa authored Oct 17, 2024
1 parent 04f1fd2 commit d1fac25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
25 changes: 8 additions & 17 deletions src/content/docs/fundamentals/reference/http-request-headers.mdx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
---
pcx_content_type: reference
title: Cloudflare HTTP request headers

---

import { Render } from "~/components"
import { Render } from "~/components";

Cloudflare passes all HTTP request headers to your origin web server and adds additional headers as specified below.

:::note

Cloudflare may remove HTTP request headers with names considered invalid [according to NGINX](https://nginx.org/en/docs/http/ngx_http_core_module.html#ignore_invalid_headers) — for example, header names containing a `.` (dot) character.
Cloudflare may remove HTTP request headers with names considered invalid [according to NGINX](https://nginx.org/en/docs/http/ngx_http_core_module.html#ignore_invalid_headers) — for example, header names containing a `.` (dot) character.
:::

## Accept-Encoding
Expand Down Expand Up @@ -40,7 +39,7 @@ When no Worker subrequest is triggered, `cf-connecting-ip` reflects the client's

Cloudflare provides [free IPv6 support](/network/ipv6-compatibility/) to all domains without requiring additional configuration or hardware. To support migrating to IPv6, Cloudflare's [Pseudo IPv4](/network/pseudo-ipv4/) provides an IPv6 to IPv4 translation service for all Cloudflare domains.

<Render file="pseudo-ipv4-warning" /> <br/>
<Render file="pseudo-ipv4-warning" /> <br />

## CF-EW-Via

Expand All @@ -62,10 +61,8 @@ Alternatively, if you do not wish to receive the `True-Client-IP` header or any

:::caution


If you are using Cloudflare in a stacked CDN and authenticating HTTP requests based on the IP address value in the `True-Client-IP` header, you must add a `True-Client-IP` header to your requests. If you do not add this header, its value can be spoofed to any value.


:::

## X-Forwarded-For
Expand All @@ -80,10 +77,8 @@ If you do not wish to receive the visitor's IP address in the `X-Forwarded-For`

:::note


To restore the original visitor IP address at your origin web server, Cloudflare recommends that your logs or applications look at `CF-Connecting-IP` or `True-Client-IP` instead of `X-Forwarded-For`. `CF-Connecting-IP` and `True-Client-IP` both have a consistent format containing only one IP address.


:::

## X-Forwarded-Proto
Expand All @@ -104,19 +99,17 @@ Enterprise customers can also see all requests via [Cloudflare Logs](/logs/).

The `CF-IPCountry` header contains a two-character country code of the originating visitor’s country.

Besides the [ISO-3166-1 alpha-2 codes](https://www.iso.org/iso-3166-country-codes.html), Cloudflare uses the following special country codes:
Besides the [ISO-3166-1 alpha-2 codes](https://www.iso.org/iso-3166-country-codes.html), Cloudflare uses the following special country codes:

* `XX` - Used for clients without country code data.
* `T1` - Used for clients using the Tor network.
- `XX` - Used for clients without country code data.
- `T1` - Used for clients using the Tor network.

To add this header to requests, along with other HTTP headers with location information for the visitor's IP address, [enable the **Add visitor location headers** Managed Transform](/rules/transform/managed-transforms/configure/).

:::note


The `CF-IPCountry` header is removed from requests made from a Worker to an origin that is not proxied behind Cloudflare.


:::

## CF-Visitor
Expand All @@ -141,10 +134,8 @@ The intended purpose of this header is to provide a means for recipients (for ex

:::note


When configuring WAF custom rules, do not match on this header. These rules are applied before Cloudflare adds the `CF-Worker` header. Instead, use the [`cf.worker.upstream_zone`](/ruleset-engine/rules-language/fields/dynamic-fields/#cfworkerupstream_zone) dynamic field, which contains the same value and exists for the same purpose.


:::

## Connection
Expand All @@ -155,5 +146,5 @@ For incoming requests, the value of this header will always be set to `Keep-Aliv

When using Spectrum with a TCP application, these headers are not visible at the origin as they are HTTP headers. If you wish to utilize these in your application, there are two options:

* Use an HTTP or HTTPS Spectrum app instead of TCP
* Use the [Proxy Protocol feature](/spectrum/how-to/enable-proxy-protocol/)
- Use an HTTP or HTTPS Spectrum app instead of TCP
- Use the [Proxy Protocol feature](/spectrum/how-to/enable-proxy-protocol/)
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ Smaller responses will not be compressed, regardless of their content type.

## Content compression from origin servers to the Cloudflare network

When requesting content from your origin server, Cloudflare supports Gzip compression, Brotli compression, or no compression.
When requesting content from your origin server, Cloudflare supports Brotli compression, Gzip compression, or no compression.

```mermaid
flowchart LR
accTitle: Compressed responses sent from the origin server
accDescr: Cloudflare accepts responses from origin server using Gzip compression, Brotli compression, or no compression.
accDescr: Cloudflare accepts responses from origin server using Brotli compression, Gzip compression, or no compression.
A[Visitor browser]
B((Cloudflare))
C[(Origin server)]
A -.-> B == "Request<br>Accept-Encoding: gzip, br" ==> C
C == "Response<br>(Gzip / Brotli / No compression)" ==> B -.-> A
A -.-> B == "Request<br>Accept-Encoding: br, gzip" ==> C
C == "Response<br>(Brotli / Gzip / No compression)" ==> B -.-> A
style A stroke-dasharray: 5 5
style B stroke: orange,fill: orange,color: black
Expand All @@ -137,18 +137,18 @@ linkStyle 1,2 stroke-width: 2px
linkStyle 0,3 stroke-width: 1px
```

If your origin server responds to a Cloudflare request using Gzip/Brotli compression, we will keep the same compression in the response sent to the website visitor if:
If your origin server responds to a Cloudflare request using Brotli/Gzip compression, we will keep the same compression in the response sent to the website visitor if:

- You include a `content-encoding` header in your server response mentioning the compression being used (`gzip` or `br`).
- You include a `content-encoding` header in your server response mentioning the compression being used (`br` or `gzip`).
- The visitor browser (or client) supports the compression algorithm.
- You do not enable Cloudflare features that change the response content (refer to [Notes about end-to-end compression](#notes-about-end-to-end-compression) for details).

Cloudflare's reverse proxy can also convert between compressed formats and uncompressed formats. Cloudflare can receive content from your origin server with Gzip or Brotli compression and serve it to visitors uncompressed (or vice versa), independently of caching.
Cloudflare's reverse proxy can also convert between compressed formats and uncompressed formats. Cloudflare can receive content from your origin server with Brotli or Gzip compression and serve it to visitors uncompressed (or vice versa), independently of caching.

If you do not want a particular response from your origin to be encoded with Gzip/Brotli when delivered to website visitors, you can disable this by including a `cache-control: no-transform` HTTP header in the response from your origin web server.
If you do not want a particular response from your origin to be encoded with Brotli/Gzip when delivered to website visitors, you can disable this by including a `cache-control: no-transform` HTTP header in the response from your origin web server.

:::caution
Cloudflare will take into consideration the `accept-encoding` header value in website visitors' requests when sending responses to those visitors. However, when requesting content from your origin server, Cloudflare will send a different `Accept-Encoding` header, supporting Gzip and Brotli compression.
Cloudflare will take into consideration the `accept-encoding` header value in website visitors' requests when sending responses to those visitors. However, when requesting content from your origin server, Cloudflare will send a different `Accept-Encoding` header, supporting Brotli and Gzip compression.
:::

---
Expand Down

0 comments on commit d1fac25

Please sign in to comment.