O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using HTTP headers

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/).

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:
        activator  "~run"
    
  2. 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");
        }
  3. Add a new routes entry for the newly-added action in foo_scala/conf/routes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required