Search in sources :

Example 1 with WebSocketExtensionData

use of io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData in project netty by netty.

the class WebSocketServerCompressionHandlerTest method testClientNoContext.

@Test
public void testClientNoContext() {
    EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerCompressionHandler());
    HttpRequest req = newUpgradeRequest(PERMESSAGE_DEFLATE_EXTENSION + "; " + CLIENT_NO_CONTEXT);
    ch.writeInbound(req);
    HttpResponse res = newUpgradeResponse(null);
    ch.writeOutbound(res);
    HttpResponse res2 = ch.readOutbound();
    List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
    Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
    Assert.assertTrue(exts.get(0).parameters().isEmpty());
    Assert.assertTrue(ch.pipeline().get(PerMessageDeflateDecoder.class) != null);
    Assert.assertTrue(ch.pipeline().get(PerMessageDeflateEncoder.class) != null);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponse(io.netty.handler.codec.http.HttpResponse) WebSocketExtensionData(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData) Test(org.junit.Test)

Example 2 with WebSocketExtensionData

use of io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData in project netty by netty.

the class DeflateFrameClientExtensionHandshakerTest method testFailedHandshake.

@Test
public void testFailedHandshake() {
    // initialize
    DeflateFrameClientExtensionHandshaker handshaker = new DeflateFrameClientExtensionHandshaker(false);
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("invalid", "12");
    // execute
    WebSocketClientExtension extension = handshaker.handshakeExtension(new WebSocketExtensionData(DEFLATE_FRAME_EXTENSION, parameters));
    // test
    assertNull(extension);
}
Also used : HashMap(java.util.HashMap) WebSocketClientExtension(io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension) WebSocketExtensionData(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData) Test(org.junit.Test)

Example 3 with WebSocketExtensionData

use of io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData in project netty by netty.

the class DeflateFrameServerExtensionHandshakerTest method testNormalHandshake.

@Test
public void testNormalHandshake() {
    // initialize
    DeflateFrameServerExtensionHandshaker handshaker = new DeflateFrameServerExtensionHandshaker();
    // execute
    WebSocketServerExtension extension = handshaker.handshakeExtension(new WebSocketExtensionData(DEFLATE_FRAME_EXTENSION, Collections.<String, String>emptyMap()));
    // test
    assertNotNull(extension);
    assertEquals(WebSocketServerExtension.RSV1, extension.rsv());
    assertTrue(extension.newExtensionDecoder() instanceof PerFrameDeflateDecoder);
    assertTrue(extension.newExtensionEncoder() instanceof PerFrameDeflateEncoder);
}
Also used : WebSocketServerExtension(io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension) DeflateFrameServerExtensionHandshaker(io.netty.handler.codec.http.websocketx.extensions.compression.DeflateFrameServerExtensionHandshaker) WebSocketExtensionData(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData) Test(org.junit.Test)

Example 4 with WebSocketExtensionData

use of io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData in project netty by netty.

the class PerMessageDeflateClientExtensionHandshakerTest method testNormalHandshake.

@Test
public void testNormalHandshake() {
    PerMessageDeflateClientExtensionHandshaker handshaker = new PerMessageDeflateClientExtensionHandshaker();
    WebSocketClientExtension extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, Collections.<String, String>emptyMap()));
    assertNotNull(extension);
    assertEquals(WebSocketClientExtension.RSV1, extension.rsv());
    assertTrue(extension.newExtensionDecoder() instanceof PerMessageDeflateDecoder);
    assertTrue(extension.newExtensionEncoder() instanceof PerMessageDeflateEncoder);
}
Also used : WebSocketClientExtension(io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension) WebSocketExtensionData(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData) Test(org.junit.Test)

Example 5 with WebSocketExtensionData

use of io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData in project netty by netty.

the class WebSocketServerCompressionHandlerTest method testClientWindowSizeUnavailable.

@Test
public void testClientWindowSizeUnavailable() {
    EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerExtensionHandler(new PerMessageDeflateServerExtensionHandshaker(6, false, 10, false, false)));
    HttpRequest req = newUpgradeRequest(PERMESSAGE_DEFLATE_EXTENSION);
    ch.writeInbound(req);
    HttpResponse res = newUpgradeResponse(null);
    ch.writeOutbound(res);
    HttpResponse res2 = ch.readOutbound();
    List<WebSocketExtensionData> exts = WebSocketExtensionUtil.extractExtensions(res2.headers().get(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
    Assert.assertEquals(PERMESSAGE_DEFLATE_EXTENSION, exts.get(0).name());
    Assert.assertTrue(exts.get(0).parameters().isEmpty());
    Assert.assertTrue(ch.pipeline().get(PerMessageDeflateDecoder.class) != null);
    Assert.assertTrue(ch.pipeline().get(PerMessageDeflateEncoder.class) != null);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponse(io.netty.handler.codec.http.HttpResponse) WebSocketServerExtensionHandler(io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler) PerMessageDeflateServerExtensionHandshaker(io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateServerExtensionHandshaker) WebSocketExtensionData(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData) Test(org.junit.Test)

Aggregations

WebSocketExtensionData (io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData)19 Test (org.junit.Test)19 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)6 HttpRequest (io.netty.handler.codec.http.HttpRequest)6 HttpResponse (io.netty.handler.codec.http.HttpResponse)6 PerMessageDeflateServerExtensionHandshaker (io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateServerExtensionHandshaker)6 WebSocketServerExtension (io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension)5 WebSocketClientExtension (io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension)4 WebSocketServerExtensionHandler (io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler)4 DeflateFrameServerExtensionHandshaker (io.netty.handler.codec.http.websocketx.extensions.compression.DeflateFrameServerExtensionHandshaker)3 HashMap (java.util.HashMap)1