Skip to main content

Remove Headers

Overview

The Remove Headers Traffic Policy action enables you to remove headers from an HTTP request before it is sent upstream or from an HTTP response before it is sent back to the client.

Configuration Reference

This is the Traffic Policy configuration reference for this action.

Action Type

remove-headers

Configuration Fields

ParameterTypeDescription
headers[]stringList of header keys to remove from the request or response. Minimum 1, Maximum 10.

Supported Phases

  • on_http_request
  • on_http_response

Supported Schemes

  • https
  • http

Behavior

When executed during the on_http_request phase, this action will remove the specified headers from incoming http requests before reaching the upstream server. When executed during the on_http_response, the configured headers are removed from http responses returned from the upstream server before reaching the client.

Removal Only

This action will only remove headers from the request or response.

  • If you want to add a header use the add-headers action.
  • If you want to replace a header, first use this action then use the add-headers action.

Ordering

Since actions are run in the order they are specified, to modify headers that have been added by other actions you must place this action after them in your traffic policy document.

Special Cases

  • You may not add or remove the user-agent header.

Examples

Removing headers from all requests

We have been getting a lot of requests with x-client-version and x-trace-id and it is starting to overwhelm our logging system. We want to remove these headers from all requests. The following example demonstrates how to remove these headers using the remove-headers action.

Example Traffic Policy Document

---
on_http_request:
- actions:
- type: "remove-headers"
config:
headers:
- "x-client-version"
- "x-trace-id"

For this example, we are assuming that ngrok is pointing at the upstream service https://httpbin.org.

Example Request

$ curl -H "x-client-version: 3.1" -H "x-trace-id: abc123" https://httpbin.ngrok.app/get
< HTTP/2 200

{
...
"headers": {
"Date": "2024-06-24T15:30:00Z",
}
...
}

In this example even though we sent the x-client-version and x-trace-id headers, they were not present on the request that was sent upstream.

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.

NameTypeDescription
actions.ngrok.remove_headers.headers_removed[]stringList of headers that were removed by the action.