RestApiServlet: Allow HEAD requests

Change I3be4aeb009 replaced the "Get file type" REST API endpoint with
the /content endpoint. According to documentation [1], the content type
can be retrieved by making a HEAD request to the endpoint.

This doesn't work because RestApiServlet is only checking for GET, and
HEAD requests result in 404. Modify it to also allow HEAD requests.

Add a test to make sure it works.

[1] https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-content

Bug: Issue 4136
Change-Id: If5eaaba2fec94499f332970ce6b8c6db2ac9c571
This commit is contained in:
David Pursehouse
2016-08-05 15:38:16 +09:00
parent 8f87b40905
commit ec3ee59b43
4 changed files with 30 additions and 4 deletions

View File

@@ -317,8 +317,7 @@ public class RestApiServlet extends HttpServlet {
return;
}
if (viewData.view instanceof RestReadView<?>
&& "GET".equals(req.getMethod())) {
if (viewData.view instanceof RestReadView<?> && isGetOrHead(req)) {
result = ((RestReadView<RestResource>) viewData.view).apply(rsrc);
} else if (viewData.view instanceof RestModifyView<?, ?>) {
@SuppressWarnings("unchecked")