From cf31ab2b9a642a574cf17ecb7b3c49b1d198404d Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Mon, 30 Dec 2019 13:38:05 +1100 Subject: [PATCH] Issue #4450 - don't expose ExtensionStack through getter on Negotation Signed-off-by: Lachlan Roberts --- .../websocket/core/server/Negotiation.java | 19 ------------------- .../server/internal/AbstractHandshaker.java | 13 ++++++++++--- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java index e7c46ac9d7f..8ded5db6316 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/Negotiation.java @@ -31,7 +31,6 @@ import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.QuotedCSV; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.websocket.core.Behavior; import org.eclipse.jetty.websocket.core.ExtensionConfig; import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.internal.ExtensionStack; @@ -184,24 +183,6 @@ public abstract class Negotiation extensionStack = null; } - public ExtensionStack getExtensionStack() - { - if (extensionStack == null) - { - // Extension stack can decide to drop any of these extensions or their parameters - extensionStack = new ExtensionStack(components, Behavior.SERVER); - extensionStack.negotiate(offeredExtensions, negotiatedExtensions); - negotiatedExtensions = extensionStack.getNegotiatedExtensions(); - - if (extensionStack.hasNegotiatedExtensions()) - baseRequest.getResponse().setHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, - ExtensionConfig.toHeaderValue(negotiatedExtensions)); - else - baseRequest.getResponse().setHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, null); - } - return extensionStack; - } - @Override public String toString() { diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java index 6647862e817..61c6b2e3c58 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/server/internal/AbstractHandshaker.java @@ -62,7 +62,8 @@ public abstract class AbstractHandshaker implements Handshaker if (!validateRequest(request)) return false; - Negotiation negotiation = newNegotiation(request, response, negotiator.getWebSocketComponents()); + WebSocketComponents components = negotiator.getWebSocketComponents(); + Negotiation negotiation = newNegotiation(request, response, components); if (LOG.isDebugEnabled()) LOG.debug("negotiation {}", negotiation); negotiation.negotiate(); @@ -123,8 +124,14 @@ public abstract class AbstractHandshaker implements Handshaker throw new WebSocketException("Upgrade failed: multiple negotiated extensions of the same name"); } - // Create and Negotiate the ExtensionStack - ExtensionStack extensionStack = negotiation.getExtensionStack(); + // Create and Negotiate the ExtensionStack. (ExtensionStack can drop any extensions or their parameters.) + ExtensionStack extensionStack = new ExtensionStack(components, Behavior.SERVER); + extensionStack.negotiate(negotiation.getOfferedExtensions(), negotiation.getNegotiatedExtensions()); + negotiation.setNegotiatedExtensions(extensionStack.getNegotiatedExtensions()); + if (extensionStack.hasNegotiatedExtensions()) + baseRequest.getResponse().setHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, ExtensionConfig.toHeaderValue(negotiation.getNegotiatedExtensions())); + else + baseRequest.getResponse().setHeader(HttpHeader.SEC_WEBSOCKET_EXTENSIONS, null); Negotiated negotiated = new Negotiated(baseRequest.getHttpURI().toURI(), protocol, baseRequest.isSecure(), extensionStack, WebSocketConstants.SPEC_VERSION_STRING);