Esempio n. 1
0
        public async Task Output()
        {
            _http1Connection.Reset();
            _http1Connection.StatusCode      = 200;
            _http1Connection.HttpVersionEnum = HttpVersion.Http11;
            _http1Connection.KeepAlive       = true;

            Task writeTask = Task.CompletedTask;

            switch (Type)
            {
            case BenchmarkTypes.TechEmpowerPlaintext:
                writeTask = TechEmpowerPlaintext();
                break;

            case BenchmarkTypes.PlaintextChunked:
                writeTask = PlaintextChunked();
                break;

            case BenchmarkTypes.PlaintextWithCookie:
                writeTask = PlaintextWithCookie();
                break;

            case BenchmarkTypes.PlaintextChunkedWithCookie:
                writeTask = PlaintextChunkedWithCookie();
                break;

            case BenchmarkTypes.LiveAspNet:
                writeTask = LiveAspNet();
                break;
            }

            await writeTask;
            await _http1Connection.ProduceEndAsync();
        }
Esempio n. 2
0
        public Http1ConnectionTests()
        {
            _pipelineFactory = KestrelMemoryPool.Create();
            var options = new PipeOptions(_pipelineFactory, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            _transport   = pair.Transport;
            _application = pair.Application;

            var connectionFeatures = new FeatureCollection();

            connectionFeatures.Set(Mock.Of <IConnectionLifetimeFeature>());
            connectionFeatures.Set(Mock.Of <IBytesWrittenFeature>());

            _serviceContext         = new TestServiceContext();
            _timeoutControl         = new Mock <ITimeoutControl>();
            _http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = _serviceContext,
                ConnectionContext  = Mock.Of <ConnectionContext>(),
                ConnectionFeatures = connectionFeatures,
                MemoryPool         = _pipelineFactory,
                TimeoutControl     = _timeoutControl.Object,
                Application        = pair.Application,
                Transport          = pair.Transport
            };

            _http1Connection = new TestHttp1Connection(_http1ConnectionContext);
            _http1Connection.Reset();
        }
        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);
        }
Esempio n. 4
0
        public void Setup()
        {
            var bufferPool = new MemoryPool();
            var pair       = PipeFactory.CreateConnectionPair(bufferPool);

            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(),
                BufferPool         = bufferPool,
                TimeoutControl     = new MockTimeoutControl(),
                Application        = pair.Application,
                Transport          = pair.Transport
            });

            http1Connection.Reset();

            _http1Connection = http1Connection;
        }
Esempio n. 5
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);
        }
        public void Setup()
        {
            _memoryPool = KestrelMemoryPool.Create();
            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);

            _pair = DuplexPipe.CreateConnectionPair(options, options);

            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,
                TimeoutControl     = new MockTimeoutControl(),
                Application        = _pair.Application,
                Transport          = _pair.Transport
            });

            http1Connection.Reset();

            _http1Connection = http1Connection;
        }
        private TestHttp1Connection MakeHttp1Connection()
        {
            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);
        }
Esempio n. 8
0
        public void Setup()
        {
            var pipeFactory = new PipeFactory();
            var pair        = pipeFactory.CreateConnectionPair();

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

            var http1Connection = new TestHttp1Connection <object>(application: null, context: new Http1ConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                PipeFactory        = pipeFactory,
                TimeoutControl     = new MockTimeoutControl(),
                Application        = pair.Application,
                Transport          = pair.Transport
            });

            http1Connection.Reset();

            _http1Connection = http1Connection;
        }
Esempio n. 9
0
        public HttpProtocolFeatureCollectionTests()
        {
            _memoryPool = KestrelMemoryPool.Create();
            var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            _transport   = pair.Transport;
            _application = pair.Application;

            _serviceContext         = new TestServiceContext();
            _timeoutControl         = new Mock <ITimeoutControl>();
            _http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = _serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = _memoryPool,
                TimeoutControl     = _timeoutControl.Object,
                Application        = pair.Application,
                Transport          = pair.Transport
            };

            _http1Connection = new TestHttp1Connection(_http1ConnectionContext);
            _http1Connection.Reset();
            _collection = _http1Connection;
        }
Esempio n. 10
0
        public void Setup()
        {
            _http1Connection.Reset();

            _http1Connection.RequestHeaders.ContentLength = _readData.Length;

            if (!WithHeaders)
            {
                _http1Connection.FlushAsync().GetAwaiter().GetResult();
            }

            ResetState();
        }
Esempio n. 11
0
        public HttpProtocolFeatureCollectionTests()
        {
            _http1ConnectionContext = new HttpConnectionContext
            {
                ServiceContext     = new TestServiceContext(),
                ConnectionFeatures = new FeatureCollection(),
                TimeoutControl     = Mock.Of <ITimeoutControl>(),
                Transport          = Mock.Of <IDuplexPipe>(),
            };

            _http1Connection = new TestHttp1Connection(_http1ConnectionContext);
            _http1Connection.Reset();
            _collection = _http1Connection;
        }
