Esempio n. 1
0
        static void ReadGoAwayFrame(IChannelHandlerContext ctx, IByteBuffer payload, int payloadEndIndex, IHttp2FrameListener listener)
        {
            int         lastStreamId = Http2CodecUtil.ReadUnsignedInt(payload);
            var         errorCode    = (Http2Error)payload.ReadUnsignedInt();
            IByteBuffer debugData    = payload.ReadSlice(payloadEndIndex - payload.ReaderIndex);

            listener.OnGoAwayRead(ctx, lastStreamId, errorCode, debugData);
        }
Esempio n. 2
0
        void ReadWindowUpdateFrame(IChannelHandlerContext ctx, IByteBuffer payload, IHttp2FrameListener listener)
        {
            int windowSizeIncrement = Http2CodecUtil.ReadUnsignedInt(payload);

            if (0u >= (uint)windowSizeIncrement)
            {
                ThrowHelper.ThrowStreamError_ReceivedWindowUpdateWithDelta0ForStream(_streamId);
            }

            listener.OnWindowUpdateRead(ctx, _streamId, windowSizeIncrement);
        }
Esempio n. 3
0
        void ReadPushPromiseFrame(IChannelHandlerContext ctx, IByteBuffer payload, int payloadEndIndex, IHttp2FrameListener listener)
        {
            int pushPromiseStreamId = _streamId;
            int padding             = ReadPadding(payload);

            VerifyPadding(padding);
            int promisedStreamId = Http2CodecUtil.ReadUnsignedInt(payload);

            // Create a handler that invokes the listener when the header block is complete.
            _headersContinuation = new PushPromiseFrameHeadersContinuation(this,
                                                                           ctx, pushPromiseStreamId, padding, promisedStreamId);

            // Process the initial fragment, invoking the listener's callback if end of headers.
            int dataLength = LengthWithoutTrailingPadding(payloadEndIndex - payload.ReaderIndex, padding);

            _headersContinuation.ProcessFragment(_flags.EndOfHeaders(), payload, dataLength, listener);
            ResetHeadersContinuationIfEnd(_flags.EndOfHeaders());
        }
Esempio n. 4
0
        void ProcessHeaderState(IByteBuffer input)
        {
            if (input.ReadableBytes < Http2CodecUtil.FrameHeaderLength)
            {
                // Wait until the entire frame header has been read.
                return;
            }

            // Read the header and prepare the unmarshaller to read the frame.
            _payloadLength = input.ReadUnsignedMedium();
            if (_payloadLength > _maxFrameSize)
            {
                ThrowHelper.ThrowConnectionError_FrameLengthExceedsMaximum(_payloadLength, _maxFrameSize);
            }

            _frameType = (Http2FrameTypes)input.ReadByte();
            _flags     = new Http2Flags(input.ReadByte());
            _streamId  = Http2CodecUtil.ReadUnsignedInt(input);

            // We have consumed the data, next time we read we will be expecting to read the frame payload.
            _readingHeaders = false;

            switch (_frameType)
            {
            case Http2FrameTypes.Data:
                VerifyDataFrame();
                break;

            case Http2FrameTypes.Headers:
                VerifyHeadersFrame();
                break;

            case Http2FrameTypes.Priority:
                VerifyPriorityFrame();
                break;

            case Http2FrameTypes.RstStream:
                VerifyRstStreamFrame();
                break;

            case Http2FrameTypes.Settings:
                VerifySettingsFrame();
                break;

            case Http2FrameTypes.PushPromise:
                VerifyPushPromiseFrame();
                break;

            case Http2FrameTypes.Ping:
                VerifyPingFrame();
                break;

            case Http2FrameTypes.GoAway:
                VerifyGoAwayFrame();
                break;

            case Http2FrameTypes.WindowUpdate:
                VerifyWindowUpdateFrame();
                break;

            case Http2FrameTypes.Continuation:
                VerifyContinuationFrame();
                break;

            default:
                // Unknown frame type, could be an extension.
                VerifyUnknownFrame();
                break;
            }
        }