← Правила Cloudflare / rules / compression-rules / examples
Включить сжатие Zstandard для стандартных типов содержимого
Следующее правило включит сжатие Zstandard для типов содержимого ответа, где Cloudflare по умолчанию применяет сжатие. Если клиент не поддерживает сжатие Zstandard, в качестве резервного варианта используется сжатие Brotli или Gzip.
Когда входящие запросы соответствуют
- Пользовательское выражение фильтра:
- Media Type входит в
text/html, text/richtext, text/plain, text/css, text/x-script, text/x-component, text/x-java-source, text/x-markdown, application/javascript, application/x-javascript, text/javascript, text/js, image/x-icon, image/vnd.microsoft.icon, application/x-perl, application/x-httpd-cgi, text/xml, application/xml, application/rss+xml, application/vnd.api+json, application/x-protobuf, application/json, multipart/bag, multipart/mixed, application/xhtml+xml, font/ttf, font/otf, font/x-woff, image/svg+xml, application/vnd.ms-fontobject, application/ttf, application/x-ttf, application/otf, application/x-otf, application/truetype, application/opentype, application/x-opentype, application/font-woff, application/eot, application/font, application/font-sfnt, application/wasm, application/javascript-binast, application/manifest+json, application/ld+json, application/graphql+json, application/geo+json
Затем
- Параметры сжатия: Custom
- Задайте пользовательский порядок для типов сжатия:
Zstandard, Brotli, Gzip
Следующий пример задаёт правила существующего ruleset точки входа (с ID {ruleset_id}) для http_response_compression фазу одним правилом сжатия, используя Обновление набора правил зоны операцию:
Необходимые разрешения API-токена
Хотя бы одно из следующих права доступа токена требуется: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 Write
Обновление набора правил зоны
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/$RULESET_ID" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"rules": [
{
"ref": "use_zstd_compression",
"expression": "(http.response.content_type.media_type in {\"text/html\" \"text/richtext\" \"text/plain\" \"text/css\" \"text/x-script\" \"text/x-component\" \"text/x-java-source\" \"text/x-markdown\" \"application/javascript\" \"application/x-javascript\" \"text/javascript\" \"text/js\" \"image/x-icon\" \"image/vnd.microsoft.icon\" \"application/x-perl\" \"application/x-httpd-cgi\" \"text/xml\" \"application/xml\" \"application/rss+xml\" \"application/vnd.api+json\" \"application/x-protobuf\" \"application/json\" \"multipart/bag\" \"multipart/mixed\" \"application/xhtml+xml\" \"font/ttf\" \"font/otf\" \"font/x-woff\" \"image/svg+xml\" \"application/vnd.ms-fontobject\" \"application/ttf\" \"application/x-ttf\" \"application/otf\" \"application/x-otf\" \"application/truetype\" \"application/opentype\" \"application/x-opentype\" \"application/font-woff\" \"application/eot\" \"application/font\" \"application/font-sfnt\" \"application/wasm\" \"application/javascript-binast\" \"application/manifest+json\" \"application/ld+json\" \"application/graphql+json\" \"application/geo+json\"})",
"action": "compress_response",
"action_parameters": {
"algorithms": [
{
"name": "zstd"
},
{
"name": "brotli"
},
{
"name": "gzip"
}
]
}
}
]
}'
Используйте ref поле, чтобы идентификаторы правил оставались стабильными при обновлениях в Terraform. Добавление этого поля не позволяет Terraform пересоздавать правило при изменениях. Дополнительную информацию см. в Устранение неполадок в документации Terraform.