Transform the request sent by a client on the fly on Kong, before hitting the upstream server.
Configuration Reference
Example plugin configuration
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter | Description |
---|---|
name
required Type: string |
The name of the plugin, in this case request-transformer . |
service.id
Type: string |
The ID of the Service the plugin targets. |
route.id
Type: string |
The ID of the Route the plugin targets. |
consumer.id
Type: string |
The ID of the Consumer the plugin targets. |
enabled
required Type: boolean Default value: true |
Whether this plugin will be applied. |
api_id
Type: string |
The ID of the API the plugin targets.
Note: The API Entity is deprecated in favor of Services since CE 0.13.0 and EE 0.32. |
config.http_method
optional |
Changes the HTTP method for the upstream request. |
config.remove.headers
optional |
List of header names. Unset the header(s) with the given name. |
config.remove.querystring
optional |
List of querystring names. Remove the querystring if it is present. |
config.remove.body
optional |
List of parameter names. Remove the parameter if and only if content-type is one the following [ |
config.replace.headers
optional |
List of headername:value pairs. If and only if the header is already set, replace its old value with the new one. Ignored if the header is not already set. |
config.replace.querystring
optional |
List of queryname:value pairs. If and only if the field name is already set, replace its old value with the new one. Ignored if the field name is not already set. |
config.rename.headers
optional |
List of headername:value pairs. If and only if the header is already set, rename the header. The value is unchanged. Ignored if the header is not already set. |
config.rename.querystring
optional |
List of queryname:value pairs. If and only if the field name is already set, rename the field name. The value is unchanged. Ignored if the field name is not already set. |
config.rename.body
optional |
List of parameter name:value pairs. Rename the parameter name if and only if content-type is one the following [ |
config.append.headers
optional |
List of headername:value pairs. If the header is not set, set it with the given value. If it is already set, a new header with the same name and the new value will be set. |
config.replace.body
optional |
List of paramname:value pairs. If and only if content-type is one the following [ |
config.add.headers
optional |
List of headername:value pairs. If and only if the header is not already set, set a new header with the given value. Ignored if the header is already set. |
config.add.querystring
optional |
List of queryname:value pairs. If and only if the querystring is not already set, set a new querystring with the given value. Ignored if the header is already set. |
config.add.body
optional |
List of pramname:value pairs. If and only if content-type is one the following [ |
config.append.headers
optional |
List of headername:value pairs. If the header is not set, set it with the given value. If it is already set, an additional new header with the same name and the new value will be appended. |
config.append.querystring
optional |
List of queryname:value pairs. If the querystring is not set, set it with the given value. If it is already set, a new querystring with the same name and the new value will be set. |
config.append.body
optional |
List of paramname:value pairs. If the content-type is one the following [ |
Note: if the value contains a ,
then the comma-separated format for lists cannot be used. The array notation must be used instead.
Order of execution
Plugin performs the response transformation in following order
remove –> rename –> replace –> add –> append
Examples
In these examples we have the plugin enabled on a Service. This would work similarly for Routes, or the depreciated API entity.
- Add multiple headers by passing each header:value pair separately:
$ curl -X POST http://localhost:8001/services/example-service/plugins \
--data "name=request-transformer" \
--data "config.add.headers[1]=h1:v1" \
--data "config.add.headers[2]=h2:v1"
incoming request headers | upstream proxied headers: |
---|---|
h1: v1 |
|
- Add multiple headers by passing comma separated header:value pair:
$ curl -X POST http://localhost:8001/services/example-service/plugins \
--data "name=request-transformer" \
--data "config.add.headers=h1:v1,h2:v2"
incoming request headers | upstream proxied headers: |
---|---|
h1: v1 |
|
- Add multiple headers passing config as JSON body:
$ curl -X POST http://localhost:8001/services/example-service/plugins \
--header 'content-type: application/json' \
--data '{"name": "request-transformer", "config": {"add": {"headers": ["h1:v2", "h2:v1"]}}}'
incoming request headers | upstream proxied headers: |
---|---|
h1: v1 |
|
- Add a querystring and a header:
$ curl -X POST http://localhost:8001/services/example-service/plugins \
--data "name=request-transformer" \
--data "config.add.querystring=q1:v2,q2:v1" \
--data "config.add.headers=h1:v1"
incoming request headers | upstream proxied headers: |
---|---|
h1: v2 |
|
h3: v1 |
|
incoming request querystring | upstream proxied querystring |
---|---|
?q1=v1 | ?q1=v1&q2=v1 |
?q1=v2&q2=v1 |
- Append multiple headers and remove a body parameter:
$ curl -X POST http://localhost:8001/services/example-service/plugins \
--header 'content-type: application/json' \
--data '{"name": "request-transformer", "config": {"append": {"headers": ["h1:v2", "h2:v1"]}, "remove": {"body": ["p1"]}}}'
incoming request headers | upstream proxied headers: |
---|---|
h1: v1 |
|
incoming url encoded body | upstream proxied url encoded body: |
---|---|
p1=v1&p2=v1 | p2=v1 |
p2=v1 | p2=v1 |