INTEGRITY Dokumentace

Povolení komprese Zstandard pro výchozí typy obsahu

Následující ukázkové pravidlo zapne kompresi Zstandard pro typy obsahu odpovědi, kde Cloudflare ve výchozím nastavení používá kompresi. Pokud klient nepodporuje kompresi Zstandard, jako záložní řešení použije kompresi Brotli nebo Gzip.

Když příchozí požadavky odpovídají

  • Vlastní filtrovací výraz:
    • Typ média is 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

Poté

  • Možnosti komprese: Custom
  • Definujte vlastní pořadí typů komprese: Zstandard, Brotli, Gzip

Následující příklad nastavuje pravidla existujícího vstupní sada pravidel (s ID {ruleset_id}) pro http_response_compression fázi na jedno pravidlo komprese pomocí Aktualizace sady pravidel zóny operace:

Požadovaná oprávnění API tokenu

Alespoň jeden z následujících oprávnění tokenu je povinné:
  • Response Compression Write
  • Config Settings Write
  • Dynamic URL Redirects Write
  • Cache Settings Write
  • Custom Errors Write
  • Origin Write
  • Managed headers Write
  • Zone Transform Rules Write
  • Mass URL Redirects Write
  • Magic Firewall Write
  • L4 DDoS Managed Ruleset Write
  • HTTP DDoS Managed Ruleset Write
  • Sanitize Write
  • Transform Rules Write
  • Select Configuration Write
  • Bot Management Write
  • Zone WAF Write
  • Account WAF Write
  • Account Rulesets Write
  • Logs Write
  • Logs Write
Aktualizace sady pravidel zóny
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"
										}
								]
						}
				}
		]
	}'

Použijte ref pole, abyste při použití Terraformu měli stabilní ID pravidel napříč aktualizacemi. Přidání tohoto pole zabrání tomu, aby Terraform při změnách pravidlo vytvářel znovu. Další informace najdete v Řešení potíží v dokumentaci Terraform.