Headers with ',' in Javascript

Not applicable

Hey folks,

I'm having some trouble with header values that contain a comma. I'm implementing a piece of java script that should process signature headers as defined in https://tools.ietf.org/html/draft-cavage-http-signatures-10

But i get only half of the value, everything after the first comma is removed, while i can get to it from the context variable. It there a good way around this? See snippet below:

print("Signature (via context): " + context.getVariable("request.header.signature.values")); 
print("Signature (via javascript: " + request.headers['Signature'])

Signature (via context): [headers="digest x-request-id date", signature="V9CKx2vr5MT/MObr3RwpvcOH0YvkcqUvwLWQgFqd3S/C95oigoemwf6iMuA8yX3lojI6UadMp6ZJtaJbDAOqZXPnwidN0lLaPnjZ2xLfCsKtAFFYLOqWPGTLSwUXLTvULOL6pU9/xheC5Ic+SdwkeaAfG5E60wU1Q2RFQC9q+kQ6mNMYtXF4qMMtPJKf6SRlYGcbEvcY4421lERMBpoa2Rqiwub2Mk63oG81chmCYCWqusm3mJU0vdSKS9Rm/6sLR+oMlcvEKZ3IdtSvEFrzaVS+Dwsy1WwGLhiYPv8DSpgFSRN+kNjM1ZqfloeseExB7cMlu9/2/b782YZJ6tUzrw==", keyId="SN=5f74dd8c52cb8489, CA=CN=XXX"]

Signature (via javascript): headers="digest x-request-id date"

The original header is

"Signature":["headers=\"digest x-request-id date\",signature=\"uQfHa9ZDb/yKeF1RmwpTpcTZxg9X5YQeuJFs5wSJ3DRpN6JmGruaPy2TC6QxD6vy4n4ejkA2fiomxReSv58XzBmiGcVvaZtr1e0nc7NTT2oYpiHvrvX8Xgy4u85dsepiKWACh5sXB3nD3et6UckXQY9o0sT+bs9rq7qh4Dh083vCXWCpchqV50eErbXEzJaEiKTyyS2KWZ3EQRBBvWAQ+yc5WDm1C8qcL7DGagvzr6azEyzUMijV/K9UeqcHWWddDXhvPwCOKAHEWWoYQB2hwOp7dYlbX+7aIYVQu088dC7bbRbCuQMKiSJarlth+CXUTaGfprwe37ksRarMJhJkHA==\",keyId=\"SN=5f74dd8c52cb8489,CA=CN=XXX\""],"TPP-Signature-Certificate"
0 4 382
4 REPLIES 4

Try this.

context.getVariable('request.header.signature.values')+'';

More explanation on this link -

https://community.apigee.com/articles/2319/how-to-handle-multi-value-headers-in-javascript.html

Thanks! This indeed gives me the value that i need, unfortunately i then need to reconstruct the original value from the resulting string.

There really should be a way to just request the original value from the header...

I agree! There should be an easier way to do what you want.

@Hugo Trippaers

You may want to examine this repo: https://github.com/apigee/iloveapis2015-hmac-httpsignature

It works with RSA and HMAC signatures.