Emit NoSuchBucket on head to non-existent bucket

Found with Ceph s3-tests.  References #5.
pull/16/head
Andrew Gaul 2014-07-29 15:58:28 -07:00
rodzic 1284c91e37
commit 88d521b11d
1 zmienionych plików z 11 dodań i 22 usunięć

Wyświetl plik

@ -80,6 +80,7 @@ final class S3ProxyHandler extends AbstractHandler {
int errorCode; int errorCode;
String method = request.getMethod(); String method = request.getMethod();
String uri = request.getRequestURI(); String uri = request.getRequestURI();
String[] path = uri.split("/", 3);
logger.debug("request: {}", request); logger.debug("request: {}", request);
switch (method) { switch (method) {
@ -92,7 +93,6 @@ final class S3ProxyHandler extends AbstractHandler {
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
} else { } else {
String[] path = uri.split("/", 3);
handleBlobRemove(response, path[1], path[2]); handleBlobRemove(response, path[1], path[2]);
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
@ -112,10 +112,7 @@ final class S3ProxyHandler extends AbstractHandler {
return; return;
} else if (uri.lastIndexOf("/") == 0 && } else if (uri.lastIndexOf("/") == 0 &&
"0".equals(request.getParameter("max-keys"))) { "0".equals(request.getParameter("max-keys"))) {
errorCode = handleContainerExists(uri.substring(1)); handleContainerExists(response, uri.substring(1));
if (errorCode != HttpServletResponse.SC_OK) {
response.sendError(errorCode);
}
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
} else if (uri.lastIndexOf("/") == 0) { } else if (uri.lastIndexOf("/") == 0) {
@ -128,27 +125,21 @@ final class S3ProxyHandler extends AbstractHandler {
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
} else { } else {
String[] path = uri.split("/", 3);
handleGetBlob(request, response, path[1], path[2]); handleGetBlob(request, response, path[1], path[2]);
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
} }
case "HEAD": case "HEAD":
if (uri.lastIndexOf("/") == 0) { if (path.length <= 2 || path[2].isEmpty()) {
errorCode = handleContainerExists(uri.substring(1)); handleContainerExists(response, uri.substring(1));
if (errorCode != HttpServletResponse.SC_OK) {
response.sendError(errorCode);
}
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
} else { } else {
String[] path = uri.split("/", 3);
handleBlobMetadata(response, path[1], path[2]); handleBlobMetadata(response, path[1], path[2]);
baseRequest.setHandled(true); baseRequest.setHandled(true);
return; return;
} }
case "PUT": case "PUT":
String[] path = uri.split("/", 3);
if (path.length <= 2 || path[2].isEmpty()) { if (path.length <= 2 || path[2].isEmpty()) {
handleContainerCreate(response, path[1]); handleContainerCreate(response, path[1]);
baseRequest.setHandled(true); baseRequest.setHandled(true);
@ -229,15 +220,13 @@ final class S3ProxyHandler extends AbstractHandler {
return HttpServletResponse.SC_OK; return HttpServletResponse.SC_OK;
} }
private int handleContainerExists(String containerName) { private void handleContainerExists(HttpServletResponse response,
try { String containerName) {
return blobStore.containerExists(containerName) if (!blobStore.containerExists(containerName)) {
? HttpServletResponse.SC_OK sendSimpleErrorResponse(response,
: HttpServletResponse.SC_NOT_FOUND; HttpServletResponse.SC_NOT_FOUND, "NoSuchBucket",
} catch (RuntimeException re) { "Not Found", Optional.<String>absent());
logger.error("Error determining container existence: {}", return;
re.getMessage());
return HttpServletResponse.SC_FORBIDDEN;
} }
} }