Cannot modify existing list with something else to come first in Join
adyanth opened this issue · 4 comments
If I have the header X-Forwarded-For: a,b,c
and would like to make it X-Forwarded-For: s,a,b,c
, it is not possible currently.
One workaround would be to set the current value to another temp header, set a new value to this, and then Join with the temp header using fix for #14 .
This is not really intuitive. If fix for #14 is present, the Join can be modifed to delete the initial value, and if that needs to be present in Join, user can call the header itself in the value to be joined at any place.
At that point, set could become join, since join with one argument is same as set. It would reduce duplication, and confusion on Join by explicitly saying the existing header will be present after.
Hello @adyanth,
Thanks for your interest in this Traefik plugin!
As you said, for now, the join
adds the value at the end of the header value.
Maybe adding an option to add the value in front of other values might be the easiest. Something like :
- Rule:
Name: 'Header join'
Header: 'Cache-Control'
Sep: ','
Values:
- 'Foo'
- 'Bar'
Type: 'Join'
Mode: 'Front' # or 'Back' as default
# Old header:
Cache-Control: gzip, deflate
# Joined header with 'Back':
Cache-Control: gzip, deflate,Foo,Bar
# Joined header with 'Front':
Cache-Control: Bar,Foo,gzip, deflate
As for this :
At that point, set could become join
I don't think it is a good idea to remove Set
or Join
. In one hand, it would be a breaking change (this is still a beta plugin, so it is not so important).
And in the other hand, it might not be super clear to the user to have to use Set
to join so headers or Join
to set a header
Hey @tomMoulard
Even limiting Join to add at beginning or ending is still a limitation I would say.
The approach of Set with join capability is that you will be explicitly saying if you would like to overwrite the old one or join it.
Something like:
- Rule:
Name: 'Header join'
Header: 'Cache-Control'
Sep: ','
Values:
- 'Foo'
- 'Bar'
Type: 'Set'
vs
- Rule:
Name: 'Header join'
Header: 'Cache-Control'
Sep: ','
HeaderPrefix: '^'
Values:
- 'Foo'
- '^Cache-Control'
- 'Bar'
Type: 'Set'
where you can exactly see if you are joining by referring to the header's old value or overwriting it by ignoring the old one.
At least that is what I had in mind. It is fine if that is not what you had in mind for this plugin, which is why I asked a license to be added ;) so that I can roll my own.
While messing around with this, I have another query on when/how traefik determines to set the XFF header when using middlewares which I think is more relevant to be asked in the traefik forum/issue. Even with trust headers set, it seems to add its own IP regardless. Let me know if you might be able to answer this if I describe in more detail.
Close thanks to 865d14b