示例#1
0
        public TestInput(IKestrelTrace log = null, ITimeoutControl timeoutControl = null)
        {
            _memoryPool = PinnedBlockMemoryPoolFactory.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>());

            Http1ConnectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: new TestServiceContext
            {
                Log = log ?? Mock.Of <IKestrelTrace>()
            },
                connectionContext: Mock.Of <ConnectionContext>(),
                transport: Transport,
                timeoutControl: timeoutControl ?? Mock.Of <ITimeoutControl>(),
                memoryPool: _memoryPool,
                connectionFeatures: connectionFeatures);

            Http1Connection = new Http1Connection(Http1ConnectionContext);
            Http1Connection.HttpResponseControl = Mock.Of <IHttpResponseControl>();
            Http1Connection.Reset();
        }
示例#2
0
        public async Task WriteDataRateTimeoutAbortsConnection()
        {
            var mockConnectionContext = new Mock <ConnectionContext>();

            var httpConnectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: new TestServiceContext(),
                connectionContext: mockConnectionContext.Object,
                connectionFeatures: new FeatureCollection(),
                transport: new DuplexPipe(Mock.Of <PipeReader>(), Mock.Of <PipeWriter>()));

            var httpConnection = new HttpConnection(httpConnectionContext);

            var aborted         = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
            var http1Connection = new Http1Connection(httpConnectionContext);

            httpConnection.Initialize(http1Connection);
            http1Connection.Reset();
            http1Connection.RequestAborted.Register(() =>
            {
                aborted.SetResult();
            });

            httpConnection.OnTimeout(TimeoutReason.WriteDataRate);

            mockConnectionContext
            .Verify(c => c.Abort(It.Is <ConnectionAbortedException>(ex => ex.Message == CoreStrings.ConnectionTimedBecauseResponseMininumDataRateNotSatisfied)),
                    Times.Once);

            await aborted.Task.DefaultTimeout();
        }
    public void Setup()
    {
        _memoryPool = PinnedBlockMemoryPoolFactory.Create();
        var options = new PipeOptions(_memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
        var pair    = DuplexPipe.CreateConnectionPair(options, options);

        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,
            memoryPool: _memoryPool,
            connectionFeatures: new FeatureCollection(),
            timeoutControl: new TimeoutControl(timeoutHandler: null));

        var http1Connection = new Http1Connection(connectionContext);

        http1Connection.Reset();

        Http1Connection = http1Connection;
        Pipe            = new Pipe(new PipeOptions(_memoryPool));
    }
示例#4
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 = TestContextFactory.CreateServiceContext(
                serverOptions: new KestrelServerOptions(),
                httpParser: new HttpParser <Http1ParsingHandler>(),
                dateHeaderValueManager: new DateHeaderValueManager(),
                log: new MockTrace());

            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(new Http1ContentLengthMessageBody(http1Connection, contentLength: 100, keepAlive: true));
            serviceContext.DateHeaderValueManager.OnHeartbeat(DateTimeOffset.UtcNow);

            return(http1Connection);
        }
示例#5
0
        public HttpProtocolFeatureCollection()
        {
            var memoryPool = PinnedBlockMemoryPoolFactory.Create();
            var options    = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair       = DuplexPipe.CreateConnectionPair(options, options);

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

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

            var http1Connection = new Http1Connection(connectionContext);

            http1Connection.Reset();

            _collection = http1Connection;
        }
示例#6
0
        public StartLineTests()
        {
            MemoryPool = PinnedBlockMemoryPoolFactory.Create();
            var options = new PipeOptions(MemoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);

            Transport = pair.Transport;

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

            var connectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: serviceContext,
                connectionContext: Mock.Of <ConnectionContext>(),
                transport: Transport,
                timeoutControl: new TimeoutControl(timeoutHandler: null),
                memoryPool: MemoryPool,
                connectionFeatures: new FeatureCollection());

            Http1Connection = new Http1Connection(connectionContext);

            Parser         = new HttpParser <Http1ParsingHandler>(showErrorDetails: true);
            ParsingHandler = new Http1ParsingHandler(Http1Connection);
        }
