Forum Discussion
How to preserve data in a HTTP 302 redirect of a POST
Hi,
We are trying to implement the following scenario and would like to know if the LTM can do the following:
- An application execute an HTTP POST request with parameters inside the HTML body
- LTM sends back a 302 redirect request back to the client to another local url
How can LTM sends back in the 302 redirect with the same parameters that were availble in the initial packet (see 1))?
Can LTM look into HTML body and use them in packet 2) with an iRule?
In initial packet 1) these parameters can be a small text or a large file that is being posted to the servers behind LTM
Thanks, Giulio.
- What_Lies_Bene1Cirrostratus
What do the parameters in the body look like?
Hi,
This is the initial packet with the POST DATA
https://dl.dropboxusercontent.com/u/11374616/first%20request.png
and this is the second, after the 302, with empty parameters
https://dl.dropboxusercontent.com/u/11374616/redirect%20without%20parameters.png
- Juerg_WiesmannNimbostratus
Hi 2funky,
I normally step a bit back, and ask, why do we get the redirect ? Wouldn't it make sense, that if the user sends the post to a the wrong URL, that BIG-IP would change the inital Post to point to the right backend URL ?
ie: your post goes to www.test.com/login.php redirect sends you to www.test.com/prod/login.php Browser sends the request to www.test.com/prod/login.php (without Parameters) iRule would need to add it.
What you could do very easy would be to change the inital post www.test.com/login.php to www.test.com/prod/login.php without changing the Parameters. So the Backend System would not need to send a redirect, and could consume the Parameters and Values as needed.
Wiesmann
- RobertColbertNimbostratus
Generally speaking, if you need to do a redirect and keep all post parameters, you will have to create a postback form which then has the client actually post to the new URL.
If the form that generates the POST is flowing through your LTM and you can't get the developers to update the target URL of the form, you may be able to use a stream replacement to change it on the way out of the LTM to the browser before they make the first post.
Hi,
Thanks for the answers. Indeed, we have a redirection iRule in place that we can not really change, as it is linked with GLB in case of servers unavailability.
So, if I get it well, LTM can parse HTML body and push it back the initial POST parameters inside the HTTP302? Do you have an example somewhere? Is it CPU intensive?
- Kevin_StewartEmployee
A 302 response is really nothing more that a simple message with a 302 status code and a Location header. That said, you could very easily send back arbitrary data in the 302 message in the payload or the URI. A browser would generally ignore the payload of a 302 response though, so it may make more sense, if the next server needs this information to either:
-
Convert the POST payload to query string data and include in the Location URL, or
-
Issue a 307 response instead, which will generally cause a browser to re-POST the data to the specified URL. Not all browsers treat a 307 the same way though, so mileage may vary.
-
- Juerg_WiesmannNimbostratus
So, now I think this iRule should do what you require just need to set your redirect URL (including the URI)
- Juerg_WiesmannNimbostratus
when RULE_INIT { set static::ext_url "http://host.header.com/path/login.php" } when HTTP_REQUEST { Check if request was a POST if { [string tolower [HTTP::method]] eq "post" } { Check if there is a Content-Length header if { [HTTP::header exists "Content-Length"] } { if { [HTTP::header "Content-Length"] > 1048000 }{ Content-Length over 1Mb so collect 1Mb set content_length 1048000 } else { Content-Length under 1Mb so collect actual length set content_length [HTTP::header "Content-Length"] } } else { Response did not have Content-Length header, so use default of 1Mb set content_length 1048000 } Don't collect content if Content-Length header value was 0 if { $content_length > 0 } { HTTP::collect $content_length } } } when HTTP_REQUEST_DATA { set content "?" foreach p [split [HTTP::payload] &] { set name [URI::decode [getfield $p = 1]] set value [URI::decode [getfield $p = 2]] set content "${content}$name=$value&" log local0. "Content: $content" } set content "${content}" set where_to "$static::ext_url$content" log local0. "$where_to" } when HTTP_RESPONSE { if { [info exists where_to] } { HTTP::respond 302 Location $where_to } }
- MRaybone_149589Nimbostratus
Hello, I'm trying to use the code supplied by Juerg Wiesmann but am getting the following error:
[parse error: PARSE syntax 357 {syntax error in expression " [HTTP::header "Content-Length"] > 1048000 " : variable references require preceding $}] [{ [HTTP::header "Content-Length"] > 1048000 }]
I have very basic F5 knowledge so this is all new to me. I'm on v11, any help appreciated!
- MRaybone_149589Nimbostratus
Think I sorted it, the copy/paste from web converted the greater than ">" symbol to "
".>
Though whilst the F5 passed the syntax check, the rule broke the webservice 🙂
Recent Discussions
Related Content
* 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