Forum Discussion

Flemming_V_Mort's avatar
Icon for Nimbostratus rankNimbostratus
Jul 10, 2012

Manipulate HTTP::request holding UTF-8 national characters in POST payload



I've used as a foundation to my iRule for handling mobile device access to RESTservices.


The scenario did call for the addition of several http-headers upon the successful pseudo side band validation of device details.



I've added more attributes to be piggy-backed on the validation-answer and to be included as new http-headers combined with the original request towards the REST services.



As I live in Denmark, we've got some national characters residing in the upper part of the UTF-8 range and I learned, that the append(and concat aso) commands invalidates those characters when used to construct the new request.



By chance I discovered, that the [HTTP::payload replace ...] does indeed conserve those characters untouched so my simple and effective solution is to replace the append/concat with a series of [HTTP::payload replace ...] commands.



Pseudo-code (see the devcentral approach for the full scenario)(the iRule has been rewritten to handle GET and POST)




set LB_request [HTTP::request]





set LB_req_payload [HTTP::payload]





set newLB_request [string map [list "CustomerNumber: " "CustomerNumber: $MyCustomerNumber"] $LB_request]


set newLB_request [string map [list "PhoneNumber: " "PhoneNumber: $MyPhoneNumber"] $newLB_request]



first empty the payload


HTTP::payload replace 0 [HTTP::payload length] ""


then copy the stored req headers into packet


HTTP::payload replace 0 0 $newLB_request


then copy the stored payload into packet


HTTP::payload replace [HTTP::payload length] 0 $LB_req_payload



fire off the new request


HTTP::retry [HTTP::payload]



The bold section above holds the fix for the TCL append/concat showing the use of “HTTP::payload replace” method to do the string manipulations.


1. The first bold HTTP::payload line does empty the object (replace current content with nothing) 2. The second HTTP::payload line inserts the manipulated request headers as the only content in the object (replace object content from offset 0 and allow infinite lengt with the manipulated headers)


3. The third HTTP::payload line does insert the original payload in the object, starting at the current end of the object content and allowing for infinite string length. (replace object content starting at the end and fill in the original payload)



I’d like not to disclose any deeper details right now.



Feel free to use the findings as you may see fit.



Kind Regards/Venlig hilsen


Flemming Vestergaard Mortensen, SAP-konsulent


Administrative software-løsninger


Niels Bohrs Allé 185, DK-5220 Odense SØ






Direkte +45 44605275 Mobil +4525247558
No RepliesBe the first to reply