Issue #4450 - websocket Extensions no longer rely upon WSCoreSession
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
c98897315c
commit
0d571ef2c2
|
@ -26,7 +26,7 @@ import org.eclipse.jetty.util.compression.DeflaterPool;
|
|||
import org.eclipse.jetty.util.compression.InflaterPool;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler.Configuration;
|
||||
|
||||
@ManagedObject("Abstract Extension")
|
||||
public class AbstractExtension implements Extension
|
||||
|
@ -36,7 +36,7 @@ public class AbstractExtension implements Extension
|
|||
private ExtensionConfig config;
|
||||
private OutgoingFrames nextOutgoing;
|
||||
private IncomingFrames nextIncoming;
|
||||
private WebSocketCoreSession coreSession;
|
||||
private Configuration configuration;
|
||||
private DeflaterPool deflaterPool;
|
||||
private InflaterPool inflaterPool;
|
||||
|
||||
|
@ -169,14 +169,14 @@ public class AbstractExtension implements Extension
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setWebSocketCoreSession(WebSocketCoreSession coreSession)
|
||||
public void setConfiguration(Configuration configuration)
|
||||
{
|
||||
this.coreSession = coreSession;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
protected WebSocketCoreSession getWebSocketCoreSession()
|
||||
protected Configuration getConfiguration()
|
||||
{
|
||||
return coreSession;
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.core;
|
||||
|
||||
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler.Configuration;
|
||||
|
||||
/**
|
||||
* Interface for WebSocket Extensions.
|
||||
|
@ -88,7 +88,7 @@ public interface Extension extends IncomingFrames, OutgoingFrames
|
|||
void setNextOutgoingFrames(OutgoingFrames nextOutgoing);
|
||||
|
||||
/**
|
||||
* Set the {@link WebSocketCoreSession} for this Extension
|
||||
* Set the {@link Configuration} for this Extension.
|
||||
*/
|
||||
void setWebSocketCoreSession(WebSocketCoreSession coreSession);
|
||||
void setConfiguration(Configuration configuration);
|
||||
}
|
||||
|
|
|
@ -254,7 +254,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable
|
|||
|
||||
for (Extension extension : extensions)
|
||||
{
|
||||
extension.setWebSocketCoreSession(coreSession);
|
||||
extension.setConfiguration(coreSession);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ public class PerMessageDeflateExtension extends AbstractExtension
|
|||
private boolean deflate(Callback callback)
|
||||
{
|
||||
// Get a buffer for the inflated payload.
|
||||
long maxFrameSize = getWebSocketCoreSession().getMaxFrameSize();
|
||||
long maxFrameSize = getConfiguration().getMaxFrameSize();
|
||||
int bufferSize = (maxFrameSize <= 0) ? deflateBufferSize : (int)Math.min(maxFrameSize, deflateBufferSize);
|
||||
final ByteBuffer buffer = getBufferPool().acquire(bufferSize, false);
|
||||
callback = Callback.from(callback, () -> getBufferPool().release(buffer));
|
||||
|
@ -289,7 +289,7 @@ public class PerMessageDeflateExtension extends AbstractExtension
|
|||
if (buffer.limit() == bufferSize)
|
||||
{
|
||||
// We need to fragment. TODO: what if there was only bufferSize of content?
|
||||
if (!getWebSocketCoreSession().isAutoFragment())
|
||||
if (!getConfiguration().isAutoFragment())
|
||||
throw new MessageTooLargeException("Deflated payload exceeded the compress buffer size");
|
||||
break;
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ public class PerMessageDeflateExtension extends AbstractExtension
|
|||
private boolean inflate(Callback callback) throws DataFormatException
|
||||
{
|
||||
// Get a buffer for the inflated payload.
|
||||
long maxFrameSize = getWebSocketCoreSession().getMaxFrameSize();
|
||||
long maxFrameSize = getConfiguration().getMaxFrameSize();
|
||||
int bufferSize = (maxFrameSize <= 0) ? inflateBufferSize : (int)Math.min(maxFrameSize, inflateBufferSize);
|
||||
final ByteBuffer payload = getBufferPool().acquire(bufferSize, false);
|
||||
callback = Callback.from(callback, () -> getBufferPool().release(payload));
|
||||
|
@ -421,7 +421,7 @@ public class PerMessageDeflateExtension extends AbstractExtension
|
|||
if (payload.limit() == bufferSize)
|
||||
{
|
||||
// We need to fragment. TODO: what if there was only bufferSize of content?
|
||||
if (!getWebSocketCoreSession().isAutoFragment())
|
||||
if (!getConfiguration().isAutoFragment())
|
||||
throw new MessageTooLargeException("Inflated payload exceeded the decompress buffer size");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
import org.eclipse.jetty.websocket.core.AbstractExtension;
|
||||
import org.eclipse.jetty.websocket.core.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.core.Frame;
|
||||
import org.eclipse.jetty.websocket.core.FrameHandler;
|
||||
import org.eclipse.jetty.websocket.core.NullAppendable;
|
||||
import org.eclipse.jetty.websocket.core.ProtocolException;
|
||||
import org.eclipse.jetty.websocket.core.WebSocketComponents;
|
||||
|
@ -38,6 +39,7 @@ public class ValidationExtension extends AbstractExtension
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(ValidationExtension.class);
|
||||
|
||||
private WebSocketCoreSession coreSession;
|
||||
private FrameSequence incomingSequence = null;
|
||||
private FrameSequence outgoingSequence = null;
|
||||
private boolean incomingFrameValidation = false;
|
||||
|
@ -53,6 +55,16 @@ public class ValidationExtension extends AbstractExtension
|
|||
return "@validation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfiguration(FrameHandler.Configuration configuration)
|
||||
{
|
||||
super.setConfiguration(configuration);
|
||||
|
||||
if (!(configuration instanceof WebSocketCoreSession))
|
||||
throw new IllegalArgumentException("ValidationExtension needs a CoreSession Configuration");
|
||||
coreSession = (WebSocketCoreSession)configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFrame(Frame frame, Callback callback)
|
||||
{
|
||||
|
@ -62,7 +74,7 @@ public class ValidationExtension extends AbstractExtension
|
|||
incomingSequence.check(frame.getOpCode(), frame.isFin());
|
||||
|
||||
if (incomingFrameValidation)
|
||||
getWebSocketCoreSession().assertValidIncoming(frame);
|
||||
coreSession.assertValidIncoming(frame);
|
||||
|
||||
if (incomingUtf8Validation != null)
|
||||
validateUTF8(frame, incomingUtf8Validation, continuedInOpCode);
|
||||
|
@ -85,7 +97,7 @@ public class ValidationExtension extends AbstractExtension
|
|||
outgoingSequence.check(frame.getOpCode(), frame.isFin());
|
||||
|
||||
if (outgoingFrameValidation)
|
||||
getWebSocketCoreSession().assertValidOutgoing(frame);
|
||||
coreSession.assertValidOutgoing(frame);
|
||||
|
||||
if (outgoingUtf8Validation != null)
|
||||
validateUTF8(frame, outgoingUtf8Validation, continuedOutOpCode);
|
||||
|
|
|
@ -77,7 +77,7 @@ public class ExtensionTool
|
|||
{
|
||||
this.ext = components.getExtensionRegistry().newInstance(extConfig, components);
|
||||
this.ext.setNextIncomingFrames(capture);
|
||||
this.ext.setWebSocketCoreSession(newWebSocketCoreSession());
|
||||
this.ext.setConfiguration(newWebSocketCoreSession());
|
||||
}
|
||||
|
||||
public void parseIncomingHex(String... rawhex)
|
||||
|
|
|
@ -135,7 +135,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
|
|||
|
||||
tester.assertNegotiated("permessage-deflate");
|
||||
|
||||
tester.parseIncomingHex( // context takeover (2 messages)
|
||||
tester.parseIncomingHex(// context takeover (2 messages)
|
||||
// message 1
|
||||
"0xc1 0x07", // (HEADER added for this test)
|
||||
"0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00",
|
||||
|
@ -376,7 +376,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
|
|||
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
|
||||
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
|
||||
ext.init(config, components);
|
||||
ext.setWebSocketCoreSession(newSession());
|
||||
ext.setConfiguration(newSession());
|
||||
|
||||
// Setup capture of incoming frames
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
|
@ -450,7 +450,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
|
|||
{
|
||||
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
|
||||
ext.init(ExtensionConfig.parse("permessage-deflate"), components);
|
||||
ext.setWebSocketCoreSession(newSession());
|
||||
ext.setConfiguration(newSession());
|
||||
|
||||
// Setup capture of outgoing frames
|
||||
OutgoingFramesCapture capture = new OutgoingFramesCapture();
|
||||
|
@ -497,7 +497,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
|
|||
PerMessageDeflateExtension ext = new PerMessageDeflateExtension();
|
||||
ExtensionConfig config = ExtensionConfig.parse("permessage-deflate");
|
||||
ext.init(config, components);
|
||||
ext.setWebSocketCoreSession(newSession());
|
||||
ext.setConfiguration(newSession());
|
||||
|
||||
// Setup capture of incoming frames
|
||||
OutgoingFramesCapture capture = new OutgoingFramesCapture();
|
||||
|
@ -548,7 +548,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest
|
|||
|
||||
// Captured from Pywebsocket (r790) - "tora" sent 3 times.
|
||||
|
||||
tester.parseIncomingHex( // context takeover (3 messages)
|
||||
tester.parseIncomingHex(// context takeover (3 messages)
|
||||
"c1 06 2a c9 2f 4a 04 00", // tora 1
|
||||
"c1 05 2a 01 62 00 00", // tora 2
|
||||
"c1 04 02 61 00 00" // tora 3
|
||||
|
|
Loading…
Reference in New Issue