When incoming requests match
-
Custom filter expression:
- URI Path equals
/download/assets.tar
- URI Path equals
Then
- Compression options: Custom
- Define a custom order for compression types:
Brotli
Create a compression rule to set Brotli as the only supported compression algorithm for a specific URI path.
The following example rule will configure only Brotli compression for a specific URI path.
When incoming requests match
Custom filter expression:
/download/assets.tarThen
BrotliSince the rule configuration does not include Auto at the end of the custom algorithms list, the response will be uncompressed if the web visitor does not support Brotli.
The following example sets the rules of an existing entry point ruleset (with ID {ruleset_id}) for the http_response_compression phase to a single compression rule, using the Update a zone ruleset operation:
Required API token permissions
Response Compression WriteConfig Settings WriteDynamic URL Redirects WriteCache Settings WriteCustom Errors WriteOrigin WriteManaged headers WriteZone Transform Rules WriteMass URL Redirects WriteMagic Firewall WriteL4 DDoS Managed Ruleset WriteHTTP DDoS Managed Ruleset WriteSanitize WriteTransform Rules WriteSelect Configuration WriteBot Management WriteZone WAF WriteAccount WAF WriteAccount Rulesets WriteLogs WriteLogs Writecurl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/$RULESET_ID" \ --request PUT \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --json '{ "rules": [ { "ref": "use_only_brotli_for_assets_tar", "expression": "http.request.uri.path eq \"/download/assets.tar\"", "action": "compress_response", "action_parameters": { "algorithms": [ { "name": "brotli" } ] } } ] }'Use the ref field to get stable rule IDs across updates when using Terraform. Adding this field prevents Terraform from recreating the rule on changes. For more information, refer to Troubleshooting in the Terraform documentation.