Skip to content

Commit

Permalink
Added the response handler before, instead of only at the time we sen…
Browse files Browse the repository at this point in the history
…d the request. The reason is that the pump starts writing the upstream request before the #send() method is actually called, and if the server side already answers to that before we call #send(), we would have no handler installed yet.
  • Loading branch information
hoetdr-post committed Dec 18, 2024
1 parent 3d7b213 commit 5f0349e
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ public void handle(AsyncResult<HttpClientRequest> event) {
}
HttpClientRequest cReq = event.result();
final Handler<AsyncResult<HttpClientResponse>> cResHandler = getAsyncHttpClientResponseHandler(req, targetUri, log, profileHeaderMap, loggingHandler, finalStartTime, finalTimerSample, afterHandler);
cReq.response(cResHandler);

if (timeout != null) {
cReq.idleTimeout(Long.parseLong(timeout));
Expand Down Expand Up @@ -443,16 +444,16 @@ public WriteStream<Buffer> drainHandler(@Nullable Handler<Void> handler) {
// Setting the endHandler would then lead to an Exception
// see also https://github.com/eclipse-vertx/vert.x/issues/2763
// so we now check if the request already is ended before installing an endHandler
cReq.send(cResHandler);
cReq.send();
} else {
req.endHandler(v -> cReq.send(cResHandler));
req.endHandler(v -> cReq.send());
pump.start();
}
} else {
loggingHandler.appendRequestPayload(bodyData);
// we already have the body complete in-memory - so we can use Content-Length header and avoid chunked transfer
cReq.putHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bodyData.length()));
cReq.send(bodyData, cResHandler);
cReq.send(bodyData);
}

loggingHandler.request(cReq.headers());
Expand Down

0 comments on commit 5f0349e

Please sign in to comment.