This plugin allow to change on the fly header's value of a request.
traefik.yml
configuration file for traefikpilot:token: [REDACTED]experimental:devPlugin:goPath: /home/tm/gomoduleName: github.com/tommoulard/htransformationentryPoints:http:address: ":8000"forwardedHeaders:insecure: trueapi:dashboard: trueinsecure: trueproviders:file:filename: rules-htransformation.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 either
Each Rule can be named with the Name
field
A Rename rule need 2 arguments
Header
, the regex of the header you want to replaceValue
, the new header# Example Rename- Rule:Name: 'Header rename'Header: 'Cache-Control'Value: 'NewHeader'Type: 'Join'
# Old header:Cache-Control: gzip, deflate# New header:NewHeader: gzip, deflate
- Rule:Name: 'Header Renaming'Header: 'X-Traefik-*'Value: 'X-Traefik-merged'Type: 'Join'
# 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 exist)
A rule Set need 2 arguments
Header
, the header you want to createValue
, the value of the new header# Example Join- Rule:Name: 'Set Cache-Control'Header: 'Cache-Control'Value: 'Foo'Type: 'Join'
# New header:Cache-Control: Foo
A rule Delete need 1 arguments
Header
, the header you want to delete# Example Del- Rule:Name: 'Delete Cache-Control'Header: 'Cache-Control'Type: 'Del'
A Join rule will concat the values of the existing header with the new one. If the header doesnt exist, it'll do nothing
It needs 3 arguments
Header
, the header you want to joinValues
, a list of values to add to the existing headerSep
, the separator you want to use# Example Join- Rule:Name: 'Header join'Header: 'Cache-Control'Sep: ','Values:- 'Foo'- 'Bar'Type: 'Join'
# Old header:Cache-Control: gzip, deflate# Joined header:Cache-Control: gzip, deflate,Foo,Bar
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'
Will firstly set the header X-Custom-2
to 'True', then delete it and lastly set it again but with False
Tom Moulard | Clément David | Martin Huvelle | Alexandre Bossut-Lasry |
---|---|---|---|
![]() | ![]() | ![]() | ![]() |