示例#7
0
    public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper)
    {
        base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper);

        _pipelineFactory = PinnedBlockMemoryPoolFactory.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>());

        _serviceContext = new TestServiceContext(LoggerFactory)
        {
            Scheduler = PipeScheduler.Inline
        };

        _timeoutControl         = new Mock <ITimeoutControl>();
        _http1ConnectionContext = TestContextFactory.CreateHttpConnectionContext(
            serviceContext: _serviceContext,
            connectionContext: Mock.Of <ConnectionContext>(),
            transport: pair.Transport,
            timeoutControl: _timeoutControl.Object,
            memoryPool: _pipelineFactory,
            connectionFeatures: connectionFeatures);

        _http1Connection = new TestHttp1Connection(_http1ConnectionContext);
    }
        public void Setup()
        {
            var memoryPool = PinnedBlockMemoryPoolFactory.Create();
            var options    = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair       = DuplexPipe.CreateConnectionPair(options, options);

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

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

            var http1Connection = new Http1Connection(connectionContext);

            http1Connection.Reset();
            serviceContext.DateHeaderValueManager.OnHeartbeat(DateTimeOffset.UtcNow);

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

            _response = context.Response;

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

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

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

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

            case BenchmarkTypes.Unknown:
                SetUnknown(1);
                GetUnknown(1);
                break;
            }
        }
示例#9
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;
        }
示例#10
0
        private LibuvOuputProcessor CreateOutputProducer(PipeOptions pipeOptions, CancellationTokenSource cts = null)
        {
            var pair = DuplexPipe.CreateConnectionPair(pipeOptions, pipeOptions);

            var logger         = new TestApplicationErrorLogger();
            var serviceContext = new TestServiceContext
            {
                Log       = new TestKestrelTrace(logger),
                Scheduler = PipeScheduler.Inline
            };
            var transportContext = new TestLibuvTransportContext {
                Log = new LibuvTrace(logger)
            };

            var socket   = new MockSocket(_mockLibuv, _libuvThread.Loop.ThreadId, transportContext.Log);
            var consumer = new LibuvOutputConsumer(pair.Application.Input, _libuvThread, socket, "0", transportContext.Log);

            var connectionFeatures = new FeatureCollection();

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

            var connectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: serviceContext,
                connectionContext: Mock.Of <ConnectionContext>(),
                transport: pair.Transport,
                memoryPool: _memoryPool,
                connectionFeatures: connectionFeatures,
                timeoutControl: Mock.Of <ITimeoutControl>());

            var http1Connection = new Http1Connection(connectionContext);

            if (cts != null)
            {
                http1Connection.RequestAborted.Register(cts.Cancel);
            }

            var outputTask = WriteOutputAsync(consumer, pair.Application.Input, http1Connection);

            var processor = new LibuvOuputProcessor
            {
                ProcessingTask = outputTask,
                OutputProducer = (Http1OutputProducer)http1Connection.Output,
                PipeWriter     = pair.Transport.Output,
            };

            return(processor);
        }
    public void InitialDictionaryIsEmpty()
    {
        using (var memoryPool = PinnedBlockMemoryPoolFactory.Create())
        {
            var options = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair    = DuplexPipe.CreateConnectionPair(options, options);
            var http1ConnectionContext = TestContextFactory.CreateHttpConnectionContext(
                serviceContext: new TestServiceContext(),
                connectionContext: Mock.Of <ConnectionContext>(),
                transport: pair.Transport,
                memoryPool: memoryPool,
                connectionFeatures: new FeatureCollection());

            var http1Connection = new Http1Connection(http1ConnectionContext);

            http1Connection.Reset();

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

            Assert.Equal(0, headers.Count);
            Assert.False(headers.IsReadOnly);
        }
    }
示例#12
0
        public void Setup()
        {
            var memoryPool = SlabMemoryPoolFactory.Create();
            var options    = new PipeOptions(memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
            var pair       = DuplexPipe.CreateConnectionPair(options, options);

            var serviceContext = TestContextFactory.CreateServiceContext(
                serverOptions: new KestrelServerOptions(),
                httpParser: NullParser <Http1ParsingHandler> .Instance);

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

            var http1Connection = new Http1Connection(connectionContext);

            http1Connection.Reset();

            _http1Connection = http1Connection;
        }