示例#1
0
    public static void WriteData(this PipeWriter writer, int streamId, Memory <byte> data, bool endStream, Http2Frame frame = null)
    {
        frame ??= new Http2Frame();
        frame.PrepareData(streamId);
        frame.PayloadLength = data.Length;
        frame.DataFlags     = endStream ? Http2DataFrameFlags.END_STREAM : Http2DataFrameFlags.NONE;

        Http2FrameWriter.WriteHeader(frame, writer);
        writer.Write(data.Span);
    }
示例#2
0
        protected Task SendDataAsync(int streamId, Span <byte> data, bool endStream)
        {
            var frame = new Http2Frame((uint)data.Length);

            frame.PrepareData(streamId);
            frame.PayloadLength = data.Length;
            frame.DataFlags     = endStream ? Http2DataFrameFlags.END_STREAM : Http2DataFrameFlags.NONE;
            data.CopyTo(frame.DataPayload);

            return(SendAsync(frame.Raw));
        }
        public Task SendDataAsync(int streamId, Memory <byte> data, bool endStream)
        {
            var outputWriter = _pair.Application.Output;
            var frame        = new Http2Frame();

            frame.PrepareData(streamId);
            frame.PayloadLength = data.Length;
            frame.DataFlags     = endStream ? Http2DataFrameFlags.END_STREAM : Http2DataFrameFlags.NONE;

            WriteHeader(frame, outputWriter);
            return(SendAsync(data.Span));
        }
示例#4
0
        protected Task SendInvalidDataFrameAsync(int streamId, int frameLength, byte padLength)
        {
            Assert.True(padLength >= frameLength, $"{nameof(padLength)} must be greater than or equal to {nameof(frameLength)} to create an invalid frame.");

            var frame = new Http2Frame(Http2Limits.MinAllowedMaxFrameSize);

            frame.PrepareData(streamId);
            frame.DataFlags  = Http2DataFrameFlags.PADDED;
            frame.Payload[0] = padLength;

            // Set length last so .Payload can be written to
            frame.PayloadLength = frameLength;

            return(SendAsync(frame.Raw));
        }
示例#5
0
        protected Task SendDataWithPaddingAsync(int streamId, Span <byte> data, byte padLength, bool endStream)
        {
            var frame = new Http2Frame(Http2Limits.MinAllowedMaxFrameSize);

            frame.PrepareData(streamId, padLength);
            frame.PayloadLength = data.Length + 1 + padLength;
            data.CopyTo(frame.DataPayload);

            if (endStream)
            {
                frame.DataFlags |= Http2DataFrameFlags.END_STREAM;
            }

            return(SendAsync(frame.Raw));
        }
        public async Task SendDataWithPaddingAsync(int streamId, Memory <byte> data, byte padLength, bool endStream)
        {
            var outputWriter = _pair.Application.Output;
            var frame        = new Http2Frame();

            frame.PrepareData(streamId, padLength);
            frame.PayloadLength = data.Length + 1 + padLength;

            if (endStream)
            {
                frame.DataFlags |= Http2DataFrameFlags.END_STREAM;
            }

            WriteHeader(frame, outputWriter);
            outputWriter.GetSpan(1)[0] = padLength;
            outputWriter.Advance(1);
            await SendAsync(data.Span);
            await SendAsync(new byte[padLength]);
        }
        public Task SendInvalidDataFrameAsync(int streamId, int frameLength, byte padLength)
        {
            Assert.True(padLength >= frameLength, $"{nameof(padLength)} must be greater than or equal to {nameof(frameLength)} to create an invalid frame.");

            var outputWriter = _pair.Application.Output;
            var frame        = new Http2Frame();

            frame.PrepareData(streamId);
            frame.DataFlags     = Http2DataFrameFlags.PADDED;
            frame.PayloadLength = frameLength;
            var payload = new byte[frameLength];

            if (frameLength > 0)
            {
                payload[0] = padLength;
            }

            WriteHeader(frame, outputWriter);
            return(SendAsync(payload));
        }