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:
@@ -51,6 +51,16 @@ public class HttpResponse {
|
||||
return response.getStatusLine().getStatusCode();
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return response.getFirstHeader("X-FYI-Content-Type").getValue();
|
||||
}
|
||||
|
||||
public boolean hasContent() {
|
||||
Preconditions.checkNotNull(response,
|
||||
"Response is not initialized.");
|
||||
return response.getEntity() != null;
|
||||
}
|
||||
|
||||
public String getEntityContent() throws IOException {
|
||||
Preconditions.checkNotNull(response,
|
||||
"Response is not initialized.");
|
||||
|
||||
@@ -114,6 +114,9 @@ public class RestSession extends HttpSession {
|
||||
return execute(Request.Delete(url + "/a" + endPoint));
|
||||
}
|
||||
|
||||
public RestResponse head(String endPoint) throws IOException {
|
||||
return execute(Request.Head(url + "/a" + endPoint));
|
||||
}
|
||||
|
||||
public static RawInput newRawInput(String content) {
|
||||
return newRawInput(content.getBytes(UTF_8));
|
||||
|
||||
Reference in New Issue
Block a user