akka / akka-http

The Streaming-first HTTP server/module of Akka

Home Page:https://doc.akka.io/docs/akka-http

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add cookie store for the HTTP client side

akka-ci opened this issue · comments

Issue by jrudolph
Wednesday Feb 11, 2015 at 13:53 GMT
Originally opened as akka/akka#16855


If configured, the store would automatically pick up cookies from responses and add them to requests. Also, it would make sure that the security rules about which cookies to apply in which situations would be applied.

This is part of the bigger initiative to support a high-level HTTP client interface as tracked as #16856.

/cc @sirthias

Comment by ktoso
Tuesday Oct 20, 2015 at 08:45 GMT


Investigating if other libraries do this. This is starting to become pretty web-browser-ish.

Comment by ktoso
Wednesday Oct 21, 2015 at 20:10 GMT


My research indicates WS does not do this => we probably shouldn't as well (at least not as a first thing to jump on unless people start demanding it furiously).

Comment by robsonpeixoto
Tuesday Feb 23, 2016 at 02:46 GMT


@ktoso it's is very useful to write deep web(behind forms) crawlers.

Comment by intracer
Wednesday Mar 16, 2016 at 09:47 GMT


As low as JDK does this https://docs.oracle.com/javase/7/docs/api/java/net/CookieManager.html
Some web API (such as Wikipedia - https://phabricator.wikimedia.org/T124252) require non-basic cookie handling

Comment by unoexperto
Tuesday May 03, 2016 at 13:52 GMT


val newCookies = response.headers.filter(_.isInstanceOf[`Set-Cookie`]).map { v =>
  val cookie = v.asInstanceOf[SetCookie].cookie()
  HttpCookiePair.apply(cookie.name(), cookie.value())
}
val cookie = Cookie(newCookies)

Gentlemen, is there elegant way of constructing Cookie header out of Set-Cookie headers ? Currently I have to cast to java SetCookie in order to get raw value. Scala version returns rendered value with path from value(). Is there right way to do it ? I'm on 2.4.4

Comment by ktoso
Tuesday May 03, 2016 at 13:53 GMT


Anywhere:

response.header[`Set-Cookie`]

Routing DSL:

headerValue[`Set-Cookie`] { setCookie => 

}

Comment by unoexperto
Tuesday May 03, 2016 at 16:39 GMT


Oh, it's not routing DSL. I'm making client call.

Comment by ktoso
Tuesday May 03, 2016 at 20:12 GMT


That's why I've shown both examples :) see "anywhere"

Comment by unoexperto
Thursday May 05, 2016 at 12:25 GMT


I see. response.header[Set-Cookie] returns only first header though. It would be nice to have response.headers[Set-Cookie]

Comment by ktoso
Thursday May 05, 2016 at 12:28 GMT


Fun idea, I fear we can't just add it like that though because name already used, some helper might be a fun idea, please open a ticket.

For now it's: val setCookies = response.headers.collect { case c: Set-Cookie => c }