Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Play 2.0+ there's not possible to use wildcard VERBs (like <code>*</code> or <code>ANY</code> or multivalued) (which could be a solution for you), so in this case '<em>DRY violation</em>' you are using is only official way.</p> <p><strong>Edit</strong> </p> <p>Actually you can try another approach:</p> <ul> <li>on the end of <code>routes</code> file put '<em>catch-all HEAD</em>` rulez</li> <li>If there is not specified route for <code>HEAD /path</code> '<em>catch-all</em>' sends it to <code>autoHead(path: String)</code> action.</li> <li>There you can forward all headers from request to <code>GET</code> version of the route with <a href="http://www.playframework.org/documentation/2.0.4/JavaWS" rel="nofollow">WebServices</a>, then get the response and return headers only.</li> </ul> <p>I added working sample of this approach (Java only) to <a href="https://github.com/biesior/play-simple-rest" rel="nofollow">play-simple-rest</a> sample app. The things important for redirecting are:</p> <ul> <li><a href="https://github.com/biesior/play-simple-rest/blob/master/app/controllers/Application.java#L69-L100" rel="nofollow">Application.autoHead(String originalPath)</a>:</li> </ul> <pre class="lang-java prettyprint-override"><code>public static Result autoHead(String originalPath) throws IllegalAccessException { WS.WSRequestHolder forwardedRequest = WS.url("http://" + request().host() + request().path()); // this header will allow you to make additional choice i.e. avoid tracking the request or something else // see condition in index() action forwardedRequest.setHeader("X_FORWARD_FROM_HEAD", "true"); // Forward original headers for (String header : request().headers().keySet()) { forwardedRequest.setHeader(header, request().getHeader(header)); } // Forward original queryString for (String key : request().queryString().keySet()) { for (String val : request().queryString().get(key)) { forwardedRequest.setQueryParameter(key, val); } } // Call the same path but with GET WS.Response wsResponse = forwardedRequest.get().get(); // Set returned headers to the response for (Field f : Http.HeaderNames.class.getFields()) { String headerName = f.get(null).toString(); if (wsResponse.getHeader(headerName) != null) { response().setHeader(headerName, wsResponse.getHeader(headerName)); } } return status(wsResponse.getStatus()); } </code></pre> <ul> <li><a href="https://github.com/biesior/play-simple-rest/blob/master/app/controllers/Application.java#L106-L108" rel="nofollow">Application.forwardedFromHead()</a> + <a href="https://github.com/biesior/play-simple-rest/blob/master/app/controllers/Application.java#L29-L33" rel="nofollow">condition using it</a></li> </ul> <pre class="lang-java prettyprint-override"><code>public static boolean forwardedFromHead() { return (request().getHeader("X_FORWARD_FROM_HEAD") != null &amp;&amp; "true".equals(request().getHeader("X_FORWARD_FROM_HEAD"))); } </code></pre> <ul> <li><p>And two routes HEAD on the <a href="https://github.com/biesior/play-simple-rest/blob/master/conf/routes#L34-L35" rel="nofollow">end of the file route file</a></p> <pre><code>HEAD / controllers.Application.autoHead(originalPath:String ?= "/") HEAD /*originalPath controllers.Application.autoHead(originalPath:String) </code></pre></li> </ul> <p>P.S. If you would like to write something similar in Scala it would be nice :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload