- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
          Generalize S3HttpHandler request matching
          #125670
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -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); | ||
|  | ||
|  | @@ -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) { | ||
|  | @@ -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(); | ||
|  | @@ -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); | ||
| } | ||
|  | ||
| 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); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A duplicate match for  There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...