htransformation
htransformation copied to clipboard
Setting X-Real-Ip from values in X-Forwarded-For
I have the following requirement and was wondering if htransformation
could be used to solve it: Traefik receives requests that contain the following header:
X-Forwarded-For: 62.123.23.32:63417, 172.22.0.4
What I would like to do, is add the following header, using the value of X-Forwarded-For
:
X-Real-Ip: 62.123.23.32
I was thinking about an approach like:
- clone
X-Forwarded-For
header asX-Real-Ip
- using
RewriteValueRule
tweak the value ofX-Real-Ip
to only include the first IP address from the list.
What I can't figure out is 1.: I thought I could use Set
with HeaderPrefix
to reference the value of another header. However, it seems HeaderPrefix
is only supported by Join
. When using Join
however, X-Real-Ip
is not set - maybe because Join
requires the header to already be there (assumption based on join.go implementation)?
Do you have any thoughts on whether it's feasible to solve the above using htransformation
and if so, how?