From 3d7b2138ff70b1108624e100bd99ae53e424533d Mon Sep 17 00:00:00 2001 From: Dries Hoet Date: Tue, 17 Dec 2024 16:38:57 +0100 Subject: [PATCH 1/2] Not adding response handler twice anymore. --- .../main/java/org/swisspush/gateleen/routing/Forwarder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java index 9eb2a718..92f062d7 100755 --- a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java +++ b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java @@ -313,7 +313,6 @@ public void handle(AsyncResult event) { } HttpClientRequest cReq = event.result(); final Handler> cResHandler = getAsyncHttpClientResponseHandler(req, targetUri, log, profileHeaderMap, loggingHandler, finalStartTime, finalTimerSample, afterHandler); - cReq.response(cResHandler); if (timeout != null) { cReq.idleTimeout(Long.parseLong(timeout)); @@ -358,7 +357,7 @@ public void handle(AsyncResult event) { */ if (bodyData == null) { - // Gateleen internal requests (e.g. from scedulers or delegates) often have neither "Content-Length" nor "Transfer-Encoding: chunked" + // Gateleen internal requests (e.g. from schedulers or delegates) often have neither "Content-Length" nor "Transfer-Encoding: chunked" // header - so we must wait for a body buffer to know: Is there a body or not? Only looking on the headers and/or the http-method is not // sustainable to know "has body or not" // But: if there is a body, then we need to either setChunked or a Content-Length header (otherwise Vertx complains with an Exception) From 5f0349e8de7a44d4d6f0660d28b649b7d842afaa Mon Sep 17 00:00:00 2001 From: Dries Hoet Date: Wed, 18 Dec 2024 13:55:01 +0100 Subject: [PATCH 2/2] Added the response handler before, instead of only at the time we send 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. --- .../java/org/swisspush/gateleen/routing/Forwarder.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java index 92f062d7..e9ceccff 100755 --- a/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java +++ b/gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java @@ -313,6 +313,7 @@ public void handle(AsyncResult event) { } HttpClientRequest cReq = event.result(); final Handler> cResHandler = getAsyncHttpClientResponseHandler(req, targetUri, log, profileHeaderMap, loggingHandler, finalStartTime, finalTimerSample, afterHandler); + cReq.response(cResHandler); if (timeout != null) { cReq.idleTimeout(Long.parseLong(timeout)); @@ -443,16 +444,16 @@ public WriteStream drainHandler(@Nullable Handler 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());