Forum Discussion
iRule for parsing the body / payload of a post request and adding an extra block of content to the originally received body
There's a couple of ways you can do this, if the POST is JSON like you say, the easiest way (in my opinion) is to use iRules LX. iRules LX is essentially Node.js which is server side JavaScript.
I wrote a code share article on reading in JSON body and modifying the values of some of the keys. You can take a similar approach to add new key pair values
https://devcentral.f5.com/s/articles/simple-iruleslx-json-rewrite-1196
The alternative, is to read in the body as before and look for unique bit of code, then using ```string map``` to replace replace this code with the bit you were looking for + the new inserted bit.
Also remember to rewrite your Content-Length header.
Hopefully this will be enough to get you going:
set payload [HTTP::payload]
set find "\"key1\": \"value1\""
set insert "$find, \"key2\": \"value2\""
set newPayload [string map [list "$find" "$inset"] $payload ]
HTTP::payload replace 0 [HTTP::header "Content-Length"] $newPayload
Good Luck!
Lee
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
