Forum Discussion
iRule: How to grab the Line-base text data and replace with desired value...
Stream content:
POST /provision HTTP/1.1
Content-Length: 56 Content-Type: text/plain; charset=ISO-8859-1 Host: w.x.y.z:abc Connection: Keep-Alive
{"imei":"355031040811111"}HTTP/1.1 100 Continue <==== Line-based data: text/plain
HTTP/1.1 200 OK Cache-Control: private Expires: Thu, 21 Mar 2013 14:23:07 UTC Content-Type: text/json
I am not able to see the imei using HTTP::request printed on the ltm log.
Once I get the imei, I would like to insert a particular value on a header based on that.
Example:
imei = x, then insert header p = r, then re-POST
Thanks in advance!
2 Replies
- Kevin_Stewart
Employee
This question is a bit like the following:
https://devcentral.f5.com/questions/how-to-check-if-response-contains-a-specific-string-using-irules
And perhaps this modified iRule would do the trick:
when HTTP_REQUEST { if { [HTTP::method] equal "POST" } { catch { HTTP::collect [HTTP::header Content-Length] } } } when HTTP_REQUEST_DATA { if { [HTTP::payload] contains "emei" } { HTTP::header insert P "R" } }Without more specifics, the above very simply inserts a header into the ingress request (to the server) based on a POST request containing "emei". Not sure if the header has to be based on the value of the emei data, but you could easily parse that out if needed. The HTTP::request command will only return the raw HTTP headers, so you'd never see the payload of a POST using that. To get to the payload (reliably), you need to collect and buffer the data using the HTTP::collect command and subsequent HTTP_REQUEST_DATA event.
- danra_139044
Altostratus
Kevin, It works! Thank you. --snip-- when HTTP_REQUEST { if { [HTTP::method] equals "POST" && [HTTP::path] contains "/provision" }{ HTTP::collect [HTTP::header Content-Length] } } when HTTP_REQUEST_DATA { if { [HTTP::payload] contains "imei_value" } { HTTP::header replace P "R" pool destination } } } --endofsnip--
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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