Can't get cookies from HttpResponse


(Vatel) #1

Hello, I am trying to make REST API call with akka http client. Below is “log in” request:

Http().singleRequest(HttpRequest(...)).flatMap { resp =>
  println("headers = " + resp.headers)
  println("cookie = " + resp.header[`Set-Cookie`])
  ...
}

This is what I see in console:

headers = List(set-cookie: myCookie=blahblah; Expires=Fri, 24 Jan 2020 13:42:55 GMT; Domain=; Path=/, Server: akka-http/10.1.6, Date: Thu, 24 Jan 2019 13:42:55 GMT)

cookie = None

In debugger I see that ‘headers’ collection contains RawHeader with ‘set-cookie’.
In network sniffer I see:

Set-Cookie: myCookie=blahblah; Expires=Fri, 24 Jan 2020 13:42:55 GMT; Domain=; Path=/

Also there is a warning from akka:

Illegal header: Illegal 'set-cookie' header: Invalid input ';', expected OWS or domain-value (line 1, column 145): myToken=blahblah; Expires=Fri, 24 Jan 2020 13:42:55 GMT; Domain=; Path=/

The cookie is set at server-side by ‘setCookie’ routing directive (under the same version of Java, Scala, Akka etc, at the same Linux machine, localhost), browsers understand it. I use Scala 2.12.8, akka 2.5.19, akka http 10.1.6, Java 8

What is wrong here?


(Arnout Engelen) #2

Indeed when a header cannot be parsed it is included as a RawHeader instead of a parsed header.

Since the error says “expected OWS or domain-value”, I think it is the Domain=; part that fails to parse. I haven’t checked the RFC, but I suspect the domain may not be empty (or perhaps in that case should be omitted entirely)?


(Vatel) #3

raboof, thank you!

I have completely missed the thing with domain… I did testing of client-side at localhost, so I was thinking that empty domain was ok. In server-side code I have found that it was a fix for Chromium that does not understand ‘127.0.0.1’ and ‘localhost’ as domain - it was incorrect fix. Without ‘Domain’ part at all in Set-Cookie it finally works!