compress-response

Compresses your service’s answer with gzip, Brotli or deflate — whichever the visitor’s browser prefers — as it streams.

Phaseson_http_response
Terminating No — the next action runs after it.
Cost 10 Traffic Policy units per run · not on the Free plan

Example

policy.yaml
on_http_response:
  - expressions:
      - "req.url.path.startsWith('/api/')"
    actions:
      - type: compress-response
        config:
          algorithms: [gzip, br, deflate]

Start an agent endpoint with it: devgate http 8080 --traffic-policy-file policy.yaml, or paste it into a reserved or cloud endpoint’s Traffic Policy tab in the dashboard.

Configuration

Field Type Description
algorithms list of strings The algorithms to choose from: gzip, deflate, br, compress, each once. When the client rates several the same, the earlier one in this list wins. Default: gzip, deflate, br, compress.

Result variables

After it runs, later rules can read what it decided:

  • actions.ngrok.compress.already_compressed — Whether the answer was compressed before the action ran (then it was left alone).
  • actions.ngrok.compress.negotiated_algorithm — The algorithm applied: gzip, br or deflate; empty when nothing was compressed.

Behaviour

  • Nothing is compressed unless the request has an Accept-Encoding header; devgate picks the allowed algorithm the client gives the highest q-value (RFC 9110).
  • An answer your service already compressed — it has a Content-Encoding — passes through unchanged.
  • The body is compressed as it streams: each chunk your service flushes reaches the visitor at once, so streamed JSON and long polling keep working. Server-sent events (text/event-stream), gRPC, images, video, audio and archives are never compressed.
  • Content-Length is removed, Content-Encoding and Vary: Accept-Encoding are set, and a strong ETag becomes weak.
  • compress is accepted, as ngrok accepts it, but never chosen: no current browser asks for it.
  • With full capture on, the Traffic Inspector shows the body as your service sent it, uncompressed.

Other actions

add-headers remove-headers basic-auth oauth openid-connect jwt-validation custom-response deny redirect url-rewrite restrict-ips rate-limit circuit-breaker verify-webhook http-request set-vars log close-connection forward-internal