Forum Discussion

James_124570's avatar
James_124570
Icon for Nimbostratus rankNimbostratus
Mar 20, 2015

Trying to change HTTP header User agent

Hi everyone!

I am trying to log the http:header user-agent to a variable using an iRule. I am trying to log exactly what broswer the client is using:(IE, FF, Chrome). Right now, the log shows: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" Here is what I have so far.

when HTTP_REQUEST {
   if {[HTTP::header "User-Agent"] contains "Firefox"} then {
      set user_agent "Firefox" }
   elseif {[HTTP::header "User-Agent"] contains "Chrome"} then {
      set user_agent "Chrome" }
   else {
   set user_agent "IE" 
    log local0. "User Agent is: $user_agent"
    }
}

but the logs shows the same output.

Any help would be great!

Thanks everyone!

  • when HTTP_REQUEST {
       if {[HTTP::header "User-Agent"] contains "Firefox"} then {
          set user_agent "Firefox" }
       elseif {[HTTP::header "User-Agent"] contains "Chrome"} then {
          set user_agent "Chrome" }
       else {
       set user_agent "IE" 
        }
        log local0. "User Agent is: $user_agent"
    }
    
  • even took a step further:

    if {[HTTP::header "User-Agent"] contains "Firefox"} then {
        set User_agent "Firefox" }
    elseif {[HTTP::header "User-Agent"] contains "Chrome"} then {
        set User_agent "Chrome" }
    elseif {[HTTP::header "User-Agent"] contains "Trident/5.0"} then {
        set User_agent "Internet Explorer-v9.0" }
    elseif {[HTTP::header "User-Agent"] contains "Trident/6.0"} then {
        set User_agent "Internet Explorer-v10.0" }
    elseif {[HTTP::header "User-Agent"] contains "Trident/7.0"} then {
        set User_agent "Internet Explorer-v11.0" }
    else {
        set User_agent "Safari" 
            log local0. "Http_version is = $http_version"
    }