Forum Discussion
Jamey_Price_105
Nimbostratus
Jan 25, 2005Problem rewriting header attribute on HTTP code 302
I'm new to TCL as of yesterday, so if I'm doing something monumentally dumb, please pardon me.
Our application runs on a server on port 9080, clients access it via port 80 or 443. When the server needs to issue a 302 Found to instruct the client to go elsewhere (say to log in first) it throws in the port that the internal server is running on. We need to strip that out and return the rest to the client. My rule is below, and something is just not right. The string does not seem to be stored in variable result. Any time I try to reference it in any way I can come up with that I ought, I get the string "result" instead.
when HTTP_RESPONSE {
if { [HTTP::header Location] starts_with "http://dev.oursite.com:9080" } {
variable result
regsub :9080 [HTTP::header Location] {} result
log {Result is [set result] or $result or [result]}
[HTTP::redirect ${result}]
[HTTP::redirect [regsub :9080 [HTTP::header Location] {}]]
}
}
Also, there seems to be some difference between TCL regsub as implemented on the Big-IP and in the official documentation. According to the official documentation, the variable is optional, and if excluded the modified string will be returned. If I try that (such as in the last, commented-out line) I get an error stating that I have the wrong number of arguments for regsub.
Please, can someone help me out here?
Thanks,
Jamey
- Jamey_Price_105
Nimbostratus
Replying to my own post here... - unRuleY_95363Historic F5 AccountA couple of notes pertaining to our Tcl implementation.
when HTTP_RESPONSE { if { [HTTP::header Location] starts_with "http://dev.oursite.com:9080" } { regexp .+:9080/(.*) [HTTP::header Location] garbage whatiwant set thingy "http://dev.oursite.com/$whatiwant" log "Thingy is $thingy" HTTP::header replace Location $thingy } }
- rapmaster_c_127Historic F5 AccountOne thing I'll add to unruley's well-written response is that you may want to condition your check on the server's response actually being a 302. Otherwise you'll be needlessly scanning non-redirects for Location: headers.
- unRuleY_95363Historic F5 AccountOh, sorry, I confused myself regarding regexp and regsub.
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