Do not emit response body for HEAD requests

pull/95/head
Andrew Gaul 2015-11-11 16:03:42 -08:00
rodzic 10f2e930a4
commit 1797992e02
1 zmienionych plików z 12 dodań i 4 usunięć

Wyświetl plik

@ -238,12 +238,12 @@ final class S3ProxyHandler extends AbstractHandler {
baseRequest.setHandled(true); baseRequest.setHandled(true);
} catch (ContainerNotFoundException cnfe) { } catch (ContainerNotFoundException cnfe) {
S3ErrorCode code = S3ErrorCode.NO_SUCH_BUCKET; S3ErrorCode code = S3ErrorCode.NO_SUCH_BUCKET;
sendSimpleErrorResponse(response, code, code.getMessage(), sendSimpleErrorResponse(request, response, code, code.getMessage(),
ImmutableMap.<String, String>of()); ImmutableMap.<String, String>of());
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
} catch (S3Exception se) { } catch (S3Exception se) {
sendSimpleErrorResponse(response, se.getError(), sendSimpleErrorResponse(request, response, se.getError(),
se.getMessage(), se.getElements()); se.getMessage(), se.getElements());
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
@ -1817,15 +1817,23 @@ final class S3ProxyHandler extends AbstractHandler {
} }
} }
private void sendSimpleErrorResponse(HttpServletResponse response, private void sendSimpleErrorResponse(
HttpServletRequest request, HttpServletResponse response,
S3ErrorCode code, String message, S3ErrorCode code, String message,
Map<String, String> elements) throws IOException { Map<String, String> elements) throws IOException {
logger.debug("{} {}", code, elements); logger.debug("{} {}", code, elements);
response.setStatus(code.getHttpStatusCode());
if (request.getMethod().equals("HEAD")) {
// The HEAD method is identical to GET except that the server MUST
// NOT return a message-body in the response.
return;
}
try (Writer writer = response.getWriter()) { try (Writer writer = response.getWriter()) {
XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter( XMLStreamWriter xml = xmlOutputFactory.createXMLStreamWriter(
writer); writer);
response.setStatus(code.getHttpStatusCode());
xml.writeStartDocument(); xml.writeStartDocument();
xml.writeStartElement("Error"); xml.writeStartElement("Error");