Issue #4450 - don't expose ExtensionStack through getter on Negotation

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2019-12-30 13:38:05 +11:00
parent 0d571ef2c2
commit cf31ab2b9a
2 changed files with 10 additions and 22 deletions

View File

@ -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()
{

View File

@ -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);