Configuration Reference
The Traffic Policy configuration reference for this action.Supported Phases
on_http_response
Type
compress-response
Configuration Fields
A list of allowed compression algorithms to be considered during encoding
type negotiation. Each element must be unique.
Supported algorithms
br
compress
deflate
gzip
Behavior
When an HTTP request includes anAccept-Encoding
header, HTTP responses are
automatically compressed, and a Content-Encoding header is added to the
response.
If the response is already compressed by your upstream service,
no additional compression will be applied.
Streaming Compression
When compression is applied, the response body is not buffered; it is compressed in real-time as it streams through the ngrok endpoint.Algorithm Choice
If a request specifiesAccept-Encoding
but none of the requested algorithms
are supported, no compression is applied, and the upstream response is returned
unmodified.
Quality Values
Compression is negotiated based on theAccept-Encoding
header as defined by
the RFC,
respecting q-values and selecting the supported algorithm with the highest
q-value.
For example:
gzip
would be selected because it has the highest q-value of 1.0
.
Response Headers
When this action performs compression, the following changes are made to the HTTP response headers:- The
Content-Length
header is removed. - A
Content-Encoding
header is added, specifying the negotiated algorithm. - A
Vary: Accept-Encoding
header is added to indicate that the response varies based on theAccept-Encoding
request header.
Examples
Compressing API Responses Based on URL Path
The following Traffic Policy configuration demonstrates how to set this up using thecompress-response
action with an expression to compress traffic on specific URL paths.
Example Traffic Policy Document
Example Request
/api/posts
,
ngrok compresses the response using one of the specified algorithms
(e.g., gzip
). The response includes the content-encoding: gzip
header, and
the body is compressed accordingly.
This setup ensures that only API responses
for paths starting with /api/
are compressed, enhancing performance and
responsiveness for only those endpoints.
Action Result Variables
The following variables are made available for use in subsequent expressions and CEL interpolations after the action has run. Variable values will only apply to the last action execution, results are not concatenated.Indicates whether the body was already compressed before the action was
applied. Returns
true
if no further compression was
performed.The compression algorithm selected and applied by the action, based on the
client’s request and action configuration.