title: Play 2 - Set header on all responses?
body: <p>I'm aware from <a href="https://stackoverflow.com/questions/8199490/setting-http-headers-in-play-2-0-scala">Setting HTTP headers in Play 2.0 (scala)?</a> that you can set response headers on a case-by-case basis by doing, for example, <code>Ok("hello").withHeaders(PRAGMA -&gt; "no-cache")</code>.</p>
  
  <p>What if you want to set that header, or a few different headers, on responses from all your Actions?  You wouldn't want to repeat the <code>withHeaders</code> everywhere.  And since this is more like an application-wide configuration, you might not want Action writers to have to use a different syntax to get your headers (e.g. <code>OkWithHeaders(...)</code>)</p>
  
  <p>What I have now is a base Controller class that looks like</p>
  
  <pre><code>class ContextController extends Controller {
   ...
   def Ok(h: Html) = Results.Ok(h).withHeaders(PRAGMA -&gt; "no-cache")
  }
  </code></pre>
  
  <p>but that doesn't feel quite right.  It feels like there should be more of an AOP-style way of defining the default headers and having them added to each response.</p>