For this recipe, we will explore how Play applications can manipulate HTTP headers. We will use the curl
tool to validate if our changes to the HTTP response headers were applied correctly. For Windows users, it is recommended to install Cygwin in order to have a unix-like environment for Windows machines (https://www.cygwin.com/).
For Java, we need to take the following steps:
Run the
foo_java
application with Hot-Reloading enabled:activator "~run"
Modify
foo_java/app/controllers/Application.java
by adding the following action:public static Result modifyHeaders() { response().setHeader("ETag", "foo_java"); return ok("Header Modification Example"); }
Add a new
routes
entry for the newly-added action infoo_scala/conf/routes
:GET /header_example controllers.Application.modifyHeaders
Request our new route and examine the response headers to confirm our modifications to the HTTP response header:
$ curl -v http://localhost:9000/header_example...