Truncating JSON headers - Unable to read the complete headers which have json values in them.

Not applicable

We are using extract variables to retrieve a header containing json values. Only a part of the value is assigned/read into the context variable.

<DisplayName>Extract Variables-1</DisplayName> <Properties/> <Header name="x-ads-test-json"> <Pattern ignoreCase="false">{header-json1}</Pattern> </Header>

curl -H "header-name:[{'from':'foo1.txt','to':'tofoo1.txt'},{'from':'foo2.txt','to':'tofoo2.txt'}]" "https://xyz.com/proxy_name"

For the example request above, the context variable has "[{'from':'foo1.txt'" instead of the entire value.

How can we get complete list of values.

0 3 131
3 REPLIES 3

Not applicable

As per design implementation when the value of the header contains a ',' (comma character) then the context variable. will not return the full value (we only get the part of the value that is before the comma character).

We need to implement Sample JS code for getting all values from HTTP header like below.

var total_values_in_header = context.proxyRequest.headers['header-name''].length();

context.setVariable('segments-in-header',total_values_in_header);

var header_value = '';

for(i=0; i<total_values_in_header; i++) {

var header_value = header_value + "," + context.proxyRequest.headers['header-name''][i];

}

context.setVariable('retrieved-header1',header_value);

header_value2 = header_value.slice(1);

context.setVariable('retrieved-header2',header_value2);

adas
Participant V

The comma is being treated as a separator and we are only returning the first value thinking its a multi-value header. So yes, this needs to handled separately in a javascript like you have already show. However, I am trying to understand what would be the use-case for someone to send json values in the header. This can have other implications and performance overheads. This is not a very scalable approach and should not be encouraged. Remember, you are doing this header parsing for every incoming request and imagine doing this at few thousand tps. It would just introduce too much of an overhead.

Not applicable

@arghya das I understand the implication of sending json value in the header but we have a few users who wanted to try this out just for the trial purpose.