Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Exception on empty cookie header #74

Open
neunzehnhundert97 opened this issue Jan 16, 2021 · 0 comments
Open

Bug: Exception on empty cookie header #74

neunzehnhundert97 opened this issue Jan 16, 2021 · 0 comments

Comments

@neunzehnhundert97
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant