Search in sources :

Example 6 with WebSocketExtensionData

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

the class PerMessageDeflateClientExtensionHandshakerTest method testCustomHandshake.

@Test
public void testCustomHandshake() {
    WebSocketClientExtension extension;
    Map<String, String> parameters;
    // initialize
    PerMessageDeflateClientExtensionHandshaker handshaker = new PerMessageDeflateClientExtensionHandshaker(6, true, 10, true, true);
    parameters = new HashMap<String, String>();
    parameters.put(CLIENT_MAX_WINDOW, "12");
    parameters.put(SERVER_MAX_WINDOW, "10");
    parameters.put(CLIENT_NO_CONTEXT, null);
    parameters.put(SERVER_NO_CONTEXT, null);
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, parameters));
    // test
    assertNotNull(extension);
    assertEquals(WebSocketClientExtension.RSV1, extension.rsv());
    assertTrue(extension.newExtensionDecoder() instanceof PerMessageDeflateDecoder);
    assertTrue(extension.newExtensionEncoder() instanceof PerMessageDeflateEncoder);
    // initialize
    parameters = new HashMap<String, String>();
    parameters.put(SERVER_MAX_WINDOW, "10");
    parameters.put(SERVER_NO_CONTEXT, null);
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, parameters));
    // test
    assertNotNull(extension);
    assertEquals(WebSocketClientExtension.RSV1, extension.rsv());
    assertTrue(extension.newExtensionDecoder() instanceof PerMessageDeflateDecoder);
    assertTrue(extension.newExtensionEncoder() instanceof PerMessageDeflateEncoder);
    // initialize
    parameters = new HashMap<String, String>();
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, parameters));
    // test
    assertNull(extension);
}
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 7 with WebSocketExtensionData

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

the class PerMessageDeflateClientExtensionHandshakerTest method testCustomData.

@Test
public void testCustomData() {
    PerMessageDeflateClientExtensionHandshaker handshaker = new PerMessageDeflateClientExtensionHandshaker(6, true, 10, true, true);
    WebSocketExtensionData data = handshaker.newRequestData();
    assertEquals(PERMESSAGE_DEFLATE_EXTENSION, data.name());
    assertTrue(data.parameters().containsKey(CLIENT_MAX_WINDOW));
    assertTrue(data.parameters().containsKey(SERVER_MAX_WINDOW));
    assertTrue(data.parameters().get(SERVER_MAX_WINDOW).equals("10"));
    assertTrue(data.parameters().containsKey(CLIENT_MAX_WINDOW));
    assertTrue(data.parameters().containsKey(SERVER_MAX_WINDOW));
}
Also used : WebSocketExtensionData(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData) Test(org.junit.Test)

Example 8 with WebSocketExtensionData

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

the class PerMessageDeflateServerExtensionHandshakerTest method testNormalHandshake.

@Test
public void testNormalHandshake() {
    WebSocketServerExtension extension;
    WebSocketExtensionData data;
    Map<String, String> parameters;
    // initialize
    PerMessageDeflateServerExtensionHandshaker handshaker = new PerMessageDeflateServerExtensionHandshaker();
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, Collections.<String, String>emptyMap()));
    // test
    assertNotNull(extension);
    assertEquals(WebSocketServerExtension.RSV1, extension.rsv());
    assertTrue(extension.newExtensionDecoder() instanceof PerMessageDeflateDecoder);
    assertTrue(extension.newExtensionEncoder() instanceof PerMessageDeflateEncoder);
    // execute
    data = extension.newReponseData();
    assertEquals(PERMESSAGE_DEFLATE_EXTENSION, data.name());
    assertTrue(data.parameters().isEmpty());
    // initialize
    parameters = new HashMap<String, String>();
    parameters.put(CLIENT_MAX_WINDOW, null);
    parameters.put(CLIENT_NO_CONTEXT, null);
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, Collections.<String, String>emptyMap()));
    // test
    assertNotNull(extension);
    assertEquals(WebSocketServerExtension.RSV1, extension.rsv());
    assertTrue(extension.newExtensionDecoder() instanceof PerMessageDeflateDecoder);
    assertTrue(extension.newExtensionEncoder() instanceof PerMessageDeflateEncoder);
    // execute
    data = extension.newReponseData();
    // test
    assertEquals(PERMESSAGE_DEFLATE_EXTENSION, data.name());
    assertTrue(data.parameters().isEmpty());
    // initialize
    parameters = new HashMap<String, String>();
    parameters.put(SERVER_MAX_WINDOW, "12");
    parameters.put(SERVER_NO_CONTEXT, null);
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, parameters));
    // test
    assertNull(extension);
}
Also used : WebSocketServerExtension(io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension) PerMessageDeflateServerExtensionHandshaker(io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateServerExtensionHandshaker) WebSocketExtensionData(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData) Test(org.junit.Test)

