Forum Discussion

johnie_44525's avatar
johnie_44525
Icon for Nimbostratus rankNimbostratus
Oct 07, 2011

how to mantain iRule HTTP::query case sensitivity

I am trying to resolve a case sensitivity issue with my iRule.

 

 

currently, the iRule parses a URL and forwards the URI to the matching site.

 

 

here the problem:

 

 

- if the parsed URL has mixed upper and lower case, the forwarding URI is only low case.

 

 

How can I change the irule to mantain case sensitivity? I see that the "HTTP_REQUEST" uses a [string tolower [HTTP::query]]. should I just remove the "tolower" value?

 

 

Any Help would be great!!!

 

 

when HTTP_REQUEST {

 

if {$static::debug}{log -noname *.*.*.* local0.info ""}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Entering HTTP REQUEST"}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Raw Request: [HTTP::request]"}

 

set rawquery [string tolower [HTTP::query]]

 

if { $rawquery starts_with "https"}{

 

set host [findstr $rawquery "https://" 8 "/"]

 

if {$static::debug}{log -noname *.*.*.* local0.info "Value of SSL Host: $host"}

 

} else {

 

set host [findstr $rawquery "http://" 7 "/"]

 

if {$static::debug}{log -noname *.*.*.* local0.info "Value of Host: $host"}

 

}

 

if {[class match $host starts_with exempted]}{

 

if {$static::debug}{log -noname *.*.*.* local0.info "Matched List of Exempted"}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Raw Query: $rawquery Host: $host"}

 

HTTP::respond 200

 

event disable all

 

return

 

 

}

 

if {[HTTP::uri] equals "/?"}{

 

log -noname *.*.*.* local0.info "HTTP URI only contained: [HTTP::uri]"

 

HTTP::respond 200

 

event disable all

 

return

 

}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Raw Query: $rawquery Host: $host"}

 

set rawhostip [RESOLV::lookup @*.*.*.* $host]

 

set hostip [getfield $rawhostip " " 1]

 

if {$static::debug}{log -noname *.*.*.* local0.info "RawHost IP: $rawhostip"}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Host IP: $hostip"}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Host IP: $hostip"}

 

if { $rawquery starts_with "https"}{

 

set port 443

 

set hostlen [expr [string length $host] + 8]

 

set hostremoved [findstr $rawquery "https://" $hostlen]

 

if {$static::debug}{log -noname *.*.*.* local0.info "Value of SSL port: $port hostlen: $hostlen hostremoved: $hostremoved"}

 

} else {

 

set port 80

 

set hostlen [expr [string length $host] + 7]

 

set hostremoved [findstr $rawquery "http://" $hostlen]

 

if {$static::debug}{log -noname *.*.*.* local0.info "Value of SSL port: $port hostlen: $hostlen hostremoved: $hostremoved"}

 

}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Host Len: $hostlen Host Removed: $hostremoved"}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Host Len: $hostlen Host Removed: $hostremoved"}

 

if { $hostremoved ne "" }{

 

if {$static::debug}{log -noname *.*.*.* local0.info "hostremoved not empty. Changing URI to: $hostremoved"}

 

HTTP::uri $hostremoved

 

} else {

 

if {$static::debug}{log -noname *.*.*.* local0.info "hostremoved empty. Changing URI to /"}

 

HTTP::uri "/"

 

}

 

if {$static::debug}{log -noname *.*.*.* local0.info "Changing Host Header to: $host"}

 

HTTP::header replace "Host" $host

 

if { $hostip ne "" }{

 

if {$static::debug}{log -noname *.*.*.* local0.info "hostip isn't empty. Sending traffic to: $hostip:$port"}

 

node $hostip $port

 

log -noname *.*.*.* local0.info "Request to $rawquery sent to $host at IP $hostip"

 

}

 

}

 

1 Reply

  • It's the line "HTTP::uri $hostremoved" that's rewriting the URI to your lowercase version.

     

     

    With that said, I'm a little confused on your iRule. You are setting rawquery to the QueryString portion of the URI (ie. /foo/bar?querystring -> querystring).

     

     

    You are then mainuplating that and then resetting the URI of the request to the manipulated querystring and omitting the previous "path" portion of the URI. I guess I'd have to understand how the app was working, but thought I'd point that out.

     

     

    For the answer to your question, if you wish to maintain case, you'll have to do something with that original string tolower but then you'll have to have all possible cases in the data group you are matching on. If you do need support mixed case in your lookup parameters, you'll likely have to lowercase the string, find where the match is in the string, and then replace that range of characters in the original URI.

     

     

    -Joe