For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Compression
Compress responses and decompress request bodies for each route with a traffic policy.
Reduce response payload sizes and decompress incoming request bodies with gzip compression.
About gzip compression
Gzip is an HTTP option that enables your gateway proxy to compress response data or decompress request data upon client request. Compression is useful in situations where large payloads need to be transmitted without compromising the response time.
Use the EnterpriseKgatewayTrafficPolicy resource to configure gzip compression and decompression per route. Choose between the following options:
Response compression: When enabled on a route, Solo Enterprise for kgateway compresses HTTP responses by using gzip when the downstream client includes an
Accept-Encoding: gzipheader. You can also configure Brotli and Zstd as additional codecs by using thelibrariesfield. Envoy negotiates the codec with the client with theAccept-Encodingheader and uses the configured library order as a tiebreaker when the client accepts multiple codecs equally. The following content types are compressed by default:application/javascriptapplication/jsonapplication/xhtml+xmlimage/svg+xmltext/csstext/htmltext/plaintext/xml
Request decompression: When enabled on a route, Solo Enterprise for kgateway decompresses gzip-encoded request bodies before forwarding them to the backend service. You can also configure Brotli and Zstd as additional codecs by using the
librariesfield. The codec is selected based on theContent-Encodingheader of the incoming request.
For more information about how Envoy handles compression, see the Envoy compressor filter docs.
Before you begin
Follow the Get started guide to install Solo Enterprise for kgateway.
Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
export INGRESS_GW_ADDRESS=$(kubectl get svc -n kgateway-system http -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}") echo $INGRESS_GW_ADDRESSkubectl port-forward deployment/http -n kgateway-system 8080:8080
Response compression
Enable gzip compression on a route so that Solo Enterprise for kgateway compresses responses for clients that support it.
Create an HTTPRoute that routes requests from the
compression.exampledomain to the httpbin sample app.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-compression namespace: httpbin spec: parentRefs: - name: http namespace: kgateway-system hostnames: - compression.example rules: - backendRefs: - name: httpbin port: 8000 EOFCreate a EnterpriseKgatewayTrafficPolicy that enables response compression on the route.
kubectl apply -f- <<EOF apiVersion: enterprisekgateway.solo.io/v1alpha1 kind: EnterpriseKgatewayTrafficPolicy metadata: name: response-compression namespace: httpbin spec: targetRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: httpbin-compression compression: responseCompression: {} EOFSetting Description spec.targetRefsThe HTTPRoute to apply this policy to. spec.compression.responseCompressionEnables gzip response compression. Responses are only compressed when the client sends an Accept-Encoding: gzipheader and the response content type matches one of the supported types.Send a request to the
/htmlhttpbin path with theAccept-Encoding: gzipheader. Verify that the response includes acontent-encoding: gzipheader, indicating that the response body is compressed.curl -vik http://$INGRESS_GW_ADDRESS:8080/html \ -H "host: compression.example:8080" \ -H "Accept-Encoding: gzip"curl -vik http://localhost:8080/html \ -H "host: compression.example" \ -H "Accept-Encoding: gzip"Example output:
< HTTP/1.1 200 OK HTTP/1.1 200 OK < content-type: text/html; charset=utf-8 content-type: text/html; charset=utf-8 < content-encoding: gzip content-encoding: gzip < transfer-encoding: chunked transfer-encoding: chunked < server: envoy server: envoySend the same request without the
Accept-Encoding: gzipheader. Verify that the response does not include acontent-encoding: gzipheader, confirming that compression is only applied when the client requests it.curl -vik http://$INGRESS_GW_ADDRESS:8080/html \ -H "host: compression.example:8080"curl -vik http://localhost:8080/html \ -H "host: compression.example"Example output:
< HTTP/1.1 200 OK HTTP/1.1 200 OK < content-type: text/html; charset=utf-8 content-type: text/html; charset=utf-8 < content-length: 3741 content-length: 3741 < server: envoy server: envoy
Request decompression
Enable gzip decompression on a route so that Solo Enterprise for kgateway decompresses request bodies before forwarding them to the backend service. This setup is useful when clients send gzip-encoded request bodies.
Create an HTTPRoute that routes requests from the
decompression.exampledomain to the httpbin sample app.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-decompression namespace: httpbin spec: parentRefs: - name: http namespace: kgateway-system hostnames: - decompression.example rules: - backendRefs: - name: httpbin port: 8000 EOFCreate a EnterpriseKgatewayTrafficPolicy that enables request decompression on the route.
kubectl apply -f- <<EOF apiVersion: enterprisekgateway.solo.io/v1alpha1 kind: EnterpriseKgatewayTrafficPolicy metadata: name: request-decompression namespace: httpbin spec: targetRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: httpbin-decompression compression: requestDecompression: {} EOFSetting Description spec.targetRefsThe HTTPRoute to apply this policy to. spec.compression.requestDecompressionEnables gzip request decompression. When a request arrives with a Content-Encoding: gzipheader, Solo Enterprise for kgateway decompresses the body before forwarding the request to the backend.Create a gzip-compressed payload to use in the test.
echo -n 'Hello, world!' | gzip > /tmp/payload.gzSend the compressed payload to the
/posthttpbin path with theContent-Encoding: gzipheader. Verify that thedatafield in the response shows the decompressed stringHello, world!, confirming that Solo Enterprise for kgateway decompressed the request body before forwarding it to httpbin.curl -vik -X POST http://$INGRESS_GW_ADDRESS:8080/post \ -H "host: decompression.example:8080" \ -H "Content-Type: text/plain" \ -H "Content-Encoding: gzip" \ --data-binary @/tmp/payload.gzcurl -vik -X POST http://localhost:8080/post \ -H "host: decompression.example" \ -H "Content-Type: text/plain" \ -H "Content-Encoding: gzip" \ --data-binary @/tmp/payload.gzExample output:
{ ... "data": "Hello, world!", "headers": { "Content-Type": [ "text/plain" ], ... } }
Other configurations
Brotli and Zstd compression codecs
By default, response compression uses Gzip only. You can offer additional codecs by setting the responseCompression.libraries field to an ordered list of codecs. Envoy negotiates the codec with the client by using the Accept-Encoding header. The configured order serves as a tiebreaker when the client accepts multiple codecs equally. Clients that do not accept any of the configured codecs receive an uncompressed response.
Supported codec values: Gzip, Brotli, Zstd.
The following example configures Brotli as the preferred codec with Gzip as a fallback.
kubectl apply -f- <<EOF
apiVersion: enterprisekgateway.solo.io/v1alpha1
kind: EnterpriseKgatewayTrafficPolicy
metadata:
name: response-compression
namespace: httpbin
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: httpbin-compression
compression:
responseCompression:
libraries:
- Brotli
- Gzip
- Zstd
EOFBrotli and Zstd request decompression
By default, request decompression handles only Gzip-encoded request bodies. You can add support for additional codecs by setting the requestDecompression.libraries field to an ordered list of codecs. Solo Enterprise for kgateway installs one Envoy decompressor filter per codec and selects the appropriate one based on the Content-Encoding header of the incoming request.
Supported codec values: Gzip, Brotli, Zstd.
The following example configures Brotli and Zstd in addition to Gzip for request decompression.
kubectl apply -f- <<EOF
apiVersion: enterprisekgateway.solo.io/v1alpha1
kind: EnterpriseKgatewayTrafficPolicy
metadata:
name: request-decompression
namespace: httpbin
spec:
targetRefs:
- group: gateway.networking.k8s.io
kind: HTTPRoute
name: httpbin-decompression
compression:
requestDecompression:
libraries:
- Brotli
- Gzip
- Zstd
EOFCleanup
You can remove the resources that you created in this guide.kubectl delete EnterpriseKgatewayTrafficPolicy response-compression -n httpbin
kubectl delete httproute httpbin-compression -n httpbin
kubectl delete EnterpriseKgatewayTrafficPolicy request-decompression -n httpbin
kubectl delete httproute httpbin-decompression -n httpbin