Skip to content

Latest commit

 

History

History
157 lines (127 loc) · 4.18 KB

File metadata and controls

157 lines (127 loc) · 4.18 KB
description
This page provides the technical details of the Transform Headers policy

Transform Headers

Overview

You can use the transform-headers policy to override HTTP headers in incoming requests or outbound responses. You can override the HTTP headers by:

  • Adding to or updating the list of headers
  • Removing headers individually
  • Defining a whitelist == Compatibility with APIM

Functional and implementation information for the transform-headers policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can be applied to v2 APIs, v4 HTTP proxy APIs, and v4 message APIs. It cannot be applied to v4 TCP proxy APIs. {% endhint %}

{% hint style="info" %} The policy configuration for a v2 API using the legacy execution engine must include the scope. If the policy is applied to a v4 API or a v2 API using the emulated reactive engine, the configuration does not include scope. {% endhint %}

{% tabs %} {% tab title="v2 API example" %} Sample policy configuration:

"transform-headers": {
    "addHeaders": [
        {
            "name": "X-Gravitee-Request-Id",
            "value": "{#request.id}"
        }
    ],
    "removeHeaders": [
        "X-Gravitee-TransactionId"
    ],
    "whitelistHeaders": [
        "Content-Type",
        "Content-Length"
    ],
    "scope": "REQUEST"
}

Add a header from the request’s payload:

"transform-headers": {
    "addHeaders": [
        {
            "name": "X-Product-Id",
            "value": "{#jsonPath(#request.content, '$.product.id')}"
        }
    ]
    "scope": "REQUEST_CONTENT"
}

{% endtab %}

{% tab title="HTTP proxy API example" %} Sample policy configuration:

"transform-headers": {
    "addHeaders": [
        {
            "name": "X-Gravitee-Request-Id",
            "value": "{#request.id}"
        }
    ],
    "removeHeaders": [
        "X-Gravitee-TransactionId"
    ],
    "whitelistHeaders": [
        "Content-Type",
        "Content-Length"
    ],
}

Add a header from the request’s payload:

"transform-headers": {
    "addHeaders": [
        {
            "name": "X-Product-Id",
            "value": "{#jsonPath(#request.content, '$.product.id')}"
        }
    ]
}

{% endtab %}

{% tab title="Message API example" %} Sample policy configuration:

"transform-headers": {
    "addHeaders": [
        {
            "name": "X-Gravitee-Message-Id",
            "value": "{#message.id}"
        }
    ],
    "removeHeaders": [
        "X-Gravitee-TransactionId"
    ],
    "whitelistHeaders": [
        "Content-Type",
        "Content-Length"
    ],
}

Add a header from the message’s payload:

"transform-headers": {
    "addHeaders": [
        {
            "name": "X-Product-Id",
            "value": "{#jsonPath(#message.content, '$.product.id')}"
        }
    ]
}

{% endtab %} {% endtabs %}

Configuration

Phases

The phases checked below are supported by the transform-headers policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsetrueonResponsetrue
onRequestContenttrueonMessageRequesttrue
onResponseContenttrueonMessageResponsetrue

Compatibility matrix

The following is the compatibility matrix for APIM and the transform-headers policy:

Plugin VersionSupported APIM versions
1.x3.x
3.x4.0+

Changelogs

{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-transform-headers/blob/master/CHANGELOG.md" %}