public void ConsumingOutOfOrderFailsGracefully()
        {
            var defultIter = new MemoryPoolIterator();

            // Calling ConsumingComplete without a preceding calling to ConsumingStart fails
            using (var socketInput = new SocketInput(null, null))
            {
                Assert.Throws <InvalidOperationException>(() => socketInput.ConsumingComplete(defultIter, defultIter));
            }

            // Calling ConsumingComplete twice in a row fails
            using (var socketInput = new SocketInput(null, null))
            {
                socketInput.ConsumingStart();
                socketInput.ConsumingComplete(defultIter, defultIter);
                Assert.Throws <InvalidOperationException>(() => socketInput.ConsumingComplete(defultIter, defultIter));
            }

            // Calling ConsumingStart twice in a row fails
            using (var socketInput = new SocketInput(null, null))
            {
                socketInput.ConsumingStart();
                Assert.Throws <InvalidOperationException>(() => socketInput.ConsumingStart());
            }
        }
示例#2
0
        public void LeadingWhitespaceIsNotIncludedInHeaderValue(string rawHeaders)
        {
            var trace = new KestrelTrace(new TestKestrelTrace());
            var ltp   = new LoggingThreadPool(trace);

            using (var pool = new MemoryPool())
                using (var socketInput = new SocketInput(pool, ltp))
                {
                    var connectionContext = new ConnectionContext()
                    {
                        DateHeaderValueManager = new DateHeaderValueManager(),
                        ServerAddress          = ServerAddress.FromUrl("http://localhost:5000")
                    };
                    var frame = new Frame <object>(application: null, context: connectionContext);
                    frame.InitializeHeaders();

                    var headerArray = Encoding.ASCII.GetBytes(rawHeaders);
                    socketInput.IncomingData(headerArray, 0, headerArray.Length);

                    var success = frame.TakeMessageHeaders(socketInput, (FrameRequestHeaders)frame.RequestHeaders);

                    Assert.True(success);
                    Assert.Equal(1, frame.RequestHeaders.Count);
                    Assert.Equal("value", frame.RequestHeaders["Header"]);

                    // Assert TakeMessageHeaders consumed all the input
                    var scan = socketInput.ConsumingStart();
                    Assert.True(scan.IsEnd);
                }
        }
示例#3
0
        public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders)
        {
            var trace = new KestrelTrace(new TestKestrelTrace());
            var ltp   = new LoggingThreadPool(trace);

            using (var pool = new MemoryPool())
                using (var socketInput = new SocketInput(pool, ltp))
                {
                    var connectionContext = new ConnectionContext()
                    {
                        DateHeaderValueManager = new DateHeaderValueManager(),
                        ServerAddress          = ServerAddress.FromUrl("http://localhost:5000")
                    };
                    var frame            = new Frame <object>(application: null, context: connectionContext);
                    var headerCollection = new FrameRequestHeaders();

                    var headerArray = Encoding.ASCII.GetBytes(rawHeaders);
                    socketInput.IncomingData(headerArray, 0, headerArray.Length);

                    var success = frame.TakeMessageHeaders(socketInput, headerCollection);

                    Assert.True(success);
                    Assert.Equal(numHeaders, headerCollection.Count());

                    // Assert TakeMessageHeaders consumed all the input
                    var scan = socketInput.ConsumingStart();
                    Assert.True(scan.IsEnd);
                }
        }
        public void ConsumingCompleteCallsBufferSizeControlSubtract(Mock <IBufferSizeControl> mockBufferSizeControl)
        {
            using (var kestrelEngine = new KestrelEngine(new MockLibuv(), new TestServiceContext()))
            {
                kestrelEngine.Start(1);

                using (var memory = new MemoryPool())
                    using (var socketInput = new SocketInput(memory, null, mockBufferSizeControl?.Object))
                    {
                        socketInput.IncomingData(new byte[20], 0, 20);

                        var iterator = socketInput.ConsumingStart();
                        iterator.Skip(5);
                        socketInput.ConsumingComplete(iterator, iterator);
                        mockBufferSizeControl?.Verify(b => b.Subtract(5));
                    }
            }
        }
示例#5
0
        public void EmptyHeaderValuesCanBeParsed(string rawHeaders, int numHeaders)
        {
            var socketInput      = new SocketInput(new MemoryPool2());
            var headerCollection = new FrameRequestHeaders();

            var headerArray = Encoding.ASCII.GetBytes(rawHeaders);
            var inputBuffer = socketInput.IncomingStart(headerArray.Length);

            Buffer.BlockCopy(headerArray, 0, inputBuffer.Data.Array, inputBuffer.Data.Offset, headerArray.Length);
            socketInput.IncomingComplete(headerArray.Length, null);

            var success = Frame.TakeMessageHeaders(socketInput, headerCollection);

            Assert.True(success);
            Assert.Equal(numHeaders, headerCollection.Count());

            // Assert TakeMessageHeaders consumed all the input
            var scan = socketInput.ConsumingStart();

            Assert.True(scan.IsEnd);
        }