RosHTTP
RosHTTP copied to clipboard
Incorrect handling of `Set-Cookie` header
As per the Node doc:
set-cookie
is always an array. Duplicates are added to the array.
Yet SimpleHttpResponse.headers
are an HeaderMap[String]
. But at runtime, headers.get("Set-Cookie")
returns a js.Array[String]
instead of a String
.
(Just discussed the issue today on the Scala.js Gitter.)
Workaround:
headers.asInstanceOf[fr.hmil.roshttp.util.HeaderMap[Any]].get("Set-Cookie") map
(_.asInstanceOf[js.Array[String]])
Thanks @ebruchez for pointing this out. This issue is open for PRs A correct fix has to take care of the following points:
- [ ] Find an appropriate way to adapt RosHTTP's API such that it can return Arrays of headers*
- [ ] adapt the Node.js driver
- [ ] make sure that XMLHttpRequest.getAllResponseHeaders() returns duplicates, then adapt the browser driver to handle them.
- [ ] make sure that HttpURLConnection.html#getHeaderField(int) returns duplicates and adapt the JVM driver
- [ ] Add test cases
*The API change should be non-breaking. Although the current API assumes headers are unique, that is still what you will want in most cases. However, some utility function should be added to allow retrieval of header arrays. No special treatment should be granted to any particular header at least from the public API point of view. If a backend does change the return type for some specific header, this should be handled and not show on the public API (the node driver will need a lot of duct tape there).
As per the Node doc:
Never realized this API was that much broken. A scala frontend can definitely make it safer to use :wink: