Ejemplo n.º 1
0
        private TestHttp1Connection MakeHttp1Connection()
        {
            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            _pair = pair;

            var serviceContext = new ServiceContext
            {
                DateHeaderValueManager = new DateHeaderValueManager(),
                ServerOptions          = new KestrelServerOptions(),
                Log        = new MockTrace(),
                HttpParser = new HttpParser <Http1ParsingHandler>()
            };

            var http1Connection = new TestHttp1Connection(new Http1ConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = _memoryPool,
                Application        = pair.Application,
                Transport          = pair.Transport
            });

            http1Connection.Reset();
            http1Connection.InitializeStreams(MessageBody.ZeroContentLengthKeepAlive);

            return(http1Connection);
        }
Ejemplo n.º 2
0
        private TestHttp1Connection MakeHttp1Connection()
        {
            using (var memoryPool = new MemoryPool())
            {
                var pair = DuplexPipe.CreateConnectionPair(memoryPool);
                _pair = pair;

                var serviceContext = new ServiceContext
                {
                    DateHeaderValueManager = new DateHeaderValueManager(),
                    ServerOptions          = new KestrelServerOptions(),
                    Log        = new MockTrace(),
                    HttpParser = new HttpParser <Http1ParsingHandler>()
                };

                var http1Connection = new TestHttp1Connection(new Http1ConnectionContext
                {
                    ServiceContext     = serviceContext,
                    ConnectionFeatures = new FeatureCollection(),
                    MemoryPool         = memoryPool,
                    Application        = pair.Application,
                    Transport          = pair.Transport
                });

                http1Connection.Reset();
                http1Connection.InitializeStreams(MessageBody.ZeroContentLengthKeepAlive);

                return(http1Connection);
            }
        }
Ejemplo n.º 3
0
        public void InitializeStreamsResetsStreams()
        {
            // Arrange
            var messageBody = Http1MessageBody.For(Kestrel.Core.Internal.Http.HttpVersion.Http11, (HttpRequestHeaders)_http1Connection.RequestHeaders, _http1Connection);

            _http1Connection.InitializeStreams(messageBody);

            var originalRequestBody  = _http1Connection.RequestBody;
            var originalResponseBody = _http1Connection.ResponseBody;

            _http1Connection.RequestBody  = new MemoryStream();
            _http1Connection.ResponseBody = new MemoryStream();

            // Act
            _http1Connection.InitializeStreams(messageBody);

            // Assert
            Assert.Same(originalRequestBody, _http1Connection.RequestBody);
            Assert.Same(originalResponseBody, _http1Connection.ResponseBody);
        }