External requests are supported but disabled by default. Contact ngrok support to enable external access.
Configuration Reference
The Traffic Policy configuration reference for this action.Supported Phases
on_http_request
, on_http_response
Type
http-request
Configuration Fields
The destination URL for the HTTP request.
The HTTP method to use for the request.
A list of query parameters to append to the URL. Each item is an object with the following structure:Maximum:
32
entries. Key max length: 128
chars. Value max length: 8192
chars.A map of HTTP headers to include in the request. Keys are header names and values are header values.Maximum:
10
entries.The body of the HTTP request. Supported on methods like
POST
, PUT
, or PATCH
.The maximum number of HTTP redirects to follow.The minimum allowed is
0
. The maximum allowed is 100
.The maximum duration as a duration string to wait for the entire request (including retries and redirects).The minimum allowed is
1s
. The maximum allowed is 30s
.A CEL expression evaluated after each failed attempt. If
true
, the request is retried (up to 3
times).Determines how to proceed if the HTTP request fails.
Behavior
Thehttp-request
action issues an outbound HTTP request during either the on_http_request
or on_http_response
phase of policy execution. It can include dynamic headers, query parameters, and a request body.
Only specific HTTP methods are supported: GET
, POST
, PUT
, PATCH
, DELETE
, and OPTIONS
. If no method is specified, GET
is used by default.
Internal Endpoint Behavior
By default, thehttp-request
action only supports requests to internal ngrok endpoints. Requests to internal endpoints (those with .internal
domains) are treated differently from public (or external) requests, these requests must resolve to an internal ngrok endpoint running on your account.
These requests also use a direct connection over ngrok’s control plane and do not rely on the public internet. If the request targets an internal agent endpoint (e.g., your self-hosted ngrok agent), it will exit the control plane and traverse the public internet to reach your agent running locally.
Retry Logic
You can use a condition to automatically retry failed requests. This is useful for handling transient errors, like a500
response. The condition is written using an expression language and has access to:
attempts
: number of attempts so farlast_attempt.req
: the most recent requestlast_attempt.res
: the most recent responselast_attempt.error
: any error that occurred
Timeout Behavior
Thetimeout
setting defines the maximum total time allowed for the entire http-request
action, including all retry attempts. This prevents long-running or stalled requests from delaying policy evaluation.
The default timeout is 3s
. You can configure any duration between 1 second and 30 seconds using standard duration formats like 5s
or 10s
.
Timeout Error Handling
Whether a timeout causes the policy to fail or continue depends on theon_error
setting:
halt
will treat the timeout as a hard failure.continue
will move forward even if the request timed out.
Loop Protection
To prevent endless loops between services, ngrok tracks internal hops. If the same request loops more than 3 times internally, it will be stopped automatically.Redirect Behavior
By default, thehttp-request
action does not follow HTTP redirects. You can enable redirect handling by setting the max_redirects
field. The allowed range is 0
to 5
. By default it is set to 0
.
If the number of redirects exceeds max_redirects
, the action fails. Redirect handling only applies to 3xx
responses from the target server.
Response Body Size Limits
The response body returned by thehttp-request
action is limited to 256 KB. If the body size exceeds this limit, the action fails and returns a response size exceeded
error.
This limit applies to the decoded body after any decompression and before retries are evaluated.
Each retry is also subject to the 256 KB response size limit. If the response body exceeds this limit, the attempt fails and the error is included in the retry_condition
evaluation.
Error Handling
Seton_error
to control what happens if the request fails:
continue
: Policy continues even if the request fails.halt
: Policy stops immediately on failure.
Automatically Injected Headers
ngrok automatically injects some headers into your request to help with debugging, tracing and abuse:Header | Purpose |
---|---|
Ngrok-Report-Abuse | Static URL for reporting abuse |
Ngrok-Req-Type | Always set to http-request |
Ngrok-Req-Id | Unique request identifier |
X-Forwarded-For | Original client IP address |
User-Agent | Identifies the request as from ngrok/cloud |
CEL Interpolation
Certain fields in thehttp-request
action support CEL (Common Expression Language) interpolation, allowing dynamic values based on the request context.
The following fields support CEL expressions:
url
headers
(values only)query_params
(values only)body
${...}
and are evaluated at runtime using the current request data.
Examples
Make a GET request
Performs a simple GET request to an internal endpoint.Send query parameters
This example sends a GET request with custom query parameters to an internal endpoint. To simulate this behavior, we’ll use httpbin.org/get, which echoes query parameters in the response.Start an Internal Agent Endpoint
Make a POST request
This example sends a POST request to an internal endpoint with a custom JSON body and headers. To simulate this behavior, we’ll use httpbin.org/post behind an internal.internal
endpoint.
Start an Internal Agent Endpoint
Example
Follow redirects
This example demonstrates how to follow up to 2 redirects using thehttp-request
action.
To simulate this behavior, we’ll use httpbin.org/redirect behind an internal .internal
endpoint.
Start an Internal Agent Endpoint
Run the following command to exposehttps://httpbin.internal
as a simulated internal service:
Example
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.The ngrok error code for an error that occurred during the invocation of an action.
The message for an error that occurred during the invocation of an action.
A list of HTTP responses for each request attempt.
The HTTP request.
The last attempted HTTP response. Unlike
actions.ngrok.attempts[i]
this variable also contains the response body.