Forum Discussion

Joseph_Lindsly's avatar
Sep 05, 2018

HTTP::header replace error

Hello,

I currently have an irule applied to a Virtual Server and recently noticed some error messages in the logs. I am not sure when it actually started but it has been consistent for the past 30 days. We upgraded our LTM from version 11.5.2 to 12.1.3.4 a few months ago so, I am not sure if the errors started after the upgrade or not.

Here is the error message:

 - Operation not supported (line 1)     invoked from within "HTTP::header replace Host $rewrite_host"

Here is the current irule:

when RULE_INIT {
   Set to 1 to enable logging, 0 to disable
  set static::debug 0
   Set to Site URL
  set static::vs_host_abc_prod "www.abc.com"
}

when CLIENT_ACCEPTED {
   Store the default pool name 
  set default_pool [LB::server pool]
}

when HTTP_REQUEST {
  set uri_lower [string tolower [HTTP::uri]]
  if { [class match $uri_lower starts_with folder_check] } {
    if { [string first "/" [string range $uri_lower [expr {[string first "/" [string range $uri_lower 2 end]] + 3}] end]] > 0 } {
      set str_end [expr {[string first "/" [string range $uri_lower [expr {[string first "/" [string range $uri_lower 2 end]] + 3}] end]] + 6}]
    } else {
      set str_end "end"
    }
  } else {
    if { [string first "/" [string range $uri_lower 2 end]] > 0 } {
      set str_end [expr {[string first "/" [string range $uri_lower 2 end]] + 1}]
    } else {
      set str_end "end"
    }
  }
  set folder [string range $uri_lower 1 $str_end]
  if { $static::debug > 0 } { log local0. "URI: [HTTP::uri] - Found folder $folder" }
  if { [class match -- $folder equals rewrite_folders] } {
    set url_rewrite 1
    set rewrite_host [class match -value $folder equals rewrite_folders ]
    HTTP::header replace Host $rewrite_host
    if { $static::debug > 0 } { log local0. "client [IP::client_addr]:[TCP::client_port] server [IP::remote_addr]:[TCP::release] host [HTTP::host]" }
    if { $static::debug > 0 } { log local0. "URI: [HTTP::uri]" }
    set dest [lindex [RESOLV::lookup @208.67.222.222 -a [HTTP::host]] 0]
    if { $dest ne "https://$rewrite_host" } {
         SSL::enable clientside
      if { $static::debug > 0 } { log local0. "Destination IP is $dest" }
      node $dest
    }
  } else {
    set url_rewrite 0
    if { $static::debug > 0 } { log local0. "-->[HTTP::uri] $default_pool" }
    pool $default_pool
  }
}

when HTTP_RESPONSE {
     if { $url_rewrite > 0 } {
     if {[HTTP::header exists Location]} {
    set protocol [string range [HTTP::header Location] 0 [string first ":" [HTTP::header Location]]]
    set locationrewrite "$protocol//$static::vs_host_abc_prod[string range [HTTP::header Location] [expr {[string first "/" [string range [HTTP::header Location] 9 end]] + 9}] end]"
    if { $static::debug > 0 } { log local0. "HTTP Location Before: [HTTP::header Location]" }
    if { $static::debug > 0 } { log local0. "Updated Version: $locationrewrite" }
    HTTP::header replace Location $locationrewrite
  } 

  STREAM::expression "@$rewrite_host@$static::vs_host_abc_prod@"
  STREAM::enable
}
}

Any suggestions would be greatly appreciated.

Thanks.

  • Any chance there is another iRule assigned to the VS that is doing a redirect or respond before this rule runs?

     

  • Yes. There are a few irules.

    irule 1

    when HTTP_REQUEST { 
           if { ([string tolower [HTTP::host]] starts_with "abc") } {
                    HTTP::respond 301 Location https://www.[HTTP::host][HTTP::uri]
                    }
    }
    

    irule 2

    when HTTP_REQUEST { 
           if { ([string tolower [HTTP::host]] starts_with "abccatseguin.com ") } {
                    HTTP::respond 301 Location  https://www.abc.com
                    }
    }
    

    irule 3

    when HTTP_REQUEST {
        set the URL here, log it on the response
       set url [HTTP::header Host][HTTP::uri]
       set vip [IP::local_addr]:[TCP::local_port]
       set hsl [HSL::open -proto UDP -pool splunk]
    }
    
    when HTTP_RESPONSE {
       set client [IP::client_addr]:[TCP::client_port]
       set snat [IP::local_addr]
       set node [IP::server_addr]:[TCP::server_port]
       set nodeResp [HTTP::status]
       set hsl [HSL::open -proto UDP -pool splunk]
    
        log connection info
       HSL::send $hsl "Client: $client -> SNAT: $snat -> VIP: $vip -> URL: $url -> Node: $node with response $nodeResp"
    }
    

    Thanks

  • You're attempting to rewrite the HTTP Host header using a dynamic method to determine the appropriate string range and then a datagroup look up.

    set rewrite_host [class match -value $folder equals rewrite_folders ]

    I would first check datagroup 'rewrite_folders' to make sure your datagroup has a corresponding value entry for $folder. This will be in the 'data' portion of the datagroup.

    Also check if there are any other iRule issuing a redirect, you may want to consider using priority for irule execution order.