Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Parsing issue | Request Header with Comma

Hi,

We are passing request header x-client-certificate-issuer header and the header is coming with value .

How ever while setting this as reference or retrieving this value from the context object is not giving complete string . Below is the example . 

Incoming request :

Header : x-client-certificate-issuer = C=BE,G=Test,L=DE,Org=Test

where header name = x-client-certificate-issuer 

Header Value = C=BE,G=Test,L=DE,Org=Test

JS - While fetching this value to a variable 

var DN = context.getVariable("x-client-certificate-issuer");

print (DN);

Out put result is = C=BE  . It is omitting the character after comma. 

 

Best Regards,

Patty 

 

Solved Solved
1 2 1,378
1 ACCEPTED SOLUTION

Yes, this is the expected, documented behavior.

multi-valued-headers.png

Reading a little further down that documentation page, it explains that you can use a variable of a different form to get the entire string. Can you try this?

 

var DN = context.getVariable("request.header.x-client-certificate-issuer.values.string");

 

This will work if you have commas in the header value.


A little more explanation and context:

The issue relates to the meaning of commas mean within HTTP headers. The HTTP spec allows multiple headers of the same name in a request. Suppose I can have a request that has repeated instances of a header, like this:

 

x-forwarded-for: 192.168.1.3
x-forwarded-for: 234.78.1.2
x-forwarded-for: 78.12.13.6

 

That can alternatively be expressed as a single header, with commas separating the values, like this:

 

x-forwarded-for: 192.168.1.3,234.78.1.2,78.12.13.6

 

And Apigee recognizes that. Specifically for headers that contain commas, also known as multi-valued headers, Apigee allows you to retrieve any of those 3 values, by using a variable name like request.header.HEADERNAME.N , where N is replaced by an index {1, 2, 3}. And you can retrieve the entire string, effectively ignoring the commas, by using request.header.HEADERNAME.values.string .

View solution in original post

2 REPLIES 2

Yes, this is the expected, documented behavior.

multi-valued-headers.png

Reading a little further down that documentation page, it explains that you can use a variable of a different form to get the entire string. Can you try this?

 

var DN = context.getVariable("request.header.x-client-certificate-issuer.values.string");

 

This will work if you have commas in the header value.


A little more explanation and context:

The issue relates to the meaning of commas mean within HTTP headers. The HTTP spec allows multiple headers of the same name in a request. Suppose I can have a request that has repeated instances of a header, like this:

 

x-forwarded-for: 192.168.1.3
x-forwarded-for: 234.78.1.2
x-forwarded-for: 78.12.13.6

 

That can alternatively be expressed as a single header, with commas separating the values, like this:

 

x-forwarded-for: 192.168.1.3,234.78.1.2,78.12.13.6

 

And Apigee recognizes that. Specifically for headers that contain commas, also known as multi-valued headers, Apigee allows you to retrieve any of those 3 values, by using a variable name like request.header.HEADERNAME.N , where N is replaced by an index {1, 2, 3}. And you can retrieve the entire string, effectively ignoring the commas, by using request.header.HEADERNAME.values.string .

Thank you Dino . This solution worked .

Thank you for nice and crystal explanation .

Best Regards,

Patty