From 949aa6c3429061f96c4966bb9adbe6bef58af229 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 27 Aug 2021 11:53:54 +1000 Subject: [PATCH] Issue #6642 - move shutdown logic into HttpChannelOverHTTP and HttpConnection Signed-off-by: Lachlan Roberts --- .../eclipse/jetty/client/http/HttpChannelOverHTTP.java | 2 +- .../main/java/org/eclipse/jetty/http/HttpGenerator.java | 9 --------- .../java/org/eclipse/jetty/server/HttpConnection.java | 5 ++++- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpChannelOverHTTP.java b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpChannelOverHTTP.java index 901857f4858..d1750e2bac5 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpChannelOverHTTP.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/http/HttpChannelOverHTTP.java @@ -103,7 +103,7 @@ public class HttpChannelOverHTTP extends HttpChannel closeReason = "failure"; else if (receiver.isShutdown()) closeReason = "server close"; - else if (sender.isShutdown()) + else if (sender.isShutdown() && response.getStatus() != HttpStatus.SWITCHING_PROTOCOLS_101) closeReason = "client close"; if (closeReason == null) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java index 5cefc3002fe..bce11e13b75 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java @@ -345,15 +345,6 @@ public class HttpGenerator return Result.FLUSH; } _state = State.END; - - // If this is a request, don't close the connection until the server responds. - if (_info.isRequest()) - return Result.DONE; - - // If successfully upgraded it is responsibility of the next protocol to close the connection. - if (_info.isResponse() && ((MetaData.Response)_info).getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101) - return Result.DONE; - return Boolean.TRUE.equals(_persistent) ? Result.DONE : Result.SHUTDOWN_OUT; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 728214a7572..d34b9f7b924 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeaderValue; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.HttpParser; +import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.http.PreEncodedHttpField; import org.eclipse.jetty.io.AbstractConnection; @@ -885,8 +886,10 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http @Override protected void onCompleteSuccess() { + boolean upgrading = _info.getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101; release().succeeded(); - if (_shutdownOut) + // If successfully upgraded it is responsibility of the next protocol to close the connection. + if (_shutdownOut && !upgrading) getEndPoint().shutdownOutput(); }