Skip to main content

Add Headers

Overview

The Add Headers policy action enables the addition of headers to both inbound requests and outbound responses.

Example

Use this action config in your Traffic Policy

# snippet
---
actions:
- type: "add-headers"
config:
headers:
is-ngrok: "1"
country: "${conn.geo.country_code}"

Behavior

When executed as an inbound policy, this action will add headers on an incoming http request before reaching the upstream server with the configured headers. When executed as an outbound policy, the configured headers are added to the response from the upstream server.

Reference

Supported Directions

  • Inbound
  • Outbound

Configuration

Type
add-headers
Parameter Description
headersMap<string, string>Headers to be added to the either the request or response. Supports interpolating the results of cel expressions in header values.

Templating Syntax

The results of CEL expressions can be interpolated into your policy's config using ngrok's ${} templating syntax. For a complete list of available variables and functions or to see a more detailed explanation, checkout the docs.

Templating Examples

# simple variable replacement
---
actions:
- type: "add-headers"
config:
headers:
time: "${time.now}"
# using a macro
---
actions:
- type: "add-headers"
config:
headers:
x-has-foobar: "${hasReqHeader('foobar')}"
# complex expression
---
actions:
- type: "add-headers"
config:
headers:
complex: "${size(getReqHeader('Content-Type')) > 0}"