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...
Kevin_Stewart
Oct 01, 2013Employee
The trick is that you have to do this in the TCP events (CLIENT_ACCEPTED and CLIENT_DATA) as the HTTP::method command is read-only. Here is a somewhat simple example of how this looks:
when CLIENT_ACCEPTED {
TCP::collect
}
when CLIENT_DATA {
separate uri and query string
set uri [findstr [TCP::payload] "GET " 4 " HTTP/1."]
set uri_no_query [findstr $uri "" 0 "?"]
set query [findstr $uri "?" 1]
replace TCP payload
regsub -all -nocase "GET" [TCP::payload] "POST" newdata
set newdata1 [string map "$uri $uri_no_query" $newdata]
regsub -all -nocase "Accept: " $newdata1 "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: [string length $query]\r\nAccept: " newdata2
TCP::payload replace 0 [TCP::payload length] ${newdata2}$query
TCP::release
}
I first separate the URI from the query string, then perform a series of replace functions to 1) change GET to POST, change the original URI to the URI without query string, and 3) inserts the Content-Type and Content-Length headers before the Accept.
This is just an example, so it doesn't account for the following conditions:
- Whether or not the request is originally a GET or POST
- Whether or not Content-Type and Content-Length headers are already present
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