Forum Discussion
greg_chew_11034
Nimbostratus
Sep 01, 2005http::redirect and http::close and not closing the session.
Hey all.
I am trying to do a redirect to www.foo.com/test.
HTTP/1.0 302 Found
Location: http://www.foo.com/browse/home.html
Server: BIG-IP
Connection: Keep-Alive
Content-Type: text/html
Content-Length: 0
This redirect works fine, but in the same browser, if you do a www.foo.com/gohere, i get in my host header
GET /gohere HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Host: www.food.com
Connection: Keep-Alive
it seems that it's bypassing the f5 altogether and my irule set and tries to look for a directory called /gohere.
thoughts?
i have tried using HTTP::close before and after my redirect to no avail.
12 Replies
- greg_chew_11034
Nimbostratus
rule foo_uris_rule_v2 { when HTTP_REQUEST { set host [string tolower [getfield [HTTP::host] ":" 1]] set uri [string tolower [HTTP::uri]] set matchstring [substr [substr $uri 1 "?"] 0 "/" ] if { $matchstring == "" } { set matchstring $host$uri } else { set matchstring $host/$matchstring } set redstring [findclass $matchstring $::foo_uris_list " " ] set query_src [findstr [HTTP::uri] "?src=" 5 "&" ] if {$query_src == ""} { set query_src [findstr [HTTP::uri] "&src=" 5 "&" ] } log local0. "query_src = $query_src" set query_trk_src [findstr [HTTP::uri] "trk_src=" 8 " " ] log local0. "query_trk_src = $query_trk_src" if { $query_src != "" } { set redstring $redstring&src=$query_src } if { $query_trk_src != "" } { set redstring $redstring&trk_src=$query_trk_src } if {$redstring eq ""} { if { $host != "www.foo.com" and $host != "foo.com"} { set element [findclass "foo.com/" $::foo_uris_list " " ] log local0. "Defaulting subdomain to foo.com" } } if {$redstring != ""} { log local0. "redirecting to $redstring" HTTP::close HTTP::redirect $redstring HTTP::close event disable all } } } - unRuleY_95363Historic F5 AccountOk, I think I know what the problem is... The logical expression operators have very high precendence, and as a result have confused many, many people. In your host check:
It's very likely that the "and" is getting done differently than you expect. I will add some parenthesis to show you the way it is likely being interpreted:if { $host != "www.foo.com" and $host != "foo.com" }
As you can see, this would definitely produce a weird and unexpected outcome.if { ($host != ("www.foo.com" and $host)) != "foo.com" }
So, try adding some parenthesis like so:
and see if that doesn't help straighten out the problem.if { ($host != "www.foo.com") and ($host != "foo.com") } - greg_chew_11034
Nimbostratus
When HTTP::close is before the HTTP::redirect,
i am getting a Sep 1 15:37:14 tmm tmm[15966]: 011f0006:3: http_process_state_parse_header - Invalid state transition to ST_HTTP_SHUTDOWN - unRuleY_95363Historic F5 AccountAlso, I really don't think you should need to do the "event disable all" since this connection should really be closing. If for some reason, the connection is not being closed, no rule events will be triggered. Instead of doing an "event disable all", maybe you should do something like set a variable that says you are done. Something like this:
when CLIENT_ACCEPTED { set http_closed 0 } when HTTP_REQUEST { if { $http_closed } { log "Hey, this connection should be closed!" reject } ... if { ... } { HTTP::redirect http://www.foo.bar.com/newuri set http_closed 1 } } - unRuleY_95363Historic F5 AccountYou really shouldn't need the HTTP::close with the HTTP::redirect as that is supposed to be the behavior of the redirect.
- greg_chew_11034
Nimbostratus
when the HTTP::close is in the irule, i get this in the ltm log.
Sep 1 13:58:49 tmm tmm[15966]: 011f0006:3: http_process_state_parse_header - Invalid state transition to ST_HTTP_SHUTDOWN
If i remove it, it goes away. also, this problem is more prevalent consistantly when you redirect to www.foo.com/feedback > external site (not www.foo.com) and then you try to go www.foo.com/gohere. i get the
GET /gohereHTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Host: www.foo.com
Connection: Keep-Alive
Cookie: unknownShopperId=2F989769E271BEDE431A9773C78F6DA7|||
HTTP/1.1 404 Not Found
Date: Thu, 01 Sep 2005 17:56:01 GMT
Server: Apache/2.0.46 (Red Hat)
Content-Length: 295
Connection: close
Content-Type: text/html; charset=iso-8859-1 - unRuleY_95363Historic F5 AccountIn looking closer at your rule, the problem may very well be that a redirect is not happening when you expect it. I would suggest adding a bunch of log statements to help debug the logic and control flow of your rule. (For example, if $redstring == "" you set element and then never redirect - this is the path that the www.foo.com/gohere url would take, so it's not surprising that it gets load-balanced to a server in the pool that then doesn't know about it).
- greg_chew_11034
Nimbostratus
i checked the code and i am just defining $redirect, but there's only one http::redirect at the end, and the $redstring is what's being redirected. it's just that in real life, i try this scenario
www.foo.com > 302 redirect to www.foo.com/home.html
(in same browser)
www.foo.com/gohere > 404 /gohere not found.
open new browser
www.foo.com/gohere > 302 redirect to www.foo.com/go_goes_here.html - unRuleY_95363Historic F5 AccountDid you ever take the "event disable all" out and verify that in fact the browser was reusing the same connection after the redirect? I'm not sure what your rationale is behind disabling all future rule event processing after the redirect. If the browser determines that it later has a request to the same ip address as a connection it already has open, then why does it need to use a new connection? As long as it redirects the next request also... ???
- greg_chew_11034
Nimbostratus
i did try taking the event disable all out of the config and it broke some of the logic.
(in new browser/new session)
www.foo.com/gohere/?src=test > 302 redirect to www.foo.com/go_to_here.html?src=test
but then would loop and keep trying to 302 to ?src=test (another bug to be fixed, but a non issue if event disable all is there.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
