requests-scala
requests-scala copied to clipboard
Bug: Exception on empty cookie header
Hi,
I just found an odd behaviour of requests-scala. When using the library to call the Spotify API, it throws the following exception:
Caused by: java.lang.IllegalArgumentException: Empty cookie header string
at java.base/java.net.HttpCookie.parseInternal(HttpCookie.java:839)
at java.base/java.net.HttpCookie.parse(HttpCookie.java:210)
at java.base/java.net.HttpCookie.parse(HttpCookie.java:186)
at requests.Response.$anonfun$cookies$2(Model.scala:205)
at scala.collection.Iterator$$anon$10.nextCur(Iterator.scala:585)
at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:599)
at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:574)
at scala.collection.mutable.Growable.addAll(Growable.scala:64)
at scala.collection.mutable.Growable.addAll$(Growable.scala:60)
at scala.collection.immutable.MapBuilderImpl.addAll(Map.scala:692)
at scala.collection.immutable.Map$.from(Map.scala:643)
at scala.collection.IterableOnceOps.toMap(IterableOnce.scala:1256)
at scala.collection.IterableOnceOps.toMap$(IterableOnce.scala:1255)
at scala.collection.AbstractIterator.toMap(Iterator.scala:1279)
at requests.Response.<init>(Model.scala:207)
at requests.Requester.apply(Requester.scala:122)
Below the (in my eyes) relevant part of scala-requests code (Model.scala, lines 201 - 207):
val cookies: Map[String, HttpCookie] = history.toSeq.flatMap(_.cookies).toMap ++ headers
.get("set-cookie")
.iterator
.flatten
.flatMap(java.net.HttpCookie.parse(_).asScala) // Line 205, where the exception happens
.map(x => x.getName -> x)
.toMap
Debugging shows that the response, which triggers this problem, has set the "set-cookie" header, but with no contents. I guess using a filter to get rid of empty strings should solve the problem.