Exemple #1
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();
        }
        public void InitialDictionaryIsEmpty()
        {
            using (var memoryPool = KestrelMemoryPool.Create())
            {
                var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
                var pair    = DuplexPipe.CreateConnectionPair(options, options);
                var http1ConnectionContext = new Http1ConnectionContext
                {
                    ServiceContext     = new TestServiceContext(),
                    ConnectionFeatures = new FeatureCollection(),
                    MemoryPool         = memoryPool,
                    Application        = pair.Application,
                    Transport          = pair.Transport,
                    TimeoutControl     = null
                };

                var http1Connection = new Http1Connection(http1ConnectionContext);

                http1Connection.Reset();

                IDictionary <string, StringValues> headers = http1Connection.ResponseHeaders;

                Assert.Equal(0, headers.Count);
                Assert.False(headers.IsReadOnly);
            }
        }
Exemple #3
0
        public void InitialDictionaryIsEmpty()
        {
            using (var memoryPool = new MemoryPool())
            {
                var pair = DuplexPipe.CreateConnectionPair(memoryPool);
                var http1ConnectionContext = new Http1ConnectionContext
                {
                    ServiceContext     = new TestServiceContext(),
                    ConnectionFeatures = new FeatureCollection(),
                    MemoryPool         = memoryPool,
                    Application        = pair.Application,
                    Transport          = pair.Transport,
                    TimeoutControl     = null
                };

                var http1Connection = new Http1Connection(http1ConnectionContext);

                http1Connection.Reset();

                IDictionary <string, StringValues> headers = http1Connection.ResponseHeaders;

                Assert.Equal(0, headers.Count);
                Assert.False(headers.IsReadOnly);
            }
        }
        public TestInput()
        {
            _memoryPool = KestrelMemoryPool.Create();
            var options = new PipeOptions(pool: _memoryPool, 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>());

            Http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = new TestServiceContext(),
                ConnectionFeatures = connectionFeatures,
                Application        = Application,
                Transport          = Transport,
                MemoryPool         = _memoryPool,
                TimeoutControl     = Mock.Of <ITimeoutControl>()
            };

            Http1Connection = new Http1Connection(Http1ConnectionContext);
            Http1Connection.HttpResponseControl = Mock.Of <IHttpResponseControl>();
        }
Exemple #5
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;
        }
        public HttpProtocolFeatureCollection()
        {
            var serviceContext = new ServiceContext
            {
                HttpParserFactory = _ => NullParser <Http1ParsingHandler> .Instance,
                ServerOptions     = new KestrelServerOptions()
            };
            var http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                PipeFactory        = new PipeFactory()
            };

            _http1Connection = new Http1Connection <object>(application: null, context: http1ConnectionContext);
        }
        public void Setup()
        {
            var serviceContext = new ServiceContext
            {
                HttpParserFactory = f => new HttpParser <Http1ParsingHandler>(),
                ServerOptions     = new KestrelServerOptions()
            };
            var http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                PipeFactory        = new PipeFactory()
            };

            var http1Connection = new Http1Connection <object>(application: null, context: http1ConnectionContext);

            http1Connection.Reset();
            _responseHeadersDirect = (HttpResponseHeaders)http1Connection.ResponseHeaders;
            var context = new DefaultHttpContext(http1Connection);

            _response = new DefaultHttpResponse(context);

            switch (Type)
            {
            case BenchmarkTypes.ContentLengthNumeric:
                ContentLengthNumeric(1);
                break;

            case BenchmarkTypes.ContentLengthString:
                ContentLengthString(1);
                break;

            case BenchmarkTypes.Plaintext:
                Plaintext(1);
                break;

            case BenchmarkTypes.Common:
                Common(1);
                break;

            case BenchmarkTypes.Unknown:
                Unknown(1);
                break;
            }
        }
Exemple #8
0
        public void Setup()
        {
            PipeFactory = new PipeFactory();
            Pipe        = PipeFactory.Create();

            var serviceContext = new ServiceContext
            {
                HttpParserFactory = f => new HttpParser <Http1ParsingHandler>(),
                ServerOptions     = new KestrelServerOptions(),
            };
            var http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = serviceContext,
                ConnectionFeatures = new FeatureCollection(),
                PipeFactory        = PipeFactory,
                TimeoutControl     = new MockTimeoutControl()
            };

            Http1Connection = new Http1Connection <object>(application: null, context: http1ConnectionContext);
        }
Exemple #9
0
        public TestInput()
        {
            _memoryPool = new MemoryPool();
            var pair = PipeFactory.CreateConnectionPair(_memoryPool);

            Transport   = pair.Transport;
            Application = pair.Application;

            Http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = new TestServiceContext(),
                ConnectionFeatures = new FeatureCollection(),
                Application        = Application,
                Transport          = Transport,
                MemoryPool         = _memoryPool,
                TimeoutControl     = Mock.Of <ITimeoutControl>()
            };

            Http1Connection = new Http1Connection(Http1ConnectionContext);
            Http1Connection.HttpResponseControl = Mock.Of <IHttpResponseControl>();
        }
Exemple #10
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();
        }
Exemple #11
0
        public void InitialDictionaryIsEmpty()
        {
            var factory = new PipeFactory();
            var pair    = factory.CreateConnectionPair();
            var http1ConnectionContext = new Http1ConnectionContext
            {
                ServiceContext     = new TestServiceContext(),
                ConnectionFeatures = new FeatureCollection(),
                PipeFactory        = factory,
                Application        = pair.Application,
                Transport          = pair.Transport,
                TimeoutControl     = null
            };

            var http1Connection = new Http1Connection <object>(application: null, context: http1ConnectionContext);

            http1Connection.Reset();

            IDictionary <string, StringValues> headers = http1Connection.ResponseHeaders;

            Assert.Equal(0, headers.Count);
            Assert.False(headers.IsReadOnly);
        }
        public async Task CopyToAsyncDoesNotCopyBlocks()
        {
            var writeCount      = 0;
            var writeTcs        = new TaskCompletionSource <(byte[], int, int)>();
            var mockDestination = new Mock <Stream>()
            {
                CallBase = true
            };

            mockDestination
            .Setup(m => m.WriteAsync(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>(), CancellationToken.None))
            .Callback((byte[] buffer, int offset, int count, CancellationToken cancellationToken) =>
            {
                writeTcs.SetResult((buffer, offset, count));
                writeCount++;
            })
            .Returns(Task.CompletedTask);

            using (var memoryPool = KestrelMemoryPool.Create())
            {
                var options                = new PipeOptions(pool: memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
                var pair                   = DuplexPipe.CreateConnectionPair(options, options);
                var transport              = pair.Transport;
                var application            = pair.Application;
                var http1ConnectionContext = new Http1ConnectionContext
                {
                    ServiceContext     = new TestServiceContext(),
                    ConnectionFeatures = new FeatureCollection(),
                    Application        = application,
                    Transport          = transport,
                    MemoryPool         = memoryPool,
                    TimeoutControl     = Mock.Of <ITimeoutControl>()
                };
                var http1Connection = new Http1Connection(http1ConnectionContext)
                {
                    HasStartedConsumingRequestBody = true
                };

                var headers = new HttpRequestHeaders {
                    HeaderContentLength = "12"
                };
                var body = Http1MessageBody.For(HttpVersion.Http11, headers, http1Connection);

                var copyToAsyncTask = body.CopyToAsync(mockDestination.Object);

                var bytes  = Encoding.ASCII.GetBytes("Hello ");
                var buffer = http1Connection.RequestBodyPipe.Writer.GetMemory(2048);
                ArraySegment <byte> segment;
                Assert.True(MemoryMarshal.TryGetArray(buffer, out segment));
                Buffer.BlockCopy(bytes, 0, segment.Array, segment.Offset, bytes.Length);
                http1Connection.RequestBodyPipe.Writer.Advance(bytes.Length);
                await http1Connection.RequestBodyPipe.Writer.FlushAsync();

                // Verify the block passed to Stream.WriteAsync() is the same one incoming data was written into.
                Assert.Equal((segment.Array, segment.Offset, bytes.Length), await writeTcs.Task);

                // Verify the again when GetMemory returns the tail space of the same block.
                writeTcs = new TaskCompletionSource <(byte[], int, int)>();
                bytes    = Encoding.ASCII.GetBytes("World!");
                buffer   = http1Connection.RequestBodyPipe.Writer.GetMemory(2048);
                Assert.True(MemoryMarshal.TryGetArray(buffer, out segment));
                Buffer.BlockCopy(bytes, 0, segment.Array, segment.Offset, bytes.Length);
                http1Connection.RequestBodyPipe.Writer.Advance(bytes.Length);
                await http1Connection.RequestBodyPipe.Writer.FlushAsync();

                Assert.Equal((segment.Array, segment.Offset, bytes.Length), await writeTcs.Task);

                http1Connection.RequestBodyPipe.Writer.Complete();

                await copyToAsyncTask;

                Assert.Equal(2, writeCount);

                // Don't call body.StopAsync() because PumpAsync() was never called.
                http1Connection.RequestBodyPipe.Reader.Complete();
            }
        }
Exemple #13
0
 public TestHttp1Connection(Http1ConnectionContext context)
     : base(context)
 {
 }
 public TestHttp1Connection(IHttpApplication <TContext> application, Http1ConnectionContext context)
     : base(application, context)
 {
 }