It appears that the xdmp.http* functions (xdmp.httpGet, xdmp.httpPost etc.) in MarkLogic Servie-side JavaScript doesn't support multiple Set-Cookie in response header -- only one of the cookies is returned
xdmp.httpGet('https://httpbin.org/response-headers?Set-Cookie=a&Set-Cookie=b')
{
"code": 200,
"message": "OK",
"headers": {
"access-control-allow-credentials": "true",
"access-control-allow-origin": "*",
"content-type": "application/json",
"date": "Thu, 11 Apr 2019 19:12:55 GMT",
"server": "nginx",
"set-cookie": "b", // only one cookie
"content-length": "111",
"connection": "keep-alive"
}
}
In comparison, the equivalent xdmp:http-* functions behave correctly:
xdmp:http-get('https://httpbin.org/response-headers?Set-Cookie=a&Set-Cookie=b')
<response xmlns="xdmp:http">
<code>200</code>
<message>OK</message>
<headers>
<access-control-allow-credentials>true</access-control-allow-credentials>
<access-control-allow-origin>*</access-control-allow-origin>
<content-type>application/json</content-type>
<date>Thu, 11 Apr 2019 19:21:40 GMT</date>
<server>nginx</server>
<set-cookie>a</set-cookie> // both cookies
<set-cookie>b</set-cookie>
<content-length>111</content-length>
<connection>keep-alive</connection>
</headers>
</response>
JSON can only represent one field per name. The parser is obviously working.
Support for multi-value http headers in JSON appears missing. There are many ways in which it could be done, but all would be internal fixes.
You could try calling xdmp.eval and using the XQuery version with XML results, and then reading the XML or transforming to JSON in a more suitable format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With