Header that contains JSON is getting mangled by Apigee.

Not applicable

If I pass a header like this:

	SiteSpectSVBanner={"totPV":"$0.00","totEV":"$0.00","totAll":"$0.00","totCS":"$0.00","totExSoon":"$0.00","lModDt":"2018-04-05 11:23:56","error":"false"};

It gets mangled, so that when I retrieve it, it looks like this:

	SiteSpectSVBanner={"totPV":"$0.00",totEV":"$0.00,totAll":"$0.00,totCS":"$0.00,totExSoon":"$0.00,lModDt":"2018-04-05 11:23:56,"error":"false"};

Note that some of the double-quotes are now missing. It's no longer valid JSON.

Further details for the problem statement are attached below.

Cookie is getting malformed when recieved.

Solved Solved
0 6 862
1 ACCEPTED SOLUTION

EDIT 2019 March 6

New information has come to light. If you retrieve the header via request.header.HEADERNAME.values.string , you will get the unparsed header, and the json will not get mangled.

This is a bit unwieldy, but it works.


Hi Ashima

Check this article for some suggestions on handling "multi-valued headers".

In general, a header that contains a comma is interpreted (blindly) by Apigee Edge as a multi-valued header. If you put JSON in a header, Apigee Edge will treat it as a multi-valued header, and retrieving "request.header.myheadername" will not work nicely.

If you can use the suggestions in the above article, great.

If not then I suggest base64-encoding the JSON on the client side before putting it into the header, then base64-decoding it in Apigee Edge after retrieval.

View solution in original post

6 REPLIES 6

@Ashima Arora ,

Can you please attach a sample proxy to reproduce issue with sample API call ?

-------------------------------

Anil Sagar

5997-screen-shot-2017-11-23-at-75916-pm.png Learn Apigee Concepts in 4 Minutes HandsOn

cookieissue-1-rev1-2018-04-161.zip

Hi Anil,



Attached is an api proxy and use below cookie while checking through postman.

SiteSpectSVBanner={"totPV":"$0.00","totEV":"$0.00","totAll":"$0.00","totCS":"$0.00","totExSoon":"$0.00","lModDt":"2018-04-05 11:23:56","error":"false"};



So at the entry point you will see that the cookie is getting malformed like this.

SiteSpectSVBanner={"totPV":"$0.00",totEV":"$0.00,totAll":"$0.00,totCS":"$0.00,totExSoon":"$0.00,lModDt":"2018-04-05 11:23:56,"error":"false"};


" are getting skipped and cookie is getting malformed.
Thanks in advance.

EDIT 2019 March 6

New information has come to light. If you retrieve the header via request.header.HEADERNAME.values.string , you will get the unparsed header, and the json will not get mangled.

This is a bit unwieldy, but it works.


Hi Ashima

Check this article for some suggestions on handling "multi-valued headers".

In general, a header that contains a comma is interpreted (blindly) by Apigee Edge as a multi-valued header. If you put JSON in a header, Apigee Edge will treat it as a multi-valued header, and retrieving "request.header.myheadername" will not work nicely.

If you can use the suggestions in the above article, great.

If not then I suggest base64-encoding the JSON on the client side before putting it into the header, then base64-decoding it in Apigee Edge after retrieval.

Hi Dino,

Thanks for the response. We are already using request.header.cookie.values to fetch all the cookies so that's not an issue for us but the actual issue is with the json in cookie getting malformed. Although the other solution suggested by you seems feasible but in case something can be done at apigee end only that would be a great help.

Thanks

Ashima

Yes, I just tested this and I see the incorrect behavior that you reported. Somehow Apigee Edge is mangling the JSON before you have a chance to receive it, when it is passed in a header. what I can suggest:

  • encode the JSON with base64 or encodeURIComponent() or similar, before passing. Then decode using the converse algorithm on the Apigee edge side, before trying to parse the JSON . This is how JWT are passed in headers; they are base64-encoded.
  • Rather than using JSON as your data-encoding format, encode it as something simpler. Like a comma-separated list of key/value pairs. E.g.:

    totPV:$0.00, totEV:$0.00, totAll:$0.00, totCS:$0.00, totExSoon:$0.00, lModDt:2018-04-05-112356, error:false
    	

    In Apigee Edge, you can read the .values variable, and then parse it as described in that prior article.

I'll raise a bug on the behavior you're seeing. It seems to me there ought to be some way of getting the original JSON through un-mangled, without double-encoding it. But anyway for now you have a workaround.

Hey Dino, was there any update on this? The JSON getting mangled before even being able to receive it.