Decompressor

Decompressor is an HTTP filter which enables Envoy to bidirectionally decompress data.

Configuration

How it works

When the decompressor filter is enabled, headers are inspected to determine whether or not the content should be decompressed. The content is decompressed and passed on to the rest of the filter chain. Note that decompression happens independently for request and responses based on the rules described below.

Currently the filter supports gzip and brotli compression only. Other compression libraries can be supported as extensions.

An example configuration of the filter may look like the following:

  1. http_filters:
  2. - name: decompressor
  3. typed_config:
  4. "@type": type.googleapis.com/envoy.extensions.filters.http.decompressor.v3.Decompressor
  5. decompressor_library:
  6. name: basic
  7. typed_config:
  8. "@type": type.googleapis.com/envoy.extensions.compression.gzip.decompressor.v3.Gzip
  9. window_bits: 10

By default decompression will be skipped when:

  • A request/response does NOT contain content-encoding header.

  • A request/response includes content-encoding header, but it does not contain the configured decompressor’s content-encoding.

  • A request/response contains a cache-control header whose value includes “no-transform”.

When decompression is applied:

  • The content-length is removed from headers.

    Note

    If an updated content-length header is desired, the buffer filter can be installed as part of the filter chain to buffer decompressed frames, and ultimately update the header. Due to filter ordering a buffer filter needs to be installed after the decompressor for requests and prior to the decompressor for responses.

  • The content-encoding header is modified to remove the decompression that was applied.

  • x-envoy-decompressor-<decompressor_name>-<compressed/uncompressed>-bytes trailers are added to the request/response to relay information about decompression.

Using different decompressors for requests and responses

If different compression libraries are desired for requests and responses, it is possible to install multiple decompressor filters enabled only for requests or responses. For instance:

  1. http_filters:
  2. # This filter is only enabled for requests.
  3. - name: envoy.filters.http.decompressor
  4. typed_config:
  5. "@type": type.googleapis.com/envoy.extensions.filters.http.decompressor.v3.Decompressor
  6. decompressor_library:
  7. name: small
  8. typed_config:
  9. "@type": "type.googleapis.com/envoy.extensions.compression.gzip.decompressor.v3.Gzip"
  10. window_bits: 9
  11. chunk_size: 8192
  12. response_direction_config:
  13. common_config:
  14. enabled:
  15. default_value: false
  16. runtime_key: response_decompressor_enabled
  17. # This filter is only enabled for responses.
  18. - name: envoy.filters.http.decompressor
  19. typed_config:
  20. "@type": type.googleapis.com/envoy.extensions.filters.http.decompressor.v3.Decompressor
  21. decompressor_library:
  22. name: large
  23. typed_config:
  24. "@type": "type.googleapis.com/envoy.extensions.compression.gzip.decompressor.v3.Gzip"
  25. window_bits: 12
  26. chunk_size: 16384
  27. request_direction_config:
  28. common_config:
  29. enabled:
  30. default_value: false
  31. runtime_key: request_decompressor_enabled

Statistics

Every configured Deompressor filter has statistics rooted at <stat_prefix>.decompressor.<decompressor_library.name>.<decompressor_library_stat_prefix>.<request/response>* with the following:

Name

Type

Description

decompressed

Counter

Number of request/responses compressed.

not_decompressed

Counter

Number of request/responses not compressed.

total_uncompressed_bytes

Counter

The total uncompressed bytes of all the request/responses that were marked for decompression.

total_compressed_bytes

Counter

The total compressed bytes of all the request/responses that were marked for decompression.

Additional stats for the decompressor library are rooted at <stat_prefix>.decompressor.<decompressor_library.name>.<decompressor_library_stat_prefix>.decompressor_library.