Forum Discussion
Rewrite JSON value.
- Aug 30, 2020
when HTTP_REQUEST { log local0. "starting collect" HTTP::collect [HTTP::header Content-Length] set clen [HTTP::header Content-Length] } when HTTP_REQUEST_DATA { binary scan [HTTP::payload] c* throwaway set incoming [HTTP::payload] log local0. "before: $incoming" regsub -all {, "formName} $incoming {, {"deviceName":"ESSApp"}, } newdata log local0. "new data is $newdata" HTTP::payload replace 0 $clen $newdata log local0. "after: [HTTP::payload]" }$ curl -kv https://172.16.0.220/xxx/formservice -d '{"token":"044VZAliLSXEo2l4Xcv9DFPNLQKbX7p8E3i/Zt+ksskQ+E=MDE5MDA2MjgwOTQzNzQwNjUwMjI4NzM5OUVTU0FwcDE1OTgzNDA4NzQ3NDM=",", "formName": "P59MBLVR_W59MBLVRE", "returnControlIDs":"39|31|37" }' -H 'Content-Type: application/json; charset=utf-8' Aug 30 16:07:03 bigip1 info tmm[12235]: Rule /Common/json_modify <HTTP_REQUEST>: starting collect Aug 30 16:07:03 bigip1 info tmm[12235]: Rule /Common/json_modify <HTTP_REQUEST_DATA>: before: {"token":"044VZAliLSXEo2l4Xcv9DFPNLQKbX7p8E3i/Zt+ksskQ+E=MDE5MDA2MjgwOTQzNzQwNjUwMjI4NzM5OUVTU0FwcDE1OTgzNDA4NzQ3NDM=",", "formName": "P59MBLVR_W59MBLVRE", "returnControlIDs":"39|31|37" } Aug 30 16:07:03 bigip1 info tmm[12235]: Rule /Common/json_modify <HTTP_REQUEST_DATA>: new data is {"token":"044VZAliLSXEo2l4Xcv9DFPNLQKbX7p8E3i/Zt+ksskQ+E=MDE5MDA2MjgwOTQzNzQwNjUwMjI4NzM5OUVTU0FwcDE1OTgzNDA4NzQ3NDM=",", {"deviceName":"ESSApp"}, ": "P59MBLVR_W59MBLVRE", "returnControlIDs":"39|31|37" } Aug 30 16:07:03 bigip1 info tmm[12235]: Rule /Common/json_modify <HTTP_REQUEST_DATA>: after: {"token":"044VZAliLSXEo2l4Xcv9DFPNLQKbX7p8E3i/Zt+ksskQ+E=MDE5MDA2MjgwOTQzNzQwNjUwMjI4NzM5OUVTU0FwcDE1OTgzNDA4NzQ3NDM=",", {"deviceName":"ESSApp"}, ": "P59MBLVR_W59MBLVRE", "returnControlIDs":"39|31|37" }
This should be done from f5 side to the server.
when HTTP_REQUEST {
log local0. "starting collect"
HTTP::collect [HTTP::header Content-Length]
set clen [HTTP::header Content-Length]
}
when HTTP_REQUEST_DATA {
binary scan [HTTP::payload] c* throwaway
set incoming [HTTP::payload]
log local0. "before: $incoming"
regsub -all {, "formName} $incoming {, {"deviceName":"ESSApp"}, } newdata
log local0. "new data is $newdata"
HTTP::payload replace 0 $clen $newdata
log local0. "after: [HTTP::payload]"
}$ curl -kv https://172.16.0.220/xxx/formservice -d '{"token":"044VZAliLSXEo2l4Xcv9DFPNLQKbX7p8E3i/Zt+ksskQ+E=MDE5MDA2MjgwOTQzNzQwNjUwMjI4NzM5OUVTU0FwcDE1OTgzNDA4NzQ3NDM=",", "formName": "P59MBLVR_W59MBLVRE", "returnControlIDs":"39|31|37" }' -H 'Content-Type: application/json; charset=utf-8'
Aug 30 16:07:03 bigip1 info tmm[12235]: Rule /Common/json_modify <HTTP_REQUEST>: starting collect
Aug 30 16:07:03 bigip1 info tmm[12235]: Rule /Common/json_modify <HTTP_REQUEST_DATA>: before: {"token":"044VZAliLSXEo2l4Xcv9DFPNLQKbX7p8E3i/Zt+ksskQ+E=MDE5MDA2MjgwOTQzNzQwNjUwMjI4NzM5OUVTU0FwcDE1OTgzNDA4NzQ3NDM=",", "formName": "P59MBLVR_W59MBLVRE", "returnControlIDs":"39|31|37" }
Aug 30 16:07:03 bigip1 info tmm[12235]: Rule /Common/json_modify <HTTP_REQUEST_DATA>: new data is {"token":"044VZAliLSXEo2l4Xcv9DFPNLQKbX7p8E3i/Zt+ksskQ+E=MDE5MDA2MjgwOTQzNzQwNjUwMjI4NzM5OUVTU0FwcDE1OTgzNDA4NzQ3NDM=",", {"deviceName":"ESSApp"}, ": "P59MBLVR_W59MBLVRE", "returnControlIDs":"39|31|37" }
Aug 30 16:07:03 bigip1 info tmm[12235]: Rule /Common/json_modify <HTTP_REQUEST_DATA>: after: {"token":"044VZAliLSXEo2l4Xcv9DFPNLQKbX7p8E3i/Zt+ksskQ+E=MDE5MDA2MjgwOTQzNzQwNjUwMjI4NzM5OUVTU0FwcDE1OTgzNDA4NzQ3NDM=",", {"deviceName":"ESSApp"}, ": "P59MBLVR_W59MBLVRE", "returnControlIDs":"39|31|37" }- MuhannadSep 01, 2020
Cirrus
Dear Simon,
Thanks for your help.
It is working perfectly except one issue, it is inserting the "deviceName":"ESSApp" in every request thus it is causing issues to other requests, it seems we need to match exactly the "formName": "P59MBLVR_W59MBLVRE" toinsert the {"deviceName":"ESSApp"}
Regards,
Muhannad
- MuhannadSep 01, 2020
Cirrus
How can i matach the "formName": "P59MBLVR_W59MBLVRE" in this IRULE:
when HTTP_REQUEST {
log local0. "starting collect"
HTTP::collect [HTTP::header Content-Length]
set clen [HTTP::header Content-Length]
when HTTP_REQUEST_DATA {
binary scan [HTTP::payload] c* throwaway
set incoming [HTTP::payload]
log local0. "before: $incoming"
regsub -all {, "formName} $incoming {, {"deviceName":"ESSApp"}, } newdata
log local0. "new data is $newdata"
HTTP::payload replace 0 $clen $newdata
log local0. "after: [HTTP::payload]"
}
Regards,
Muhannad
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
