diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketUpgradeHandler.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketUpgradeHandler.java index 651ccd984de..4e08dde927a 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketUpgradeHandler.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/WebSocketUpgradeHandler.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.websocket.core.server; import java.io.IOException; +import java.util.Objects; import java.util.function.Function; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -47,7 +48,7 @@ public class WebSocketUpgradeHandler extends HandlerWrapper public WebSocketUpgradeHandler(WebSocketNegotiator negotiator, String... pathSpecs) { - this.negotiator = negotiator; + this.negotiator = Objects.requireNonNull(negotiator); addPathSpec(pathSpecs); } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java index b7fd481cb94..9859f16664e 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC6455Handshaker.java @@ -68,24 +68,14 @@ public final class RFC6455Handshaker implements Handshaker public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, FrameHandler.Customizer defaultCustomizer) throws IOException { - final Request baseRequest = Request.getBaseRequest(request); - final HttpChannel httpChannel = baseRequest.getHttpChannel(); - final Connector connector = httpChannel.getConnector(); - - if (negotiator == null) - { - if (LOG.isDebugEnabled()) - LOG.debug("not upgraded: no WebSocketNegotiator {}", baseRequest); - return false; - } - if (!HttpMethod.GET.is(request.getMethod())) { if (LOG.isDebugEnabled()) - LOG.debug("not upgraded method!=GET {}", baseRequest); + LOG.debug("not upgraded method!=GET {}", request); return false; } + final Request baseRequest = Request.getBaseRequest(request); if (!HttpVersion.HTTP_1_1.equals(baseRequest.getHttpVersion())) { if (LOG.isDebugEnabled()) @@ -93,15 +83,7 @@ public final class RFC6455Handshaker implements Handshaker return false; } - ByteBufferPool pool = negotiator.getByteBufferPool(); - if (pool == null) - pool = baseRequest.getHttpChannel().getConnector().getByteBufferPool(); - - Negotiation negotiation = new Negotiation( - baseRequest, - request, - response, - new WebSocketComponents()); + Negotiation negotiation = new Negotiation(baseRequest, request, response, new WebSocketComponents()); if (LOG.isDebugEnabled()) LOG.debug("negotiation {}", negotiation); @@ -200,6 +182,8 @@ public final class RFC6455Handshaker implements Handshaker LOG.debug("session {}", coreSession); // Create a connection + HttpChannel httpChannel = baseRequest.getHttpChannel(); + Connector connector = httpChannel.getConnector(); WebSocketConnection connection = newWebSocketConnection(httpChannel.getEndPoint(), connector.getExecutor(), connector.getScheduler(), connector.getByteBufferPool(), coreSession); if (LOG.isDebugEnabled()) LOG.debug("connection {}", connection); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC8441Handshaker.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC8441Handshaker.java index 241e82a196c..60080b3c041 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC8441Handshaker.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/RFC8441Handshaker.java @@ -65,10 +65,14 @@ public class RFC8441Handshaker implements Handshaker @Override public boolean upgradeRequest(WebSocketNegotiator negotiator, HttpServletRequest request, HttpServletResponse response, FrameHandler.Customizer defaultCustomizer) throws IOException { - Request baseRequest = Request.getBaseRequest(request); - HttpChannel httpChannel = baseRequest.getHttpChannel(); - Connector connector = httpChannel.getConnector(); + if (!HttpMethod.CONNECT.is(request.getMethod())) + { + if (LOG.isDebugEnabled()) + LOG.debug("not upgraded method!=GET {}", request.toString()); + return false; + } + Request baseRequest = Request.getBaseRequest(request); if (!HttpVersion.HTTP_2.equals(baseRequest.getHttpVersion())) { if (LOG.isDebugEnabled()) @@ -76,24 +80,6 @@ public class RFC8441Handshaker implements Handshaker return false; } - if (!HttpMethod.CONNECT.is(request.getMethod())) - { - if (LOG.isDebugEnabled()) - LOG.debug("not upgraded method!=GET {}", baseRequest); - return false; - } - - if (negotiator == null) - { - if (LOG.isDebugEnabled()) - LOG.debug("not upgraded: no WebSocketNegotiator {}", baseRequest); - return false; - } - - ByteBufferPool pool = negotiator.getByteBufferPool(); - if (pool == null) - pool = baseRequest.getHttpChannel().getConnector().getByteBufferPool(); - Negotiation negotiation = new RFC8441Negotiation(baseRequest, request, response, new WebSocketComponents()); if (LOG.isDebugEnabled()) LOG.debug("negotiation {}", negotiation); @@ -189,8 +175,10 @@ public class RFC8441Handshaker implements Handshaker if (LOG.isDebugEnabled()) LOG.debug("coreSession {}", coreSession); - // Create a connection - EndPoint endPoint = baseRequest.getHttpChannel().getTunnellingEndPoint(); + // Create the Connection + HttpChannel httpChannel = baseRequest.getHttpChannel(); + Connector connector = httpChannel.getConnector(); + EndPoint endPoint = httpChannel.getTunnellingEndPoint(); WebSocketConnection connection = newWebSocketConnection(endPoint, connector.getExecutor(), connector.getScheduler(), connector.getByteBufferPool(), coreSession); if (LOG.isDebugEnabled()) LOG.debug("connection {}", connection);