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); }
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)); }
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)); }
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)); }