Skip to content

Commit

Permalink
Merge pull request #620 from swisspost/bug-618-ResponseHandler-in-For…
Browse files Browse the repository at this point in the history
…warder-called-twice-per-request

Bug 618 response handler in forwarder called twice per request
  • Loading branch information
mcweba authored Jan 6, 2025
2 parents cedb622 + 5f0349e commit dc6591d
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void handle(AsyncResult<HttpClientRequest> 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)
Expand Down Expand Up @@ -444,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();

Check warning on line 447 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L447

Added line #L447 was not covered by tests
} else {
req.endHandler(v -> cReq.send(cResHandler));
req.endHandler(v -> cReq.send());

Check warning on line 449 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L449

Added line #L449 was not covered by tests
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);

Check warning on line 456 in gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java

View check run for this annotation

Codecov / codecov/patch

gateleen-routing/src/main/java/org/swisspush/gateleen/routing/Forwarder.java#L456

Added line #L456 was not covered by tests
}

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

0 comments on commit dc6591d

Please sign in to comment.