This plugin allows to change, on the fly, the header's value of a request.
traefik.yml
configuration file for traefikpilot:token: [REDACTED]experimental:devPlugin:goPath: /home/tm/gomoduleName: github.com/adyanth/header-transformentryPoints:http:address: ":8000"forwardedHeaders:insecure: trueapi:dashboard: trueinsecure: trueproviders:file:filename: rules-header-transform.yaml
$ docker run -d --network host containous/whoami -port 5000# traefik --config-file traefik.yml
To choose a Rule you have to fill the Type
field with one of the following:
Each Rule can be named with the Name
field
A Rule Rename needs two arguments and optionally the third.
Header
, the regex of the header you want to replaceValue
, the new headerHeaderPrefix
, the prefix to denote the new Header name is to be taken from another header value# Example Rename- Rule:Name: 'Header rename'Header: 'Cache-Control'Value: 'NewHeader'Type: 'Rename'
# Old header:Cache-Control: gzip, deflate# New header:NewHeader: gzip, deflate
- Rule:Name: 'Header Renaming'Header: 'X-Traefik-*'Value: 'X-Traefik-merged'Type: 'Rename'
# Old header:X-Traefik-uuid: 0X-Traefik-date: mer. 21 oct. 2020 11:57:39 CEST# New header:X-Traefik-merged: 0 # A value from old headers
A Set rule will either create or replace the header and value (if it already exists), appending multiple values with the separator if specified.
A Rule Set needs the first two arguments, and optionally the next three.
Value
can be skipped if specifying Values
.
Header
, the header you want to createValue
, the value of the new headerValues
, a list of values to addSep
, the separator you want to useHeaderPrefix
, the prefix to denote the Value is to be taken from another header# Example Set- Rule:Name: 'Set Cache-Control'Header: 'Cache-Control'Value: 'Foo'Type: 'Set'
# New header:Cache-Control: Foo
# Example Usage- Rule:Name: 'Header set'Header: 'X-Forwarded-For'Value: '^CF-Connecting-IP'HeaderPrefix: "^"Type: 'Set'
# Old header:CF-Connecting-IP: 1.1.1.1# New headers:CF-Connecting-IP: 1.1.1.1X-Forwarded-For: 1.1.1.1
# Example Usage- Rule:Name: 'Header XFF'Header: 'X-Forwarded-For'Value: '^CF-Connecting-IP'Values:- '^X-Forwarded-For'- '192.168.0.1'Sep: ', 'HeaderPrefix: "^"Type: 'Set'
# Old header:CF-Connecting-IP: 1.1.1.1X-Forwarded-For: 10.0.0.1, 10.10.10.1# New headers:CF-Connecting-IP: 1.1.1.1X-Forwarded-For: 1.1.1.1, 10.0.0.1, 10.10.10.1, 192.168.0.1
# Example Join- Rule:Name: 'Header join'Header: 'Cache-Control'Sep: ','HeaderPrefix: "^"Values:- '^Cache-Control'- 'Foo'- 'Bar'Type: 'Set'
# Old header:Cache-Control: gzip, deflate# Joined header:Cache-Control: gzip, deflate,Foo,Bar
A Rule Delete needs only one argument
Header
, the header you want to delete# Example Del- Rule:Name: 'Delete Cache-Control'Header: 'Cache-Control'Type: 'Del'
The rules will be evaluated in the order of definition
#Example- Rule:Name: 'Header addition'Header: 'X-Custom-2'Value: 'True'Type: 'Set'- Rule:Name: 'Header deletion'Header: 'X-Custom-2'Type: 'Del'- Rule:Name: 'Header join'Header: 'X-Custom-2'Value: 'False'Type: 'Set'
This will firstly set the header X-Custom-2
to 'True', then delete it and finally set it again but with False