Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void handle(final HttpExchange exchange) throws IOException {
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), response.length);
exchange.getResponseBody().write(response);

} else if (Regex.simpleMatch("PUT /" + path + "/*?uploadId=*&partNumber=*", request)) {
} else if (isUploadPartRequest(request)) {
final Map<String, String> params = new HashMap<>();
RestUtils.decodeQueryString(request, request.indexOf('?') + 1, params);

Expand Down Expand Up @@ -213,7 +213,7 @@ public void handle(final HttpExchange exchange) throws IOException {
exchange.getResponseHeaders().add("ETag", blob.v1());
exchange.sendResponseHeaders(RestStatus.OK.getStatus(), -1);

} else if (Regex.simpleMatch("GET /" + bucket + "/?prefix=*", request)) {
} else if (isListObjectsRequest(request)) {
final Map<String, String> params = new HashMap<>();
RestUtils.decodeQueryString(request, request.indexOf('?') + 1, params);
if (params.get("list-type") != null) {
Expand Down Expand Up @@ -315,7 +315,7 @@ public void handle(final HttpExchange exchange) throws IOException {
}
exchange.sendResponseHeaders((deletions > 0 ? RestStatus.OK : RestStatus.NO_CONTENT).getStatus(), -1);

} else if (Regex.simpleMatch("POST /" + bucket + "/?delete", request)) {
} else if (isMultiObjectDeleteRequest(request)) {
final String requestBody = Streams.copyToString(new InputStreamReader(exchange.getRequestBody(), UTF_8));

final StringBuilder deletes = new StringBuilder();
Expand All @@ -337,16 +337,36 @@ public void handle(final HttpExchange exchange) throws IOException {
exchange.getResponseBody().write(response);

} else {
logger.error("unknown request: {}", request);
exchange.sendResponseHeaders(RestStatus.INTERNAL_SERVER_ERROR.getStatus(), -1);
}
} catch (Exception e) {
logger.error("exception in request " + request, e);
throw e;
} finally {
exchange.close();
}
}

private boolean isUploadPartRequest(String request) {
return Regex.simpleMatch("PUT /" + path + "/*?uploadId=*&partNumber=*", request)
|| Regex.simpleMatch("PUT /" + path + "/*?partNumber=*&uploadId=*", request);
Copy link
Contributor

@DiannaHohensee DiannaHohensee Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you distinguish between the V1 vs V2 request formats in the methods, and add a todo someplace? I'm imagining that we should clean up and remove the V1 formats after the upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened ES-11379. Honestly this is all hideous, we should be parsing the request properly, but it's only a test fixture...

}

private boolean isListMultipartUploadsRequest(String request) {
return Regex.simpleMatch("GET /" + bucket + "/?uploads&prefix=*", request)
|| Regex.simpleMatch("GET /" + bucket + "/?uploads&max-uploads=*&prefix=*", request);
|| Regex.simpleMatch("GET /" + bucket + "/?uploads&max-uploads=*&prefix=*", request)
|| Regex.simpleMatch("GET /" + bucket + "?uploads&prefix=*", request)
|| Regex.simpleMatch("GET /" + bucket + "?uploads&max-uploads=*&prefix=*", request);
Copy link
Contributor

@mhl-b mhl-b Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A duplicate match for /?uploads&max-uploads=*&prefix=*? line 358.
Pattern.compile("GET \/bucket(\/)?\?uploads&(max-uploads=.*&)?prefix=.*")? Who needs simpleMatch when you can do complex match?:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a duplicate, one has an extra / :)

}

private boolean isListObjectsRequest(String request) {
return Regex.simpleMatch("GET /" + bucket + "/?prefix=*", request)
|| Regex.simpleMatch("GET /" + bucket + "?list-type=2&*prefix=*", request);
}

private boolean isMultiObjectDeleteRequest(String request) {
return request.equals("POST /" + bucket + "/?delete") || request.equals("POST /" + bucket + "?delete");
}

public Map<String, BytesReference> blobs() {
Expand Down