Forum Discussion
F5 iRule for X-Country-Code not working as expected
- Oct 22, 2025
Thanks Jeffrey_Granier, I tried the code below which resolved my issue. Thanks for your support.
when HTTP_REQUEST {
if {[HTTP::uri] starts_with "/java"} {
set country_code [whereis [IP::client_addr] country]
log local0. "Matched /java - client IP: [IP::client_addr], country: $country_code"
set session_key "country_[TCP::client_port]"
table set $session_key $country_code 300
}
}when HTTP_RESPONSE_RELEASE {
set session_key "country_[TCP::client_port]"
set country_code [table lookup $session_key]
if {$country_code ne ""} {
log local0. "HTTP_RESPONSE triggered for session $session_key, country: $country_code"
HTTP::header insert "X-Client-Country-Code" $country_code
log local0. "Added X-Country-Code: $country_code to response"# Clean up the session table
table delete $session_key
}
}
Hello ashokp1,
I see you have a few responses to assist you and wanted to encourage you to update your post if either of these have helped answer your questions. If they have please mark the post as solved, or if it has not please update with where you are at and what you may need additional help with.
Thank you for being a part of our community!
-Melissa
Recent Discussions
Related Content
* 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