Forum Discussion

DeVon_Jarvis's avatar
DeVon_Jarvis
Icon for Nimbostratus rankNimbostratus
Mar 09, 2009

HTTP::is_redirect error?

I have built this iRule to simulate the "Redirect_Rewrite modify" option.

 

 

when HTTP_REQUEST {

 

Save the host

 

set host [string tolower [HTTP::host]]

 

}

 

when HTTP_RESPONSE {

 

if {[HTTP::is_redirect] and [HTTP::header exists "location"]} {

 

set location [string tolower [HTTP::header "location"]]

 

if { ($location starts_with "http://") and ($location contains $host)} {

 

set newloc "https://[substr [HTTP::header Location] 7]"

 

HTTP::header replace Location $newloc

 

}

 

}

 

}

 

 

Works good in test, but when I put it in production, I am getting this error occasionally.

 

 

Mar 9 12:49:21 tmm tmm[1729]: 01220001:3: TCL error: redirect_to_https_matching - Illegal argument. Can't execute in the current context. (line 1) invoked from within "HTTP::is_redirect"

 

 

Any idea what is going on?
  • BTW: I am on 9.4.6

     

     

    I changed the code to test the HTTP::status for 301, 302, etc, and the error has changed.

     

     

    when HTTP_REQUEST {

     

    Save the host

     

    set host [string tolower [HTTP::host]]

     

    }

     

    when HTTP_RESPONSE {

     

    switch [HTTP::status] {

     

    "301" -

     

    "302" -

     

    "303" -

     

    "305" -

     

    "307" {

     

    set redirect 1

     

    }

     

    default {

     

    set redirect 0

     

    }

     

    }

     

    if {$redirect == 1} {

     

    set location [string tolower [HTTP::header "Location"]]

     

    if { ($location starts_with "http://") and ($location contains $host)} {

     

    HTTP::header replace Location [string map -nocase { "http://" "https://" } [HTTP::header value Location]]

     

    }

     

    }

     

    }

     

     

    Mar 9 14:38:33 tmm tmm[1729]: 01220001:3: TCL error: redirect_to_https_matching - Illegal argument. Can't execute in the current context. (line 1) invoked from within "HTTP::status"
  • I added priority to my iRule, causing it to run first, and the errors seem to have disappeared. Wonder what was happening in the other iRules that was breaking this? Any ideas?

     

     

    The current iRule is:

     

     

    when HTTP_REQUEST priority 100 {

     

    Save the host

     

    set host [string tolower [HTTP::host]]

     

    }

     

    when HTTP_RESPONSE priority 100 {

     

    if {[HTTP::is_redirect]} {

     

    set location [string tolower [HTTP::header "Location"]]

     

    if { ($location starts_with "http://") and ($location contains $host)} {

     

    HTTP::header replace Location [string map -nocase { "http://" "https://" } [HTTP::header value Location]]

     

    }

     

    }

     

    }
  • What is the other iRule doing? Is it redirecting the client in HTTP_RESPONSE?

     

     

    Aaron
  • I have a problem with 9.4.6 and came across this thread, I have noticed this after upgrading to 9.4.6.

     

     

    May 3 19:13:42 tmm tmm[2269]: 01220001:3: TCL error: ir_irule1 - Illegal argument. Can't execute in the current context. (line 39) invoked from within "HTTP::respond 401"

     

     

    Any idea what could be causing this?

     

     

    Thanks
  • Hi smallIP,

     

     

    Can you post the iRule(s) enabled on the virtual server and any debug you have from /var/log/ltm? Does the error occur on every request?

     

     

    Aaron