Browse Source

Fix pipelining (#8530)

Sébastien Ros 1 year ago
parent
commit
747178475e

+ 8 - 47
frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.HttpConnection.cs

@@ -110,9 +110,8 @@ public partial class BenchmarkApplication : IHttpConnection
         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)
@@ -140,57 +139,19 @@ public partial class BenchmarkApplication : IHttpConnection
 
         _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()