Skip to content

Commit

Permalink
Store bytes in HTTP Responses to allow for subsequent reads
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodrobins committed Aug 27, 2024
1 parent 3ad57cf commit 039ca4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,15 @@ void error() {
ex -> {
assertThat(ex.getResponse())
.isNotNull()
.extracting(HttpSender.Response::statusCode)
.isEqualTo(statusCode);
.satisfies(
response -> {
assertThat(response)
.extracting(HttpSender.Response::statusCode)
.isEqualTo(statusCode);

assertThatCode(response::responseBody).doesNotThrowAnyException();
});

assertThat(ex.getCause()).isNull();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public void onResponse(Call call, okhttp3.Response response) {
try (ResponseBody body = response.body()) {
onResponse.accept(
new Response() {
@Nullable private byte[] bodyBytes;

@Override
public int statusCode() {
return response.code();
Expand All @@ -155,7 +157,10 @@ public String statusMessage() {

@Override
public byte[] responseBody() throws IOException {
return body.bytes();
if (bodyBytes == null) {
bodyBytes = body.bytes();
}
return bodyBytes;
}
});
}
Expand Down

0 comments on commit 039ca4c

Please sign in to comment.