Skip to content

Commit

Permalink
Fix pipelining (#8530)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros authored Nov 8, 2023
1 parent b7ddeff commit 7471784
Showing 1 changed file with 8 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ private async Task HandleRequestAsync(ReadOnlySequence<byte> buffer)
Reader.AdvanceTo(buffer.Start, buffer.End);
}

private void ParseHttpRequest(ref ReadOnlySequence<byte> buffer, bool isCompleted)
private void ParseHttpRequest(ref SequenceReader<byte> reader, ref ReadOnlySequence<byte> buffer, bool isCompleted)
{
var reader = new SequenceReader<byte>(buffer);
var state = _state;

if (state == State.StartLine)
Expand Down Expand Up @@ -140,57 +139,19 @@ private void ParseHttpRequest(ref ReadOnlySequence<byte> buffer, bool isComplete

_state = state;

if (state == State.Body)
{
// Complete request read, consumed and examined are the same (length 0)
buffer = buffer.Slice(reader.Position, 0);
}
else
{
// In-complete request read, consumed is current position and examined is the remaining.
buffer = buffer.Slice(reader.Position);
}
}

private void ParseHttpRequest(ref SequenceReader<byte> reader, ref ReadOnlySequence<byte> buffer, bool isCompleted)
{
var state = _state;

if (state == State.StartLine)
if (_requestType != RequestType.Json && _requestType != RequestType.PlainText)
{
if (Parser.ParseRequestLine(new ParsingAdapter(this), ref reader))
if (state == State.Body)
{
state = State.Headers;
// Complete request read, consumed and examined are the same (length 0)
buffer = buffer.Slice(reader.Position, 0);
}
}

if (state == State.Headers)
{
var success = Parser.ParseHeaders(new ParsingAdapter(this), ref reader);

if (success)
else
{
state = State.Body;
// In-complete request read, consumed is current position and examined is the remaining.
buffer = buffer.Slice(reader.Position);
}
}

if (state != State.Body && isCompleted)
{
ThrowUnexpectedEndOfData();
}

_state = state;

if (state == State.Body)
{
// Complete request read, consumed and examined are the same (length 0)
buffer = buffer.Slice(reader.Position, 0);
}
else
{
// In-complete request read, consumed is current position and examined is the remaining.
buffer = buffer.Slice(reader.Position);
}
}

private static HtmlEncoder CreateHtmlEncoder()
Expand Down

0 comments on commit 7471784

Please sign in to comment.