Beispiel #1
0
        public void SuccessfulUpgrade()
        {
            HttpClientUpgradeHandler.ISourceCodec  sourceCodec  = new FakeSourceCodec();
            HttpClientUpgradeHandler.IUpgradeCodec upgradeCodec = new FakeUpgradeCodec();
            var handler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 1024);
            var catcher = new UserEventCatcher();
            var channel = new EmbeddedChannel(catcher);

            channel.Pipeline.AddFirst("upgrade", handler);

            Assert.True(channel.WriteOutbound(new DefaultFullHttpRequest(HttpVersion.Http11, HttpMethod.Get, "netty.io")));
            var request = channel.ReadOutbound <IFullHttpRequest>();

            Assert.Equal(2, request.Headers.Size);
            Assert.True(request.Headers.Contains(HttpHeaderNames.Upgrade, (AsciiString)"fancyhttp", false));
            Assert.True(request.Headers.Contains((AsciiString)"connection", (AsciiString)"upgrade", false));
            Assert.True(request.Release());
            Assert.Equal(HttpClientUpgradeHandler.UpgradeEvent.UpgradeIssued, catcher.UserEvent);

            var upgradeResponse = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus.SwitchingProtocols);

            upgradeResponse.Headers.Add(HttpHeaderNames.Upgrade, (AsciiString)"fancyhttp");
            Assert.False(channel.WriteInbound(upgradeResponse));
            Assert.False(channel.WriteInbound(EmptyLastHttpContent.Default));

            Assert.Equal(HttpClientUpgradeHandler.UpgradeEvent.UpgradeSuccessful, catcher.UserEvent);
            Assert.Null(channel.Pipeline.Get("upgrade"));

            Assert.True(channel.WriteInbound(new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus.OK)));
            var response = channel.ReadInbound <IFullHttpResponse>();

            Assert.Equal(HttpResponseStatus.OK, response.Status);
            Assert.True(response.Release());
            Assert.False(channel.Finish());
        }
Beispiel #2
0
        public void DontStripConnectionHeaders()
        {
            HttpClientUpgradeHandler.ISourceCodec  sourceCodec  = new FakeSourceCodec();
            HttpClientUpgradeHandler.IUpgradeCodec upgradeCodec = new FakeUpgradeCodec();
            HttpClientUpgradeHandler handler = new HttpClientUpgradeHandler(sourceCodec, upgradeCodec, 1024);
            UserEventCatcher         catcher = new UserEventCatcher();
            EmbeddedChannel          channel = new EmbeddedChannel(catcher);

            channel.Pipeline.AddFirst("upgrade", handler);

            DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.Http11, HttpMethod.Get, "netty.io");

            request.Headers.Add(HttpHeaderNames.Connection, "extra");
            request.Headers.Add((AsciiString)"extra", "value");
            Assert.True(channel.WriteOutbound(request));
            var readRequest = channel.ReadOutbound <IFullHttpRequest>();

            var connectionHeaders = readRequest.Headers.GetAll(HttpHeaderNames.Connection);

            Assert.True(connectionHeaders.Contains((AsciiString)"extra"));
            Assert.True(readRequest.Release());
            Assert.False(channel.Finish());
        }