http header value whitespaces stripped after comma character

Not applicable

Hi Everyone,

I've observed that when a request comes our Apigee Edge with a header value which contains a comma and whitespaces, the whitespaces are stripped.

I've verified that the whitespaces are there in my outgoing http request from my client, but in the Apigee real-time trace tool, the very first instance of incoming message displays the header value without the whitespaces!

It would therefore appear that Apigee, in its http request parsing/rendering process, is stripping out the whitespaces that occur after a comma. I've confirmed that this is not simply an issue in how the header value is rendered in the trace tool, as any subsequent flow variables which use the header value also reflect that the whitespaces have been stripped.

Why is this? Is there any way around this? This seems like a bug unless someone knows why this should be expected behavior (I can't find any reason why in the HTTP Protocol spec).

Thanks in advance for any insight and/or help on this!

Best,

Chris

0 2 1,722
2 REPLIES 2

I don't know why Apigee Edge would be doing that, but,... maybe I can help you.

What are you really trying to do? Are the spaces after the commas important? Can you elaborate a little on your scenario?

I have just checked RFC7230, and it states that a comma-separated list of values for a header is formatted as a value, followed by a comma, and optional whitespace, and then the next value, and so on. Therefore the whitespace after a comma is insignificant, according to the proposed standard. If you are relying on the whitespace after a comma, I think maybe you might be doing it wrong.

If you want to get the individual values, you would do something like this:

var hdr = context.getVariable('response.header.HEADERNAME.values')+'';
// get the array of header values: 
var a = hdr.substring(1, hdr.length-1).split(',');

...per this article.

@Dino

Thanks for the quick reply. The reason why I'm trying to preserve the whitespace after the comma is that my API is sending a filename in the http header. The filename could have commas in it, and although this is certainly an edge case, whenever a filename is passed with a comma followed by whitespace, the whitespace is stripped.

Ideally, we would change our implementation to not send the filename in the header; however, in the (probably lengthy) interim, I wanted to at least be able to get this edge case sorted.

The article you mention is actually how we had it implemented; however, the whitespace appears to be stripped at the very first instance in the trace tool rendering (as well as in the flow variable itself).

Thanks in advance for your help!