Esempio n. 12
0
        public Http1HttpProtocolFeatureCollectionTests()
        {
            var context = TestContextFactory.CreateHttpConnectionContext(
                connectionContext: Mock.Of <ConnectionContext>(),
                serviceContext: new TestServiceContext(),
                transport: Mock.Of <IDuplexPipe>(),
                connectionFeatures: new FeatureCollection(),
                timeoutControl: Mock.Of <ITimeoutControl>());

            _httpConnectionContext = context;
            _http1Connection       = new TestHttp1Connection(context);
            _http1Connection.Reset();
            _collection = _http1Connection;
        }
Esempio n. 13
0
        public void Setup()
        {
            _http1Connection.Reset();
            if (Chunked)
            {
                _http1Connection.RequestHeaders.Add("Transfer-Encoding", "chunked");
            }
            else
            {
                _http1Connection.RequestHeaders.ContentLength = _writeData.Length;
            }

            if (!WithHeaders)
            {
                _http1Connection.FlushAsync().GetAwaiter().GetResult();
            }

            ResetState();
        }
Esempio n. 14
0
        public HttpProtocolFeatureCollectionTests()
        {
            var context = new Http2StreamContext
            {
                ServiceContext     = new TestServiceContext(),
                ConnectionFeatures = new FeatureCollection(),
                TimeoutControl     = Mock.Of <ITimeoutControl>(),
                Transport          = Mock.Of <IDuplexPipe>(),
                ServerPeerSettings = new Http2PeerSettings(),
                ClientPeerSettings = new Http2PeerSettings(),
            };

            _httpConnectionContext = context;
            _http1Connection       = new TestHttp1Connection(context);
            _http1Connection.Reset();
            _collection = _http1Connection;

            var http2Stream = new TestHttp2Stream(context);

            http2Stream.Reset();
            _http2Collection = http2Stream;
        }
Esempio n. 15
0
        public Http1ConnectionTests()
        {
            _pipelineFactory = new MemoryPool();
            var pair = PipeFactory.CreateConnectionPair(_pipelineFactory);

            _transport   = pair.Transport;
            _application = pair.Application;

            _serviceContext         = new TestServiceContext();
            _timeoutControl         = new Mock <ITimeoutControl>();
            _http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = _serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                MemoryPool         = _pipelineFactory,
                TimeoutControl     = _timeoutControl.Object,
                Application        = pair.Application,
                Transport          = pair.Transport
            };

            _http1Connection = new TestHttp1Connection(_http1ConnectionContext);
            _http1Connection.Reset();
        }
Esempio n. 16
0
        public async Task TakeMessageHeadersThrowsWhenHeadersExceedTotalSizeLimit()
        {
            const string headerLine = "Header: value\r\n";

            _serviceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1;
            _http1Connection.Reset();

            await _application.Output.WriteAsync(Encoding.ASCII.GetBytes($"{headerLine}\r\n"));

            var readableBuffer = (await _transport.Input.ReadAsync()).Buffer;

            var exception = Assert.Throws <BadHttpRequestException>(() => _http1Connection.TakeMessageHeaders(readableBuffer, out _consumed, out _examined));

            _transport.Input.Advance(_consumed, _examined);

            Assert.Equal(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, exception.Message);
            Assert.Equal(StatusCodes.Status431RequestHeaderFieldsTooLarge, exception.StatusCode);
        }
Esempio n. 17
0
        public async Task TakeMessageHeadersSucceedsWhenHeaderValueContainsUTF8()
        {
            var headerName       = "Header";
            var headerValueBytes = new byte[] { 0x46, 0x72, 0x61, 0x6e, 0xc3, 0xa7, 0x6f, 0x69, 0x73 };
            var headerValue      = Encoding.UTF8.GetString(headerValueBytes);

            _http1Connection.Reset();

            await _application.Output.WriteAsync(Encoding.UTF8.GetBytes($"{headerName}: "));

            await _application.Output.WriteAsync(headerValueBytes);

            await _application.Output.WriteAsync(Encoding.UTF8.GetBytes("\r\n\r\n"));

            var readableBuffer = (await _transport.Input.ReadAsync()).Buffer;

            _http1Connection.TakeMessageHeaders(readableBuffer, trailers: false, out _consumed, out _examined);
            _transport.Input.AdvanceTo(_consumed, _examined);

            Assert.Equal(headerValue, _http1Connection.RequestHeaders[headerName]);
        }
Esempio n. 18
0
 public void Setup()
 {
     _http1Connection.Reset();
     _http1Connection.RequestHeaders.ContentLength = _writeData.Length;
     _http1Connection.FlushAsync().GetAwaiter().GetResult();
 }