コード例 #1
0
        private TestHttp1Connection MakeHttp1Connection()
        {
            var options = new PipeOptions(_memoryPool, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            _pair = pair;

            var serviceContext = TestContextFactory.CreateServiceContext(
                serverOptions: new KestrelServerOptions(),
                httpParser: new HttpParser <Http1ParsingHandler>(),
                dateHeaderValueManager: new DateHeaderValueManager());

            var connectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: serviceContext,
                connectionContext: null,
                transport: pair.Transport,
                timeoutControl: new TimeoutControl(timeoutHandler: null),
                memoryPool: _memoryPool,
                connectionFeatures: new FeatureCollection());

            var http1Connection = new TestHttp1Connection(connectionContext);

            http1Connection.Reset();
            http1Connection.InitializeBodyControl(MessageBody.ZeroContentLengthKeepAlive);
            serviceContext.DateHeaderValueManager.OnHeartbeat(DateTimeOffset.UtcNow);

            return(http1Connection);
        }
コード例 #2
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 HttpConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = _memoryPool,
                TimeoutControl     = new TimeoutControl(timeoutHandler: null),
                Transport          = pair.Transport
            });

            http1Connection.Reset();
            http1Connection.InitializeBodyControl(MessageBody.ZeroContentLengthKeepAlive);
            serviceContext.DateHeaderValueManager.OnHeartbeat(DateTimeOffset.UtcNow);

            return(http1Connection);
        }
コード例 #3
0
        public void InitializeStreamsResetsStreams()
        {
            // Arrange
            var messageBody = Http1MessageBody.For(Kestrel.Core.Internal.Http.HttpVersion.Http11, (HttpRequestHeaders)_http1Connection.RequestHeaders, _http1Connection);

            _http1Connection.InitializeBodyControl(messageBody);

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

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

            // Act
            _http1Connection.InitializeBodyControl(messageBody);

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