Ejemplo n.º 1
0
        public void FailedWhenUnknownFrameInMiddleOfHeaderBlock()
        {
            int streamId = 1;

            var input = Unpooled.Buffer();

            try
            {
                var headers = new DefaultHttp2Headers
                {
                    Authority = (AsciiString)"foo",
                    Method    = (AsciiString)"get",
                    Path      = (AsciiString)"/",
                    Scheme    = (AsciiString)"https"
                };
                Http2Flags flags = new Http2Flags().EndOfHeaders(false).EndOfStream(true);
                this.WriteHeaderFrame(input, streamId, headers, flags);
                Http2CodecUtil.WriteFrameHeader(input, 0, (Http2FrameTypes)0xff, new Http2Flags(), streamId);
                Assert.Throws <Http2Exception>(() => this.frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object));
            }
            finally
            {
                input.Release();
            }
        }
Ejemplo n.º 2
0
        private void WriteContinuationFrame(IByteBuffer output, int streamId, IHttp2Headers headers, Http2Flags flags)
        {
            IByteBuffer headerBlock = Unpooled.Buffer();

            try
            {
                hpackEncoder.EncodeHeaders(streamId, headerBlock, headers, NeverSensitiveDetector.Instance);
                Http2CodecUtil.WriteFrameHeader(output, headerBlock.ReadableBytes, Http2FrameTypes.Continuation, flags, streamId);
                output.WriteBytes(headerBlock, headerBlock.ReadableBytes);
            }
            finally
            {
                headerBlock.Release();
            }
        }
Ejemplo n.º 3
0
        public void FailedWhenAckSettingsFrameWithPayload()
        {
            var input = Unpooled.Buffer();

            try
            {
                Http2CodecUtil.WriteFrameHeader(input, 1, Http2FrameTypes.Settings, new Http2Flags().Ack(true), 0);
                input.WriteByte(1);
                Assert.Throws <Http2Exception>(() => frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object));
            }
            finally
            {
                input.Release();
            }
        }
Ejemplo n.º 4
0
        public void FailedWhenWindowUpdateFrameWithZeroDelta()
        {
            var input = Unpooled.Buffer();

            try
            {
                Http2CodecUtil.WriteFrameHeader(input, 4, Http2FrameTypes.WindowUpdate, new Http2Flags(), 0);
                input.WriteInt(0);
                Assert.Throws <Http2Exception>(() => frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object));
            }
            finally
            {
                input.Release();
            }
        }
Ejemplo n.º 5
0
        public void FailedWhenSettingsFrameWithWrongPayloadLength()
        {
            var input = Unpooled.Buffer();

            try
            {
                Http2CodecUtil.WriteFrameHeader(input, 8, Http2FrameTypes.Settings, new Http2Flags(), 0);
                input.WriteInt(Http2CodecUtil.SettingsMaxHeaderListSize);
                input.WriteInt(1024);
                Assert.Throws <Http2Exception>(() => frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object));
            }
            finally
            {
                input.Release();
            }
        }
Ejemplo n.º 6
0
        public void ReadAckSettingsFrame()
        {
            var input = Unpooled.Buffer();

            try
            {
                Http2CodecUtil.WriteFrameHeader(input, 0, Http2FrameTypes.Settings, new Http2Flags().Ack(true), 0);
                frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object);

                this.listener.Object.OnSettingsAckRead(this.ctx.Object);
            }
            finally
            {
                input.Release();
            }
        }
Ejemplo n.º 7
0
        private void WriteHeaderFramePriorityPresent(IByteBuffer output, int streamId, IHttp2Headers headers, Http2Flags flags, int streamDependency, int weight)
        {
            IByteBuffer headerBlock = Unpooled.Buffer();

            try
            {
                headerBlock.WriteInt(streamDependency);
                headerBlock.WriteByte(weight - 1);
                hpackEncoder.EncodeHeaders(streamId, headerBlock, headers, NeverSensitiveDetector.Instance);
                Http2CodecUtil.WriteFrameHeader(output, headerBlock.ReadableBytes, Http2FrameTypes.Headers, flags, streamId);
                output.WriteBytes(headerBlock, headerBlock.ReadableBytes);
            }
            finally
            {
                headerBlock.Release();
            }
        }
Ejemplo n.º 8
0
        public void ReadSettingsFrame()
        {
            var input = Unpooled.Buffer();

            try
            {
                Http2CodecUtil.WriteFrameHeader(input, 6, Http2FrameTypes.Settings, new Http2Flags(), 0);
                input.WriteShort(Http2CodecUtil.SettingsMaxHeaderListSize);
                input.WriteInt(1024);
                frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object);

                this.listener.Object.OnSettingsRead(this.ctx.Object, new Http2Settings().MaxHeaderListSize(1024));
            }
            finally
            {
                input.Release();
            }
        }
Ejemplo n.º 9
0
        private void WriteHeaderFrameWithData(IByteBuffer output, int streamId, IHttp2Headers headers, IByteBuffer dataPayload)
        {
            IByteBuffer headerBlock = Unpooled.Buffer();

            try
            {
                hpackEncoder.EncodeHeaders(streamId, headerBlock, headers, NeverSensitiveDetector.Instance);
                Http2CodecUtil.WriteFrameHeader(output, headerBlock.ReadableBytes, Http2FrameTypes.Headers,
                                                new Http2Flags().EndOfHeaders(true), streamId);
                output.WriteBytes(headerBlock, headerBlock.ReadableBytes);

                Http2CodecUtil.WriteFrameHeader(output, dataPayload.ReadableBytes, Http2FrameTypes.Data, new Http2Flags().EndOfStream(true), streamId);
                output.WriteBytes(dataPayload);
            }
            finally
            {
                headerBlock.Release();
            }
        }
Ejemplo n.º 10
0
        public void FailedWhenDataFrameNotAssociateWithStream()
        {
            var input   = Unpooled.Buffer();
            var payload = Unpooled.Buffer();

            try
            {
                payload.WriteByte(1);

                Http2CodecUtil.WriteFrameHeader(input, payload.ReadableBytes, Http2FrameTypes.Data, new Http2Flags().EndOfStream(true), 0);
                input.WriteBytes(payload);
                Assert.Throws <Http2Exception>(() => frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object));
            }
            finally
            {
                payload.Release();
                input.Release();
            }
        }
Ejemplo n.º 11
0
        public void ReadUnknownFrame()
        {
            var input   = Unpooled.Buffer();
            var payload = Unpooled.Buffer();

            try
            {
                payload.WriteByte(1);

                Http2CodecUtil.WriteFrameHeader(input, payload.ReadableBytes, (Http2FrameTypes)0xff, new Http2Flags(), 0);
                input.WriteBytes(payload);
                this.frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object);

                this.listener.Verify(x => x.OnUnknownFrame(this.ctx.Object, (Http2FrameTypes)0xff, 0, new Http2Flags(), payload.Slice(0, 1)));
            }
            finally
            {
                payload.Release();
                input.Release();
            }
        }
Ejemplo n.º 12
0
 private static void WritePriorityFrame(IByteBuffer output, int streamId, int streamDependency, int weight)
 {
     Http2CodecUtil.WriteFrameHeader(output, 5, Http2FrameTypes.Priority, new Http2Flags(), streamId);
     output.WriteInt(streamDependency);
     output.WriteByte(weight - 1);
 }