Forum Discussion

Gilev_Anton_260's avatar
Gilev_Anton_260
Icon for Nimbostratus rankNimbostratus
Aug 17, 2017

Adding/rewriting header in server response.

Hello. Pretty new to F5 and whole iRules and already hit a wall. We need to do a next thing: If a user's request contains a certain header, i need to return content of that header in another header in a server response. All of that got to be done on our F5. I wrote an iRule, but when i enable it, traffic stops completely on that VIP.

 

when HTTP_REQUEST { if { [HTTP::header exists "Header"] } { set $insert_response_header 1 $header_var = HTTP::header value "Header" pool pool_POOL_HLS } else {pool pool_POOL_HLS }

 

} when HTTP_RESPONSE {

 

if {$insert_response_header==1}{

 

HTTP::header replace "CORS" $header_var

 

}

 

}

 

Can somebody point me in a right direction? And the main trouble is that i can't see system logs, since i don't have full access to F5.

 

1 Reply

  • Hello Gilev,

    Your code contains error, try the following :

    Also from ssh check the log file in real time using command

    tail -f /var/log/ltm

     

    when HTTP_REQUEST { 
    
        if { [HTTP::header exists "Header"] } { 
    
            set insert_response_header 1 
            set header_var [HTTP::header value "Header"]
            log local0. "Header value in request $header_var"
            pool pool_POOL_HLS 
    
        } else {
            pool pool_POOL_HLS 
        }
    
    } 
    
    when HTTP_RESPONSE {
    
        if { $insert_response_header eq "1" } {            
            HTTP::header replace "CORS" $header_var
            log local0. "Header CORS value [HTTP::header value "CORS"]"
        } 
    }
    

     

    Hope it helps

    Don't forget to give us feedback

    Regards