コード例 #1
0
        protected override void InitChannel(IChannel channel)
        {
            var pipeline = channel.Pipeline;

            if (_cert is object)
            {
                var tlsSettings = new ClientTlsSettings(_targetHost)
                {
                    ApplicationProtocols = new List <SslApplicationProtocol>(new[]
                    {
                        SslApplicationProtocol.Http2,
                        SslApplicationProtocol.Http11
                    })
                }.AllowAnyServerCertificate();
                pipeline.AddLast("tls", new TlsHandler(tlsSettings));
            }

            var build = Http2FrameCodecBuilder.ForClient();

            build.InitialSettings = Http2Settings.DefaultSettings(); // this is the default, but shows it can be changed.
            Http2FrameCodec http2FrameCodec = build.Build();

            pipeline.AddLast(http2FrameCodec);
            pipeline.AddLast(new Http2MultiplexHandler(new SimpleChannelInboundHandler0()));
        }
コード例 #2
0
        protected override void InitChannel(IChannel ch)
        {
            var pipeline = ch.Pipeline;

            if (_cert is object)
            {
                pipeline.AddLast("tls", new TlsHandler(
                                     stream => new SslStream(stream, true, (sender, certificate, chain, errors) => true),
                                     new ClientTlsSettings(_targetHost)
                {
                    ApplicationProtocols = new List <SslApplicationProtocol>(new[]
                    {
                        SslApplicationProtocol.Http2,
                        //SslApplicationProtocol.Http11
                    })
                }
                                     ));
            }
            var build = Http2FrameCodecBuilder.ForClient();

            build.InitialSettings = Http2Settings.DefaultSettings(); // this is the default, but shows it can be changed.
            Http2FrameCodec http2FrameCodec = build.Build();

            pipeline.AddLast(http2FrameCodec);
            pipeline.AddLast(new Http2MultiplexHandler(new SimpleChannelInboundHandler0()));
        }
コード例 #3
0
        public void TestConsumeReceivedSettingsDelegate()
        {
            var encoder = new Mock <ITestHttp2ConnectionEncoder>();
            DecoratingHttp2ConnectionEncoder decoratingHttp2ConnectionEncoder =
                new DecoratingHttp2ConnectionEncoder(encoder.Object);

            Http2Settings settings = Http2Settings.DefaultSettings();

            decoratingHttp2ConnectionEncoder.ConsumeReceivedSettings(Http2Settings.DefaultSettings());
            //encoder.Verify(x => x.ConsumeReceivedSettings(It.Is<Http2Settings>(v => v == settings)), Times.Exactly(1));
            // Http2Settings.DefaultSettings每次返回新实例
            encoder.Verify(x => x.ConsumeReceivedSettings(It.IsAny <Http2Settings>()), Times.Exactly(1));
        }
コード例 #4
0
 public void TestConsumeReceivedSettingsThrows()
 {
     try
     {
         var encoder = new Mock <IHttp2ConnectionEncoder>();
         DecoratingHttp2ConnectionEncoder decoratingHttp2ConnectionEncoder =
             new DecoratingHttp2ConnectionEncoder(encoder.Object);
         decoratingHttp2ConnectionEncoder.ConsumeReceivedSettings(Http2Settings.DefaultSettings());
         Assert.False(true);
     }
     catch (Exception exc)
     {
         Assert.IsType <InvalidOperationException>(exc);
     }
 }