Skip to content

Commit

Permalink
[notificationsforfiretv] Missing Content-Length (#521) (#569)
Browse files Browse the repository at this point in the history
* fixed: missing Content-Length header (BodyPublisher.ofByteArrays JDK 17 issue)

Signed-off-by: Tom Blum [email protected]
  • Loading branch information
Trinitus01 authored Mar 23, 2024
1 parent 7fc9b63 commit 5746302
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublisher;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
Expand Down Expand Up @@ -103,9 +104,15 @@ public void addFilePart(String name, File file) throws IOException {
public String send() throws IOException, InterruptedException {
byteArrays.add(("--" + boundary + "--").getBytes(StandardCharsets.UTF_8));

int length = 0;
for (byte[] bytes : byteArrays) {
length += bytes.length;
}

BodyPublisher bodyPublisher = BodyPublishers.fromPublisher(BodyPublishers.ofByteArrays(byteArrays), length);
HttpRequest httpRequest = HttpRequest.newBuilder()
.header("Content-Type", "multipart/form-data;boundary=" + boundary)
.POST(BodyPublishers.ofByteArrays(byteArrays)).uri(uri).build();
.header("Content-Type", "multipart/form-data;boundary=" + boundary).POST(bodyPublisher).uri(uri)
.build();
HttpResponse<String> response = httpClient.send(httpRequest, BodyHandlers.ofString());
if (response.statusCode() == HttpURLConnection.HTTP_OK) {
return response.body();
Expand Down

0 comments on commit 5746302

Please sign in to comment.