description |
---|
This page provides the technical details of the Transform Headers policy |
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:
{% hint style="warning" %} This policy can be applied to all Gravitee APIs: v2 APIs, v4 proxy APIs, and v4 message 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="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 %}
The phases checked below are supported by the transform-headers
policy:
v2 Phases | Compatible? | v4 Phases | Compatible? |
---|---|---|---|
onRequest | true | onRequest | true |
onResponse | true | onResponse | true |
onRequestContent | true | onMessageRequest | true |
onResponseContent | true | onMessageResponse | true |
The following is the compatibility matrix for APIM and the transform-headers
policy:
Plugin Version | Supported APIM versions |
---|---|
1.x | 3.x |
3.x | 4.0+ |
{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-transform-headers/blob/master/CHANGELOG.md" %}