trying to set a response header based on the referer

irule newby trying to set a response header based on the referer but getting the error below.

when HTTP_REQUEST { set referer_host [URI::host [HTTP::header value Referer]]

when HTTP_RESPONSE {

if {( $referer_host ne “” ) and ( $referer_host contains “lbl.gov” )} then {

HTTP::header insert X-Frame-Options “ALLOW-FROM $referer_host” } else { HTTP::header insert X-Frame-Options “SAMEORIGIN” } } }

error: [command is not valid in the current scope][when HTTP_RESPONSE { if {( $referer_host ne “” ) and ( $referer_host contains “lbl.gov” )} then { HTTP::header insert X-Frame-Options “ALLOW-FROM $referer_host” } else { HTTP::header insert X-Frame-Options “SAMEORIGIN” } }]

ne and then are not valid TCL commands. Also, there’s no need to check if the variable is an empty string if you are looking for an explicit string. Give this a try:

when HTTP_REQUEST {
    set referer_host [URI::host [HTTP::header value Referer]]
}

when HTTP_RESPONSE {
    if {$referer_host contains "lbl.gov"}{
        HTTP::header insert X-Frame-Options "ALLOW-FROM $referer_host"
    }
    else {
        HTTP::header insert X-Frame-Options "SAMEORIGIN"
    }
}

ne and then are not valid TCL commands. Also, there’s no need to check if the variable is an empty string if you are looking for an explicit string. Give this a try:

when HTTP_REQUEST {
    set referer_host [URI::host [HTTP::header value Referer]]
}

when HTTP_RESPONSE {
    if {$referer_host contains "lbl.gov"}{
        HTTP::header insert X-Frame-Options "ALLOW-FROM $referer_host"
    }
    else {
        HTTP::header insert X-Frame-Options "SAMEORIGIN"
    }
}

thanks much

thanks much