From 747178475e9b1e37ff00cb59f1f6e70d06790217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ros?= Date: Wed, 8 Nov 2023 15:45:30 -0800 Subject: [PATCH] Fix pipelining (#8530) --- .../BenchmarkApplication.HttpConnection.cs | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.HttpConnection.cs b/frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.HttpConnection.cs index 18aca87eb70..cbd375cb61b 100644 --- a/frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.HttpConnection.cs +++ b/frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.HttpConnection.cs @@ -110,9 +110,8 @@ private async Task HandleRequestAsync(ReadOnlySequence buffer) Reader.AdvanceTo(buffer.Start, buffer.End); } - private void ParseHttpRequest(ref ReadOnlySequence buffer, bool isCompleted) + private void ParseHttpRequest(ref SequenceReader reader, ref ReadOnlySequence buffer, bool isCompleted) { - var reader = new SequenceReader(buffer); var state = _state; if (state == State.StartLine) @@ -140,57 +139,19 @@ private void ParseHttpRequest(ref ReadOnlySequence 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 reader, ref ReadOnlySequence 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()