Example 9 with WebSocketExtensionData

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

the class PerMessageDeflateServerExtensionHandshakerTest method testCustomHandshake.

@Test
public void testCustomHandshake() {
    WebSocketServerExtension extension;
    Map<String, String> parameters;
    WebSocketExtensionData data;
    // initialize
    PerMessageDeflateServerExtensionHandshaker handshaker = new PerMessageDeflateServerExtensionHandshaker(6, true, 10, true, true);
    parameters = new HashMap<String, String>();
    parameters.put(CLIENT_MAX_WINDOW, null);
    parameters.put(SERVER_MAX_WINDOW, "12");
    parameters.put(CLIENT_NO_CONTEXT, null);
    parameters.put(SERVER_NO_CONTEXT, null);
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, parameters));
    // test
    assertNotNull(extension);
    assertEquals(WebSocketServerExtension.RSV1, extension.rsv());
    assertTrue(extension.newExtensionDecoder() instanceof PerMessageDeflateDecoder);
    assertTrue(extension.newExtensionEncoder() instanceof PerMessageDeflateEncoder);
    // execute
    data = extension.newReponseData();
    // test
    assertEquals(PERMESSAGE_DEFLATE_EXTENSION, data.name());
    assertTrue(data.parameters().containsKey(CLIENT_MAX_WINDOW));
    assertTrue(data.parameters().get(CLIENT_MAX_WINDOW).equals("10"));
    assertTrue(data.parameters().containsKey(SERVER_MAX_WINDOW));
    assertTrue(data.parameters().get(SERVER_MAX_WINDOW).equals("12"));
    assertTrue(data.parameters().containsKey(CLIENT_MAX_WINDOW));
    assertTrue(data.parameters().containsKey(SERVER_MAX_WINDOW));
    // initialize
    parameters = new HashMap<String, String>();
    parameters.put(SERVER_MAX_WINDOW, "12");
    parameters.put(SERVER_NO_CONTEXT, null);
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, parameters));
    // test
    assertNotNull(extension);
    assertEquals(WebSocketServerExtension.RSV1, extension.rsv());
    assertTrue(extension.newExtensionDecoder() instanceof PerMessageDeflateDecoder);
    assertTrue(extension.newExtensionEncoder() instanceof PerMessageDeflateEncoder);
    // execute
    data = extension.newReponseData();
    // test
    assertEquals(PERMESSAGE_DEFLATE_EXTENSION, data.name());
    assertEquals(2, data.parameters().size());
    assertTrue(data.parameters().containsKey(SERVER_MAX_WINDOW));
    assertTrue(data.parameters().get(SERVER_MAX_WINDOW).equals("12"));
    assertTrue(data.parameters().containsKey(SERVER_NO_CONTEXT));
    // initialize
    parameters = new HashMap<String, String>();
    // execute
    extension = handshaker.handshakeExtension(new WebSocketExtensionData(PERMESSAGE_DEFLATE_EXTENSION, parameters));
    // test
    assertNotNull(extension);
    // execute
    data = extension.newReponseData();
    // test
    assertEquals(PERMESSAGE_DEFLATE_EXTENSION, data.name());
    assertTrue(data.parameters().isEmpty());
}
Also used : WebSocketServerExtension(io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtension) PerMessageDeflateServerExtensionHandshaker(io.netty.handler.codec.http.websocketx.extensions.compression.PerMessageDeflateServerExtensionHandshaker) WebSocketExtensionData(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData) Test(org.junit.Test)

Example 10 with WebSocketExtensionData

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

the class WebSocketServerCompressionHandlerTest method testServerWindowSizeDisableThenFallback.

@Test
public void testServerWindowSizeDisableThenFallback() {
    EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerExtensionHandler(new PerMessageDeflateServerExtensionHandshaker(6, false, 15, false, false)));
    HttpRequest req = newUpgradeRequest(PERMESSAGE_DEFLATE_EXTENSION + "; " + SERVER_MAX_WINDOW + "=10, " + 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