Improve Content-Length error handling

Found with Ceph s3-tests.  References #5.
pull/16/head
Andrew Gaul 2014-07-28 00:42:44 -07:00
rodzic a6c997d71c
commit 5c843eb272
1 zmienionych plików z 31 dodań i 1 usunięć

Wyświetl plik

@ -459,13 +459,16 @@ final class S3ProxyHandler extends AbstractHandler {
String blobName) throws IOException {
// Flag headers present since HttpServletResponse.getHeader returns
// null for empty headers.
boolean hasContentLength = false;
boolean hasContentMD5 = false;
ImmutableMap.Builder<String, String> userMetadata =
ImmutableMap.builder();
Enumeration<String> enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String headerName = enumeration.nextElement();
if (headerName.equals(HttpHeaders.CONTENT_MD5)) {
if (headerName.equals(HttpHeaders.CONTENT_LENGTH)) {
hasContentLength = true;
} else if (headerName.equals(HttpHeaders.CONTENT_MD5)) {
hasContentMD5 = true;
} else if (headerName.toLowerCase().startsWith(
USER_METADATA_PREFIX)) {
@ -498,6 +501,33 @@ final class S3ProxyHandler extends AbstractHandler {
}
}
if (!hasContentLength) {
sendSimpleErrorResponse(response,
HttpServletResponse.SC_LENGTH_REQUIRED,
"MissingContentLength", "Length Required",
Optional.<String>absent());
return;
}
long contentLength = 0;
boolean validContentLength = true;
String contentLengthString = request.getHeader(
HttpHeaders.CONTENT_LENGTH);
if (contentLengthString == null) {
validContentLength = false;
} else {
try {
contentLength = Long.parseLong(contentLengthString);
} catch (NumberFormatException nfe) {
validContentLength = false;
}
}
if (!validContentLength || contentLength < 0) {
sendSimpleErrorResponse(response,
HttpServletResponse.SC_BAD_REQUEST, "InvalidArgument",
"Invalid Argument", Optional.<String>absent());
return;
}
try (InputStream is = request.getInputStream()) {
BlobBuilder.PayloadBlobBuilder builder = blobStore
.blobBuilder(blobName)