Gzip Compression

Gzip enables Ambassador to compress upstream data upon client request. Compression is useful in situations where large payloads need to be transmitted without compromising the response time. Compression can also save on bandwidth costs at the expense of increased compute cost.

How does it work

When the gzip filter is enabled, request and response headers are inspected to determine whether or not the content should be compressed. The content is compressed and then sent to the client with the appropriate headers if either response and request allow.

For more details see Envoy - Gzip

The gzip API

  • memory_level: Value from 1 to 9 that controls the amount of internal memory used by zlib. Higher values use more memory, but are faster and produce better compression results. The default value is 5.
  • min_content_length: Minimum response length, in bytes, which will trigger compression. The default value is 30.
  • compression_level: A value used for selecting the zlib compression level. This setting will affect speed and amount of compression applied to the content. “BEST” provides higher compression at the cost of higher latency, “SPEED” provides lower compression with minimum impact on response time. “DEFAULT” provides an optimal result between speed and compression. This field will be set to “DEFAULT” if not specified.
  • compression_strategy: A value used for selecting the zlib compression strategy which is directly related to the characteristics of the content. Most of the time “DEFAULT” will be the best choice, though there are situations which changing this parameter might produce better results. For example, run-length encoding (RLE) is typically used when the content is known for having sequences which same data occurs many consecutive times. For more information about each strategy, please refer to zlib manual.
  • content_type: Set of strings that allows specifying which mime-types yield compression; e.g., application/json, text/html, etc. When this field is not defined, compression will be applied to the following mime-types: “application/javascript”, “application/json”, “application/xhtml+xml”, “image/svg+xml”, “text/css”, “text/html”, “text/plain”, “text/xml”.
  • disable_on_etag_header: If true, disables compression when the response contains an etag header. When it is false, the filter will preserve weak etags and remove the ones that require strong validation.
  • remove_accept_encoding_header: If true, removes accept-encoding from the request headers before dispatching it to the upstream so that responses do not get compressed before reaching the filter.


apiVersion: ambassador/v0
kind:  Module
name:  ambassador
    memory_level: 2
    min_content_length: 32
    compression_level: BEST
    compression_strategy: RLE
    - application/javascript
    - application/json
    - text/plain
    disable_on_etag_header: false
    remove_accept_encoding_header: false

Minimum configuration:

apiVersion: ambassador/v0
kind:  Module
name:  ambassador
    enabled: true