EddyVerbruggen/nativescript-webview-utils

Setting multiple cookies in header not possible

Opened this issue · 0 comments

Which platform(s) does your issue occur on?

  • Both

Please, provide the following version numbers that your issue occurs with:

Not relevant as this is a code related thing.

Please, tell us how to recreate the issue in as much detail as possible.

As the headers is in a Map<string, string> it is not possible to use the header parameter Set-Cookie more than for one cookie. I need to set more than one cookie when doing a request and it's not possible as of how a Map works. To be able to set more than one cookie the syntax in a HTTP header is:
Set-Cookie: cookie1=value1
Set-Cookie: cookie2=value2
etc

By the nature of a Map<string, string> there is no way to set more than one and one only value. A way of doing this could be to use a method named WebViewUtils.addHeaders(wv: WebView, headers: Map<string, string[]>) and that in a non destructive manner just adds the the array of header values with the header param name one for each value. Non-destructive in that manner that addHeaders of whatever type can be called multiple times and in that manner build up the total payload of headers.

Is there any code involved? Yes!

// This code does not work. Server will only retrieve cookie2 but both must be included to make a successful request.
const headers: Map<string, string> = new Map();
headers.set('Set-Cookie', 'cookie1=value1');
headers.set('Set-Cookie', 'cookie2=value2');
WebViewUtils.addHeaders(webView, headers);