Configuration reference
The Traffic Policy configuration reference for this action.Supported phases
on_http_request
Type
rate-limit
Configuration fields
Behavior
Determining the rate limit bucket
When this action runs, ngrok uses information from the incoming HTTP request to determine which rate limit bucket the request falls into. Thebucket_key configuration field defines each bucket by specific criteria such as client IP, request host, or a header value.
If the bucket hasn’t exceeded its capacity, the request proceeds to the next action in your policy configuration.
conn.client_ip is the IP address of the connection to ngrok, not a value from the X-Forwarded-For header.
A client can’t change its conn.client_ip bucket by setting X-Forwarded-For.
ngrok adds the client IP after any X-Forwarded-For values the client sends rather than replacing them.
For details, see Upstream headers.
Multiple buckets
If you specify multiplebucket_key values, the action creates a unique rate limit bucket for each combination of the specified keys.
For example, if you have two bucket_key values, such as req.host and conn.client_ip, all incoming requests that have the exact same combination of Host header and client IP are grouped into the same rate limit bucket.
To rate limit separately with two different buckets, create multiple rate-limit actions instead.
Rate limit exceeded
If the identified bucket has received more events than its capacity over the specified duration:- The request is rejected with an
HTTP 429—Too Many Requestsstatus code. - The
retry-afterheader is included in the response, indicating the number of seconds after which the request may be retried.
Capacity per ingress server
Currently, thecapacity for each rate limit bucket is applied per ingress server.
This means that each server independently tracks the number of requests and enforces the rate limits accordingly.
Non-terminating action
This is a Non-terminating action. It does not return a response, and will allow Traffic Policy processing to continue to the next Action in the chain. All Cloud Endpoint Traffic Policies must end with a terminating action. This requirement does not apply to Agent Endpoints.Examples
Rate limit by host header
The following Traffic Policy configuration demonstrates how to use therate-limit action to rate limit
all incoming requests by the Host header.
Example Traffic Policy document
Example request
httpbin.ngrok.app using the curl
command returns a 429 status code with a retry-after header indicating
the number of seconds to wait before retrying the request.