RosHTTP icon indicating copy to clipboard operation
RosHTTP copied to clipboard

Incorrect handling of `Set-Cookie` header

Open ebruchez opened this issue 7 years ago • 2 comments

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.)

ebruchez avatar Aug 23 '17 21:08 ebruchez

Workaround:

headers.asInstanceOf[fr.hmil.roshttp.util.HeaderMap[Any]].get("Set-Cookie") map
  (_.asInstanceOf[js.Array[String]])

ebruchez avatar Aug 23 '17 21:08 ebruchez

Thanks @ebruchez for pointing this out. This issue is open for PRs A correct fix has to take care of the following points:

*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:

hmil avatar Aug 24 '17 07:08 hmil