Forum Discussion

Jamey_Price_105's avatar
Jamey_Price_105
Icon for Nimbostratus rankNimbostratus
Jan 31, 2005

HTTP::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
  • 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.

     

     

    when HTTP_RESPONSE_DATA {

     

    set nummatches [regexp -nocase "oursite" [HTTP::payload]]

     

    if { $nummatches }{

     

    regsub "oursite.ourdomain.com" [HTTP::payload] "oursitedev.ourdomain.com" fixeddata

     

    log "Replacing payload $nummatches times."

     

    HTTP::payload replace 0 $clen $fixeddata

     

    } else {

     

    log "No payload will be replaced."

     

    }

     

    HTTP::release

     

    }

     

     

    I tried escaping the periods in case they were being interpreted to match any character (which shouldn't matter regardless, but I'm grasping at straws here), and then I shortened what I'm searching for in the regexp to just the oursite bit of the full oursite.ourdomain.com to see if it's even matching, and it does not appear that that is matching at all.

     

     

    I believe we are compressing the response data on the server, do I need to disable that, or decompress it somehow, before I do anything with it in an iRule? All my logs have to say about this is "No payload will be replaced."

     

     

    Thanks again, this has been a great help. I'm getting there, but I've just not quite made it yet.

     

     

    Jamey
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    What are you getting for [HTTP::payload length]?

     

     

    Also, what version are you running?
  • Sometimes [HTTP::payload] length is null, sometimes it explicitly prints zero, and sometimes it 2-9k.

     

     

    We're running 9.03.

     

     

    Jamey