For this recipe, we will explore how Play applications can manipulate HTTP cookies. We will use the curl
tool to validate our changes to the HTTP response headers containing the new cookie we added to the response.
For Java, we need to take the following steps:
Run the
foo_java
application with Hot-Reloading enabled.Modify
foo_java/app/controllers/Application.scala
by adding the following action:public static Result modifyCookies() { response().setCookie("source", "tw", (60*60)); return ok("Cookie Modification Example"); }
Add a new route entry for the newly-added action in
foo_java/conf/routes
:GET /cookie_example controllers.Application.modifyCookies
Request our new route and examine the response headers to confirm our modifications to the HTTP response header:
$ curl -v http://localhost:9000/cookie_example * Hostname was NOT found in DNS cache * Trying ::1... * Connected to localhost (::1) port 9000 (#0) > GET /cookie_example...