Forum Discussion
Nandhi
Jan 10, 2024Cirrus
Add a custom "X-forwarded-for" header name
Hello Everyone, Need an assistant to add custom http header name and value to insert XFF headers. The default name "X-forwarded-for" cannot understand by the client side. Example need to add name "H...
JRahm
Jan 11, 2024Admin
Hi Nandhi, I am not able to get the profile suggestions by Paulius or zamroni777 working in my local lab (happy to be told what I'm doing wrong!) but I am able to a) remove any existing X-Forwarded-For that arrives and b) insert new based on the requests client IP address both via iRule and local traffic policy. I find the traffic policy overly complicated as it requires Tcl anyway, so personally I'd use the iRule, but both solutions work.
iRule
when HTTP_REQUEST {
if { [HTTP::header exists "X-Forwarded-For"] } {
HTTP::header remove "X-Forwarded-For"
}
HTTP::header insert "X-Custom-XFF" [IP::client_addr]
}
Policy
ltm policy insert_custom_xff {
last-modified 2024-01-10:15:50:09
requires { http }
rules {
custom_xff {
actions {
0 {
http-header
insert
name X-Custom-XFF
value tcl:[IP::client_addr]
}
}
ordinal 1
}
remove_std_xff {
actions {
0 {
http-header
remove
name X-Forwarded-For
}
}
}
}
status published
strategy all-match
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects