Forum Discussion
andreoli_4699
Nimbostratus
Jan 13, 2010HTTP::payload replace with MORE data?
Hi all, I have the following code:
when HTTP_REQUEST priority 300 {
set original_payload [HTTP::payload]
set original_length [HTTP::header value Content-Length]
if { [lindex $session_var 7] == 1 and not ( [info exists all_done] ) } {
set original_request [HTTP::request]
HTTP::uri "/lookup.asp?id=[lindex $session_var 6]"
snatpool legacy-connect_snat
pool lookup.pool
event HTTP_REQUEST disable
} elseif { [info exists all_done] and $all_done == 1 } {
lset session_var 7 2
HTTP::header replace SOFTCERT_NUM $authkey
unset all_done
}
}
when HTTP_RESPONSE priority 300 {
if { [lindex $session_var 7] == 1 and not ( [info exists all_done] ) } {
HTTP::collect 1
}
}
when HTTP_RESPONSE_DATA priority 300 {
if { [lindex $session_var 7] == 1 and not ( [info exists all_done] ) } {
set authkey [HTTP::payload]
set all_done 1
event HTTP_REQUEST enable
HTTP::header replace "Content-Length" $original_length
HTTP::payload replace 0 $original_length $original_payload
HTTP::retry $original_request
}
}
(Note that a few things, like session_var, are set by another script)
The purpose of this is to intercept a request, store the payload and length (1665 bytes) to a local variable, then take certificate information, and, by replacing the URI and doing a "pool" statement, go off and look up some data on another server. Upon return, it takes the reply data (10 bytes), stuffs it into another header, then HTTP::payload replace with what was originally gathered at the beginning. It then does a HTTP::retry with the original request.
Everything seems to be working great until I go to replace the payload, then it bombs with a "list index out of range". By playing around, it seems that since my payload went from 1665 bytes down to 10 through the lookup, it won't let me replace the payload with anything more than 10 bytes.
Does anyone have any idea how I can increase the buffer size that's allocated to this new payload so that I can replace it with the original data for my http::retry?
This is my first post, and I've been looking at this until my eyes bled, so be gentle 😉
Thanks!
Tony
- andreoli_4699
Nimbostratus
Thanks Aaron. I tried that, as well as hard coding the number, but it all boils down to the fact that, even though it hasn't changed in size from what was originally grabbed, the buffer has gotten smaller thanks to the "pool" lookup, and the error comes in when I try to replace with anything more than 10 bytes. - hoolio
Cirrostratus
Can you log the [HTTP::payload length] value and try using it?when HTTP_RESPONSE_DATA priority 300 { if { [lindex $session_var 7] == 1 and not ( [info exists all_done] ) } { set authkey [HTTP::payload] set all_done 1 event HTTP_REQUEST enable log local0. "300: \[HTTP::payload length\]: [HTTP::payload length], \[HTTP::payload\]: [HTTP::payload]" HTTP::payload replace 0 [HTTP::payload length] $original_payload HTTP::retry $original_request } }
- andreoli_4699
Nimbostratus
I think that does it. I actually wrapped the payload replace on both sides with your log code, so I can see before and after:log local0. "300: \[HTTP::payload length 1\]: [HTTP::payload length], \[HTTP::payload\]: [HTTP::payload]" HTTP::payload replace 0 [HTTP::payload length] $original_payload log local0. "300: \[HTTP::payload length 2\]: [HTTP::payload length], \[HTTP::payload\]: [HTTP::payload]"
- hoolio
Cirrostratus
Actually... I'm not sure I follow the exact logic you're trying to implement. It's a little tricky to follow without the full rule. But to guess... - andreoli_4699
Nimbostratus
What happens is my original request comes in and contains a payload (a soap envelope). I take some cert info and use that to do a username/password lookup against another database (via the pool statement). That result comes back in the payload (which is why I save the original payload [soap envelope] at the beginning), I then put the username/password into the headers, put the original payload back in, and retry the original request. - andreoli_4699
Nimbostratus
In fact, what I'm doing is very similar to this example: http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__request.html - andreoli_4699
Nimbostratus
The solution ended up being the append you mentioned earlier. Once I appended the original payload back to the original request, everything worked as expected. - hoolio
Cirrostratus
That makes sense. Good to hear you got it working. - andreoli_4699
Nimbostratus
Hi there, me again ;-) I'm hitting another snag, and have been beating my head against the wall on it. - hoolio
Cirrostratus
Hi Tony,
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