Forum Discussion
boneyard
Oct 01, 2013MVP
iRule to change HTTP GET into POST
i have an incoming GET request on my virtual server which i want to change into a POST request towards the node. in princple this would mean:
change the word GET into POST change the uri to re...
IheartF5_45022
Sep 21, 2015Nacreous
Hi I have managed to do this without using TCP::collect. I have borrowed the idea from this post https://devcentral.f5.com/codeshare/http-method-conversion, but without the need to use 2 separate virtual servers.
The following iRule will convert a GET request with query parameters into a POST to the same path, but placing the query parameters in the request body instead of the request line.
Be careful....you could exhaust all your connections on the box if you tinker with it and get it wrong 🙂
when HTTP_REQUEST {
set pool [LB::server pool]
set method [HTTP::method]
if {[HTTP::uri] eq "/reentrant"} {
HTTP::respond 200
return
} elseif {[HTTP::method] eq "GET"} {
Create POST
set post "POST [HTTP::path] HTTP/1.1\r\nHost: [HTTP::host]\r\nContent-Type: text/plain\r\nContent-Length: [string length [URI::query [HTTP::uri]]]\r\n\r\n[URI::query [HTTP::uri]]"
Change the uri so that when this event is fired again we know to return a 200
HTTP::uri "/reentrant"
Invoke this iRule again re-entrantly
virtual [virtual]
}
}
when HTTP_RESPONSE {
If the clientside request was a GET, retry as a POST
if {$method eq "GET"} {
pool $pool
HTTP::retry $post
return
}
}
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