Skip to main content

Phases

In Traffic Policy, a phase represents a distinct point in the lifecycle of a request as it moves through an ngrok endpoint. Phases allow you to inspect, process, and manage traffic at key moments.

Traffic Policy Phases

on_tcp_connect

The first phase in the traffic lifecycle. This phase is triggered when a new TCP connection is established. It provides an opportunity to allow, reject, or manipulate connections before any higher-level protocol processing begins. This phase is present in all traffic to the endpoint.

on_http_request

Activated when ngrok receives an HTTP request over an established connection. This phase provides access to the request's details (e.g., headers, method, path) as variables and is ideal for actions like forwarding traffic, rewriting paths, or applying authentication and rate limits.

on_http_response

Triggered after ngrok receives a response from the upstream service. This phase allows you to modify the response before it is sent to the client, such as by adding headers, changing status codes, or transforming the response body.

Phases Available by Protocol

Some phases are not available on certain protocols. The following table defines the availability by protocol:

Protocolon_tcp_connecton_http_requeston_http_response
HTTPS
HTTP
TLS
TCP