For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

milanv_137346's avatar
milanv_137346
Icon for Nimbostratus rankNimbostratus
Nov 20, 2013

Set Host header

Hi,

I'm a newbie to this. Can someone help me correct the iRule below? We need the first value in the X-Forwarded-Host to be assigned to the Host header regards, Milan

when HTTP_REQUEST {

if {[HTTP::header exists X-Forwarded-Host] && llength [HTTP::header X-Forwarded-Host] > 1}{ 
    HTTP::header replace Host [string trimleft [lindex [split [HTTP::header X-Forwarded-Host] ","] 0] /{] 
} 
elseif {[HTTP::header exists X-Forwarded-Host]}
{
    HTTP::header replace Host [HTTP::header X-Forwarded-Host]
}

}

1 Reply

  • Try this:

    when HTTP_REQUEST {
        if { [HTTP::header exists X-Forwarded-Host] } {
            HTTP::header replace X-Forwarded-Host [string trim [lindex [split [HTTP::header X-Forwarded-Host] ","] 0]]
        }
    }
    

    If the header exists, there's a pretty good bet that it'll have at last one value. If the header has two values delimited with a comma, the above will take the first one. If the header only contains one value, then the split function will produce a list of one, which will still be at the 0 index.