Forum Discussion
Jamey_Price_105
Nimbostratus
Jan 31, 2005HTTP::payload replacing content
I'm basing this rule off a thread I found at http://devcentral.f5.com/default.aspx?tabid=28&view=topic&forumid=5&postid=1521
Basically, we have chunks of our site running on multiple servers, and I need to inspect the request and send it off to different pools based on the URL requested. However, those seperate internal servers don't know anything about being behind a reverse-proxy, so any links they send off will likely still refer to themselves.
So, to test my ability to rewrite the page as needed, there are chunks of our dev site that point at our production site for things like images, or parts of the site that just don't have a dev portion, and I'd like to rewrite those from pointing at oursite.ourdomain.com to oursitedev.ourdomain.com. The only modifications I made are to the text being searched for and replaced with, and the fact that I'm replacing a short string with a longer one, so I THINK I have to increment by -3, the difference in length. Or should I use 24, the length of the longer string?
Also, I tried doing this with a regsub, and that didn't seem to work either. It logs that it is replacing data, but still the page source contains oursite.ourdomain.com.
What am I doing wrong?
when HTTP_RESPONSE {
set clen [HTTP::header Content-Length]
if { $clen > 0 } {
log "Collecting $clen of data."
HTTP::collect $clen
} else {
log "Content-Length is [HTTP::header Content-Length] will be collected."
HTTP::collect 99999999
}
}
when HTTP_RESPONSE_DATA {
regsub "oursite.ourdomain.com" [HTTP::payload] "oursitedev.ourdomain.com" fixeddata
log "Replacing payload with fixed data."
HTTP::payload replace 0 [HTTP::payload $clen] $fixeddata
HTTP::release
}
when HTTP_RESPONSE_DATA {
set last [string last "oursite.ourdomain.com" [HTTP::payload $clen]]
for {set found 0} {$found < $last} {incr found -3}{
set found [string first "oursitedev.ourdomain.com" [HTTP::payload $clen] $found]
HTTP::payload replace $found 21 "oursitedev.ourdomain.com"
}
}
Oh, and I tried using a stream profile, and that didn't work. But even if it did, we are almost certain to need to replace more than one string per site, and being able to set only one replacement would be bad.
Thanks very much,
Jamey
- Jamey_Price_105
Nimbostratus
So far, it's not quite working still. I've been screwing with it, adding some more checking and logging to see where it's blowing up, and this is where I'm at now. - unRuleY_95363Historic F5 AccountWhat are you getting for [HTTP::payload length]?
- Jamey_Price_105
Nimbostratus
Sometimes [HTTP::payload] length is null, sometimes it explicitly prints zero, and sometimes it 2-9k.
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