We’re using Silhouette project and trying to migrate from Play2.5/Scala 2.11 to Play2.6.15/Scala 2.12.6
And it seems like there is some issue around RequestHeader.cookies API. Silhouette CookieAuthenticatorService contains following code:
request.cookies.get(settings.cookieName) match {
case Some(cookie) => ....
case None => Future.successful(None)
In Play 2.5 request.cookies never throws exception and returns Cookies backed by empty Map. In Play 2.6, it tries to do TypedMap.apply(key) and throws NoSuchElementException:
Caused by: java.util.NoSuchElementException: key not found: Cookies
at scala.collection.immutable.Map$Map3.apply(Map.scala:167)
at play.api.libs.typedmap.DefaultTypedMap.apply(TypedMap.scala:92)
at play.api.mvc.RequestHeader.cookies(RequestHeader.scala:221)
at play.api.mvc.RequestHeader.cookies$(RequestHeader.scala:221)
at play.api.mvc.WrappedRequest.cookies(WrappedRequest.scala:16)
at com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticatorService.$anonfun$retrieve$2(CookieAuthenticator.scala:210)
at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:303)
at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
Seems like vanilla Play2.6 always initiates RequestAttrKey.Cookies attribute (in DefaultRequestFactory), and it somehow lost in my integration with Silhouette or/and FakeRequest (an exception is thrown in tests), but I would like to know, is that change looking like breaking backward-compatibility, isn’t it?