Replaces every match of a Java regular expression in the message body or in all header values.
The body is decoded first and sent without Content-Encoding afterwards. Messages with a binary content type are left unchanged. If the body cannot be replaced, the flow is aborted with a 500 error.
Security Hint
The expression may run on requests and responses. Overlapping quantifiers such as (.*),(.*) can take a long time on crafted messages. See ReDoS Protection.
Example Configuration
api:
port: 2000
flow:
- response:
- regExReplacer:
regex: 'http://backend\.internal:8080(/[^"\s]*)'
replace: 'https://api.example.com$1'
target:
url: http://backend.internal:8080
api:
port: 2000
flow:
- response:
- regExReplacer:
regex: 'http://backend\.internal:8080(/[^"\s]*)'
replace: 'https://api.example.com$1'
target:
url: http://backend.internal:8080
Syntax
regExReplacer:
regex: <string> # required
replace: <string> # required
target: bodyregExReplacer: regex: <string> # required replace: <string> # required target: body
Attributes
| Name | Required | Default | Description | Examples |
|---|---|---|---|---|
| regex | true | - | Java regular expression. Every match is replaced. | http://backend\.internal:8080(/[^"\s]*) |
| replace | true | - | Replacement for each match. $1, $2, ... insert the groups captured by regex; write \$ for a literal dollar sign. | https://api.example.com$1 |
| target | false | body | body replaces in the message body, header in the values of all header fields. | header |