Forum Discussion
Lars_Terje_Vaal
Nimbostratus
Oct 31, 2007HTTP::method. Can it be changed?
Hi. I need to change the http method from POST to GET in a request. Is it possible?
6 Replies
- hoolio
Cirrostratus
I don't think you can set the method with HTTP::method. The wiki page only shows that you can retrieve the method--not set it. If you could change the request method, I'm not sure it would be a good idea. You'd have to try to handle any POST data that was sent with the request.
If you send a redirect to the same host and URI, the client should follow the redirect with a GET:when HTTP_REQUEST { if {$some_condition == 1}{ HTTP::redirect http://[HTTP::host][HTTP::uri] } }
Aaron - Patrick_Chang_7Historic F5 AccountYou can do it, but you would have to manually recreate the request in its entirety. This would require parsing the post data and converting them into query parameters in the URI. There is a secret function (not well documented) in the F5 Web Accelerator which will do this for you automatically.
- Lars_Terje_Vaal
Nimbostratus
Interesting, but we do not have the Web Accelerator license.
Do you pchang or anyone else have an example on how to build/recreate the request from the start inside iRules?
One thing is to create the header values and the uri which is easy to change with HTTP::uri and HTTP::header, but how to specify to use GET or POST?
Another thing.
If I receive a POST and wants to resend it with HTTP::retry. How can that be done?
This codewhen HTTP_REQUEST { set orginal_request [HTTP::request] } when HTTP_RESPOND { if {some condition} { HTTP::retry $orginal_request } }
Will only resend the request and not the POST data. If I do a collect, I will receive the POST data, but how can the payload be resent? - hoolio
Cirrostratus
I don't think there is a way to change the method using HTTP:: commands. I suppose you could collect the TCP data and replace the POST string with GET within the TCP payload. I don't think it would be a simple thing to do though.
I'm wondering if it wouldn't be much easier to rewrite the response from the web app that generates the request you want to change from a POST to a GET. If you knew the URI and/or form name which generates the POST request, you could use a stream command to rewrite the form method from POST to GET. This would also eliminate the need to convert POST parameters to the URI.
Aaron - hoolio
Cirrostratus
I would think you could modify the variable you're saving the request to, $orginal_request, before using HTTP::retry $orginal_request.
Aaron - Lars_Terje_Vaal
Nimbostratus
I found the solution now on how to do a HTTP::retry if the request method is POSTwhen HTTP_REQUEST { set orginal_request [HTTP::request] HTTP::collect [HTTP::header "Content-Length"] if {$isRetry} { HTTP::header replace Content-Length "0" HTTP::payload replace 0 0 $payloadReq set isRetry 0 } } when HTTP_REQUEST_DATA { set payloadReq [HTTP::payload] } when HTTP_RESPOND { if {some condition} { HTTP::retry $orginal_request set isRetry 1 } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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