Forum Discussion

ashokp1's avatar
ashokp1
Icon for Altostratus rankAltostratus
Oct 02, 2025
Solved

F5 iRule for X-Country-Code not working as expected

Is it possible to insert an X-Country-Code into the F5 BIG-IP response to the client.    I want to do this only for a specific URI pattern. I tried the iRule below, using HTTP_REQUEST to capture th...
  • ashokp1's avatar
    ashokp1
    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
        }
    }