Forum Discussion

zeropixel_23561's avatar
zeropixel_23561
Icon for Nimbostratus rankNimbostratus
Dec 24, 2015

iRule to add the Server header in the HTTP Response (PLEASE HELP)

I created the iRule and need to add the Server header in the HTTP Response.

 

I added the iRule from the article https://support.f5.com/kb/en-us/solutions/public/10000/000/sol10089.html, but it added Xerver: ABC, not Server: ABC. I changed to Server instead but failed working. Any ideas? Please help. Thanks so much!!

 

In the Definition field, paste the following iRule:

 

when HTTP_RESPONSE { if { [HTTP::header exists "Server"] } { HTTP::header insert Xerver [HTTP::header value "Server"] } }

 

10 Replies

  • If you are just trying to add/replace the server header this simple iRule should do the trick to set the server header to "ABC.

     

    when HTTP_RESPONSE {
        HTTP::header replace Server "ABC"
    }
    

     

  • I did the following to add the header, but still cannot see in the response. I have confirmed the virtual server has added the irule. By the way, I am using version 12, not 11. It shouldn't matter, I hope. Any ideas? Please help!!

     

    when HTTP_RESPONSE { HTTP::header insert Server "ABC" }

     

  • https://support.f5.com/kb/en-us/solutions/public/14000/300/sol14342.html

     

    Is "Xerver" have some meaning? I am confused why not called "Server", I used the following but it added Xerver: ABC in the response.

     

    when HTTP_RESPONSE { if { [HTTP::header exists "Server"] } { HTTP::header insert Xerver [HTTP::header value "Server"] } } when HTTP_RESPONSE_RELEASE { if { [HTTP::header exists "Xerver"] } { HTTP::header insert Server [HTTP::header value "Xerver"] HTTP::header remove Xerver } }

     

  • Xerver cannot be changed to Server, it is probably the F5 keyword? I do not know the meaning though.

     

    when HTTP_RESPONSE { if { [HTTP::header exists "Server"] } { HTTP::header insert Xerver [HTTP::header value "Server"] } } when HTTP_RESPONSE_RELEASE { if { [HTTP::header exists "Xerver"] } { HTTP::header insert Server [HTTP::header value "Xerver"] HTTP::header remove Xerver } }

     

  • It keep generating Xerver for me, that is frustrating.

     

    If I change every Xerver to Server, it is just not working and cannot append the Server header in response. Any ideas please?? Thanks!!

     

    when HTTP_RESPONSE { if { [HTTP::header exists "Server"] } { HTTP::header insert Server [HTTP::header value "Server"] } } when HTTP_RESPONSE_RELEASE { if { [HTTP::header exists "Server"] } { HTTP::header insert Server [HTTP::header value "Server"] HTTP::header remove Server } }

     

  • I need Server in response header back to the browser, because client side code has validation and it is failing. It is just not working when I changed to Xerver to Server.

     

    when HTTP_RESPONSE { if { [HTTP::header exists "Server"] } { HTTP::header insert Server [HTTP::header value "Server"] } } when HTTP_RESPONSE_RELEASE { if { [HTTP::header exists "Server"] } { HTTP::header insert Server [HTTP::header value "Server"] HTTP::header remove Server } }

     

  • Hi Zeropixel,

    keep in mind that the sol10089 is referencing to a very specific scenario and also some rather old LTM versions.

    If you want to preserve the server header on ASM enabled virtual servers on newer LTM versions, this code would make it...

     

    when HTTP_RESPONSE {
        set server_header [HTTP::header value "Server"]
    }
    
    when HTTP_RESPONSE_RELEASE {
        if { $server_header ne "" } then {
            HTTP::header insert Server $server_header
        }
    }
    

     

    Note: It saves the original Server: header value into a variable during HTTP_RESPONSE. And then copies variable back to the Server: header during HTTP_RESPONSE_RELEASE. The reason for that is that ASM performs some header clean ups including the removal of Server: beader in between the two events.

    To set a fixed server header value on ASM enabled virtual servers, use this code...

     

    when HTTP_RESPONSE_RELEASE {
        HTTP::header insert Server "My-Server-Name"
    }
    

     

    But if you don't use ASM enabled virtual servers, then this command could be used to add or overwrite the server header values...

     

    when HTTP_RESPONSE {
        HTTP::header replace Server "My-Server-Name"
    }
    

     

    Cheers, Kai