Skip to content

Instantly share code, notes, and snippets.

@adilfulara
Last active November 26, 2024 01:39
Show Gist options
  • Save adilfulara/c392d978e902abe4f14a63e134e1c4eb to your computer and use it in GitHub Desktop.
Save adilfulara/c392d978e902abe4f14a63e134e1c4eb to your computer and use it in GitHub Desktop.
HTTPBin - Enable Compression Filter
static_resources:
listeners:
- name: listener_0
address:
socket_address:
address: 0.0.0.0
port_value: 10000
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
http_filters:
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
inline_code: |
-- Lua script to check compression header
function envoy_on_request(request_handle)
-- Get the compression header value
local compress_header = request_handle:headers():get("x-compress-request")
if compress_header == "true" then
-- Enable compression by setting accept-encoding
request_handle:headers():add("accept-encoding", "gzip")
end
end
- name: envoy.filters.http.compressor
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor
compressor_library:
name: gzip
typed_config:
"@type": type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip
memory_level: 5
window_bits: 12
compression_level: 6
compression_strategy: DEFAULT_STRATEGY
request_direction_config:
common_config:
enabled:
default_value: false
runtime_key: request_compression_enabled
response_direction_config:
remove_accept_encoding_header: true
common_config:
min_content_length: 50
# content_length: 1024
content_type:
- application/json
- text/plain
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: service_backend
timeout: 30s
clusters:
- name: service_backend
connect_timeout: 5s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: service_backend
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: httpbin.org
port_value: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment