Skip to content

Commit

Permalink
Merge pull request #561 from GDATASoftwareAG/java/disable-http2
Browse files Browse the repository at this point in the history
java: Disable HTTP/2 in file + stream uploads
  • Loading branch information
doxthree authored Aug 20, 2024
2 parents ac7b450 + f6f2dc5 commit ca51997
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions java/src/main/java/de/gdata/vaas/Vaas.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,33 +543,23 @@ private CompletableFuture<VerdictResponse> forFileAsync(Path file, UUID guid,

private CompletableFuture<Void> uploadFile(Path file, String url, String authToken)
throws IOException, URISyntaxException {

var builder = HttpRequest
.newBuilder(new URI(url))
.header("Authorization", authToken)
.version(Version.HTTP_1_1)
.PUT(HttpRequest.BodyPublishers.ofFile(file));
var request = builder.build();

var futureResponse = this.httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofString());

return futureResponse.thenAccept(response -> {
if (response.statusCode() != 200) {
throwAsUnchecked(new IOException(
"Failed to upload file. HTTP Status Code: " + response.statusCode() + " Error: "
+ response.body()));
}
});
var bodyPublisher = HttpRequest.BodyPublishers.ofFile(file);
return uploadInternal(bodyPublisher, url, authToken);
}

private CompletableFuture<Void> uploadStream(InputStream stream, long contentLength, String url, String authToken)
throws URISyntaxException {
var bodyPublisher = BodyPublishers.fromPublisher(BodyPublishers.ofInputStream(() -> stream), contentLength);
return uploadInternal(bodyPublisher, url, authToken);
}

private CompletableFuture<Void> uploadInternal(HttpRequest.BodyPublisher body, String url, String authToken)
throws URISyntaxException {
var request = HttpRequest
.newBuilder(new URI(url))
.header("Authorization", authToken)
.PUT(bodyPublisher)
.version(Version.HTTP_1_1)
.PUT(body)
.build();

var futureResponse = this.httpClient
Expand Down

0 comments on commit ca51997

Please sign in to comment.