Forum Discussion

kykong_107132's avatar
kykong_107132
Icon for Nimbostratus rankNimbostratus
Apr 20, 2009

HTTP responser header insert base on URI

Hi all,

 

how can we insert HTTP RESPONSE header base on URI? Example, if HTTP request URI contains "/test/header/", I need to insert a new header "Via test_server" in the HTTP RESPONSE header.

 

 

Can iRule do this?

 

thank in advance.

2 Replies

  • Hi kky,

    Sure, here is an example:

     
     when HTTP_REQUEST { 
      
         Check if some condition in the request is true 
        if {[HTTP::path] starts_with "/test/string"}{ 
      
            Track that we want to insert a header in the response 
           set insert_response_header 1 
        } else { 
      
            Track that we do not want to insert a header in the response 
           set insert_response_header 0 
        } 
     } 
     when HTTP_RESPONSE { 
      
         Check if we're inserting a header in the response 
        if {$insert_response_header}{ 
      
            Insert the header 
           HTTP::header insert "my_header_name" "my_header_value" 
        } 
     } 
     

    Aaron