Forum Discussion

senthil's avatar
senthil
Icon for Nimbostratus rankNimbostratus
Oct 16, 2019

Need Irule to replace http host based on pool member

Team,

 

Need an Irule to replace http host based on pool member when sending request.

 

Users will target abc.com VIP in f5 and F5 has got xyz.com and def.com - After F5 picks pool member based on LB method F5 need to replace the http host as xyz.com or def.com before sending to pool members.

 

Can you please help me with Irule .

3 Replies

  • when CLIENT_ACCEPTED {

    if { [IP::addr [LB::server addr] equals $xyz] }{

    set server xyz

    if { [IP::addr [LB::server addr] equals $def] }{

    set server def

    }

    }

     

    when HTTP_REQUEST {

    STREAM::disable

    HTTP::header remove "Accept-Encoding"

    if {$server == xyz} {

    HTTP::header replace "Host" "xyz.com"

    }

    if {$server == def} {

    HTTP::header replace "Host" "def.com"

    }

    }

     

    when HTTP_RESPONSE {

     if { [HTTP::header Location] contains "xyz.com" } { HTTP::header replace Location [string map {"xyz.com" "abc.com"} [HTTP::header Location]] }

     if { [HTTP::header Location] contains "def.com" } { HTTP::header replace Location [string map {"def.com" "abc.com"} [HTTP::header Location]] } 

     if {[HTTP::header value Content-Type] contains "text"}{

       STREAM::expression {@xyz.com@abc.com@@def.com@abc.com@}

       STREAM::enable

     }

    }

     

  • Thank you..Will it still work if backend is https .

     

    Thanks

    Senthil