예제 #1
0
        public void ReadHeaderFrame()
        {
            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(true).EndOfStream(true);
                this.WriteHeaderFrame(input, streamId, headers, flags);
                this.frameReader.ReadFrame(this.ctx.Object, input, this.listener.Object);

                this.listener.Verify(x => x.OnHeadersRead(this.ctx.Object, 1, headers, 0, true));
            }
            finally
            {
                input.Release();
            }
        }
예제 #2
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();
            }
        }
예제 #3
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();
            }
        }
예제 #4
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();
            }
        }
예제 #5
0
 public void OnUnknownFrame(IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload)
 {
 }
 public void WriteInboundFrame(Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload)
 {
     _writer.WriteFrameAsync(_ctx, frameType, streamId, flags, payload, _ctx.NewPromise()).GetAwaiter().GetResult();
 }
예제 #7
0
 public void OnUnknownFrame(IChannelHandlerContext ctx, Http2FrameTypes frameType, int streamId, Http2Flags flags, IByteBuffer payload)
 {
     this.listener.OnUnknownFrame(ctx, frameType, streamId, flags, payload);
     this.messageLatch.SafeSignal();
 }