Document updated on Jul 30, 2024
The response headers modifier allows you to add
, replace
, or delete
headers declaratively before responses are returned to the end-user for all declared endpoints simultaneously.
The main benefit of the modifier/response-headers
is that the execution happens at the end of the response flow, and you can transform headers from all types of endpoints or encodings or change headers set by KrakenD itself (like the X-KrakenD-Complete
and similar)
With this component, you can transform the returning headers no matter how they were generated.
The configuration of the modifier is quite simple, and is declared at the service level, acting over all endpoints’ activity. If you want to transform headers in a single endpoint, see the different ways below.
mY-HEAdEr
becomes My-Header
.Here is a configuration example that performs the three types of transformations:
X-Hello: World
header to all responsesCache-Control
to set a no-store
valueServer
header set by the backend{
"version": 3,
"extra_config": {
"modifier/response-headers": {
"add": {
"X-Hello": [
"World"
]
},
"replace": {
"Cache-Control": [
"no-store"
],
"Vary": [
"foo",
"bar",
"foobar"
]
},
"delete": [
"Server"
]
}
}
}
The operations are always executed in this fixed order:
delete
replace
add
| The headers you want to add. Every key under add is the header name, and the values are declared in an array with all those you want to set. If the header didn’t exist previously, it is created with the values you passed. If the header existed, then the new values are appended.Properties of |
| The list of headers you want to delete. All headers listed will be missing in the response. Example: ["X-Krakend","X-Krakend-Completed"] |
| The headers you want to replace. The key used under replace is the header name, and the value an array with all the header values you want to set. The replacement overwrites any other value that could exist in this header.Properties of |
X-KrakenD
headersIf for any reason you want to remove the KrakenD headers from the reponses, you only need to set the following configuration:
{
"version": 3,
"extra_config": {
"modifier/response-headers": {
"delete": [
"X-Krakend", "X-Krakend-Completed"
]
}
}
}
There are several ways to set response headers without the modifier/response-headers
that allow you work on a per-endpoint scenario, such as:
no-op
encoding on the endpoints you like.no-op
)The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.