DeflateFrameServerExtensionHandshaker implements WebSocketServerExtensionHandshaker { @Override public WebSocketServerExtension handshakeExtension(WebSocketExtensionData extensionData) { if (!X_WEBKIT_DEFLATE_FRAME_EXTENSION.equals(extensionData.name()) && !DEFLATE_FRAME_EXTENSION.equals(extensionData.name())) { return null; } if (extensionData.parameters().isEmpty()) { return new DeflateFrameServerExtension(compressionLevel, extensionData.name()); } else { return null; } } DeflateFrameServerExtensionHandshaker();  DeflateFrameServerExtensionHandshaker(int compressionLevel); @Override WebSocketServerExtension handshakeExtension(WebSocketExtensionData extensionData);  }
@Test public void testNormalHandshake() { DeflateFrameServerExtensionHandshaker handshaker = new DeflateFrameServerExtensionHandshaker(); WebSocketServerExtension extension = handshaker.handshakeExtension( new WebSocketExtensionData(DEFLATE_FRAME_EXTENSION, Collections.<String, String>emptyMap())); assertNotNull(extension); assertEquals(WebSocketServerExtension.RSV1, extension.rsv()); assertTrue(extension.newExtensionDecoder() instanceof PerFrameDeflateDecoder); assertTrue(extension.newExtensionEncoder() instanceof PerFrameDeflateEncoder); }
@Test public void testWebkitHandshake() { DeflateFrameServerExtensionHandshaker handshaker = new DeflateFrameServerExtensionHandshaker(); WebSocketServerExtension extension = handshaker.handshakeExtension( new WebSocketExtensionData(X_WEBKIT_DEFLATE_FRAME_EXTENSION, Collections.<String, String>emptyMap())); assertNotNull(extension); assertEquals(WebSocketServerExtension.RSV1, extension.rsv()); assertTrue(extension.newExtensionDecoder() instanceof PerFrameDeflateDecoder); assertTrue(extension.newExtensionEncoder() instanceof PerFrameDeflateEncoder); }
@Test public void testFailedHandshake() { DeflateFrameServerExtensionHandshaker handshaker = new DeflateFrameServerExtensionHandshaker(); Map<String, String> parameters; parameters = new HashMap<String, String>(); parameters.put("unknown", "11"); WebSocketServerExtension extension = handshaker.handshakeExtension( new WebSocketExtensionData(DEFLATE_FRAME_EXTENSION, parameters)); assertNull(extension); }