Rob
Rob

Reputation: 191

Play Framework withCookies but no cookies in client document

I have a simple controller

object Application extends Controller {
  def index = Action {
    Ok(views.html.index("Your new application is ready.")).withCookies(Cookie("Key", "Value"))
  }
}

Everything is setup properly (routes, index.scala.html ...)

The "index" triggers the following JavaScript code.

console.log("thecookies: " + document.cookie);

(There is no more code)

The output is only

thecookies:

but no cookies.

Any ideas ? I am clueless and cannot make the example even more simple.

Running on : play_2.11:2.3.8

(Browser allows cookies)

Upvotes: 1

Views: 414

Answers (1)

Rob
Rob

Reputation: 191

To make the cookie be accessible through 'document.cookie' I had to set the 'httpOnly' flag to 'false' (which is default on 'true', the last parameter) !

.....withCookies(Cookie("key", "value", None, "/", None, false, false))

Upvotes: 1

Related Questions