Skip to content

Commit 9820f47

Browse files
committed
Refactor readResponseContent() for decoding response before afterResponse(this) handling
1 parent 79a6590 commit 9820f47

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

client/src/main/java/io/avaje/http/client/DHttpClientRequest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ public HttpClientResponse TRACE() {
393393
}
394394

395395
private void readResponseContent() {
396-
final HttpResponse<byte[]> response = asByteArray();
397-
this.httpResponse = response;
398-
context.checkMaybeThrow(response);
396+
final HttpResponse<byte[]> response = sendWith(HttpResponse.BodyHandlers.ofByteArray());
399397
encodedResponseBody = context.readContent(response);
398+
context.afterResponse(this);
399+
context.checkMaybeThrow(response);
400400
}
401401

402402
@Override
@@ -436,11 +436,19 @@ public <T> Stream<T> stream(Class<T> cls) {
436436

437437
@Override
438438
public <T> HttpResponse<T> withHandler(HttpResponse.BodyHandler<T> responseHandler) {
439+
final HttpResponse<T> response = sendWith(responseHandler);
440+
context.afterResponse(this);
441+
return response;
442+
}
443+
444+
/**
445+
* Prepare and send the request but not performing afterResponse() handling.
446+
*/
447+
private <T> HttpResponse<T> sendWith(HttpResponse.BodyHandler<T> responseHandler) {
439448
context.beforeRequest(this);
440449
addHeaders();
441450
HttpResponse<T> response = performSend(responseHandler);
442451
httpResponse = response;
443-
context.afterResponse(this);
444452
return response;
445453
}
446454

0 commit comments

Comments
 (0)