From 7aad37952d87ae2e4674c0c01bddc657d821849a Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Mon, 23 Sep 2024 14:24:18 -0500 Subject: [PATCH] fix request body --- .../wagyourtail/jvmdg/j11/impl/http/HttpClientImpl.java | 6 ++++-- .../jvmdg/j11/stub/java_net_http/J_N_H_HttpRequest.java | 8 ++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/java-api/src/java11/java/xyz/wagyourtail/jvmdg/j11/impl/http/HttpClientImpl.java b/java-api/src/java11/java/xyz/wagyourtail/jvmdg/j11/impl/http/HttpClientImpl.java index 87b7551..0703d38 100644 --- a/java-api/src/java11/java/xyz/wagyourtail/jvmdg/j11/impl/http/HttpClientImpl.java +++ b/java-api/src/java11/java/xyz/wagyourtail/jvmdg/j11/impl/http/HttpClientImpl.java @@ -154,7 +154,7 @@ public void onSubscribe(Flow.Subscription subscription) { @Override public void onNext(ByteBuffer item) { try { - out.write(item.array()); + out.write(item.array(), item.arrayOffset() + item.position(), item.remaining()); } catch (IOException e) { Utils.sneakyThrow(e); } @@ -190,7 +190,9 @@ public void onComplete() { HttpResponseInfo info = new HttpResponseInfo(responseCode, new J_N_H_HttpHeaders(headers), version); J_N_H_HttpResponse.BodySubscriber subscriber = handler.apply(info); try (InputStream is = responseCode >= 400 ? connection.getErrorStream() : connection.getInputStream()) { - subscriber.onNext(List.of(ByteBuffer.wrap(is.readAllBytes()))); + if (is != null) { + subscriber.onNext(List.of(ByteBuffer.wrap(is.readAllBytes()))); + } subscriber.onComplete(); T body = subscriber.getBody().toCompletableFuture().join(); diff --git a/java-api/src/java11/java/xyz/wagyourtail/jvmdg/j11/stub/java_net_http/J_N_H_HttpRequest.java b/java-api/src/java11/java/xyz/wagyourtail/jvmdg/j11/stub/java_net_http/J_N_H_HttpRequest.java index adbaecc..f5c6ac9 100644 --- a/java-api/src/java11/java/xyz/wagyourtail/jvmdg/j11/stub/java_net_http/J_N_H_HttpRequest.java +++ b/java-api/src/java11/java/xyz/wagyourtail/jvmdg/j11/stub/java_net_http/J_N_H_HttpRequest.java @@ -178,9 +178,7 @@ public void request(long n) { return; } completed = true; - ByteBuffer buffer = ByteBuffer.wrap(bytes, offset, length); - buffer.flip(); - subscriber.onNext(buffer); + subscriber.onNext(ByteBuffer.wrap(bytes, offset, length)); subscriber.onComplete(); } @@ -220,9 +218,7 @@ public void request(long n) { } completed = true; try (InputStream is = Files.newInputStream(file)) { - ByteBuffer buffer = ByteBuffer.wrap(is.readAllBytes()); - buffer.flip(); - subscriber.onNext(buffer); + subscriber.onNext(ByteBuffer.wrap(is.readAllBytes())); subscriber.onComplete(); } catch (Exception e) { subscriber.onError(e);