Skip to content
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

Fix GCS Mock Http Handler JDK Bug (#51933) #51944

Merged
merged 1 commit into from
Feb 5, 2020
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 @@ -88,7 +88,7 @@ public void handle(final HttpExchange exchange) throws IOException {
}
try {
// Request body is closed in the finally block
final InputStream wrappedRequest = Streams.noCloseStream(exchange.getRequestBody());
final BytesReference requestBody = Streams.readFully(Streams.noCloseStream(exchange.getRequestBody()));
if (Regex.simpleMatch("GET /storage/v1/b/" + bucket + "/o*", request)) {
// List Objects https://cloud.google.com/storage/docs/json_api/v1/objects/list
final Map<String, String> params = new HashMap<>();
Expand Down Expand Up @@ -155,7 +155,7 @@ public void handle(final HttpExchange exchange) throws IOException {
// Batch https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch
final String uri = "/storage/v1/b/" + bucket + "/o/";
final StringBuilder batch = new StringBuilder();
for (String line : Streams.readAllLines(wrappedRequest)) {
for (String line : Streams.readAllLines(requestBody.streamInput())) {
if (line.length() == 0 || line.startsWith("--") || line.toLowerCase(Locale.ROOT).startsWith("content")) {
batch.append(line).append('\n');
} else if (line.startsWith("DELETE")) {
Expand All @@ -174,7 +174,7 @@ public void handle(final HttpExchange exchange) throws IOException {

} else if (Regex.simpleMatch("POST /upload/storage/v1/b/" + bucket + "/*uploadType=multipart*", request)) {
// Multipart upload
Optional<Tuple<String, BytesReference>> content = parseMultipartRequestBody(wrappedRequest);
Optional<Tuple<String, BytesReference>> content = parseMultipartRequestBody(requestBody.streamInput());
if (content.isPresent()) {
blobs.put(content.get().v1(), content.get().v2());

Expand All @@ -194,7 +194,7 @@ public void handle(final HttpExchange exchange) throws IOException {
final String blobName = params.get("name");
blobs.put(blobName, BytesArray.EMPTY);

byte[] response = Streams.readFully(wrappedRequest).utf8ToString().getBytes(UTF_8);
byte[] response = requestBody.utf8ToString().getBytes(UTF_8);
exchange.getResponseHeaders().add("Content-Type", "application/json");
exchange.getResponseHeaders().add("Location", httpServerUrl(exchange) + "/upload/storage/v1/b/" + bucket + "/o?"
+ "uploadType=resumable"
Expand All @@ -219,7 +219,7 @@ public void handle(final HttpExchange exchange) throws IOException {
final int start = getContentRangeStart(range);
final int end = getContentRangeEnd(range);

blob = new CompositeBytesReference(blob, Streams.readFully(wrappedRequest));
blob = new CompositeBytesReference(blob, requestBody);
blobs.put(blobName, blob);

if (limit == null) {
Expand Down