Skip to content

Commit

Permalink
fix request body
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Sep 23, 2024
1 parent 7d4f4ca commit 7aad379
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -190,7 +190,9 @@ public void onComplete() {
HttpResponseInfo info = new HttpResponseInfo(responseCode, new J_N_H_HttpHeaders(headers), version);
J_N_H_HttpResponse.BodySubscriber<T> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7aad379

Please sign in to comment.