|
@@ -2,6 +2,7 @@
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
|
|
using System;
|
|
using System;
|
|
|
|
+using System.Buffers.Text;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.IO.Pipelines;
|
|
using System.IO.Pipelines;
|
|
using System.Text.Encodings.Web;
|
|
using System.Text.Encodings.Web;
|
|
@@ -42,27 +43,48 @@ namespace PlatformBenchmarks
|
|
public readonly static AsciiString Plaintext = "/plaintext";
|
|
public readonly static AsciiString Plaintext = "/plaintext";
|
|
public readonly static AsciiString Json = "/json";
|
|
public readonly static AsciiString Json = "/json";
|
|
public readonly static AsciiString Fortunes = "/fortunes";
|
|
public readonly static AsciiString Fortunes = "/fortunes";
|
|
|
|
+ public readonly static AsciiString SingleQuery = "/db";
|
|
|
|
+ public readonly static AsciiString MultipleQueries = "/queries/count=";
|
|
}
|
|
}
|
|
|
|
|
|
private RequestType _requestType;
|
|
private RequestType _requestType;
|
|
|
|
+ private int _queries;
|
|
|
|
|
|
public void OnStartLine(HttpMethod method, HttpVersion version, Span<byte> target, Span<byte> path, Span<byte> query, Span<byte> customMethod, bool pathEncoded)
|
|
public void OnStartLine(HttpMethod method, HttpVersion version, Span<byte> target, Span<byte> path, Span<byte> query, Span<byte> customMethod, bool pathEncoded)
|
|
{
|
|
{
|
|
var requestType = RequestType.NotRecognized;
|
|
var requestType = RequestType.NotRecognized;
|
|
if (method == HttpMethod.Get)
|
|
if (method == HttpMethod.Get)
|
|
{
|
|
{
|
|
- if (Paths.Plaintext.Length <= path.Length && path.StartsWith(Paths.Plaintext))
|
|
|
|
|
|
+ var pathLength = path.Length;
|
|
|
|
+ if (Paths.SingleQuery.Length <= pathLength && path.StartsWith(Paths.SingleQuery))
|
|
{
|
|
{
|
|
- requestType = RequestType.PlainText;
|
|
|
|
|
|
+ requestType = RequestType.SingleQuery;
|
|
}
|
|
}
|
|
- else if (Paths.Json.Length <= path.Length && path.StartsWith(Paths.Json))
|
|
|
|
|
|
+ else if (Paths.Json.Length <= pathLength && path.StartsWith(Paths.Json))
|
|
{
|
|
{
|
|
requestType = RequestType.Json;
|
|
requestType = RequestType.Json;
|
|
}
|
|
}
|
|
- else if (Paths.Fortunes.Length <= path.Length && path.StartsWith(Paths.Fortunes))
|
|
|
|
|
|
+ else if (Paths.Fortunes.Length <= pathLength && path.StartsWith(Paths.Fortunes))
|
|
{
|
|
{
|
|
requestType = RequestType.Fortunes;
|
|
requestType = RequestType.Fortunes;
|
|
}
|
|
}
|
|
|
|
+ else if (Paths.Plaintext.Length <= pathLength && path.StartsWith(Paths.Plaintext))
|
|
|
|
+ {
|
|
|
|
+ requestType = RequestType.PlainText;
|
|
|
|
+ }
|
|
|
|
+ else if (Paths.MultipleQueries.Length <= pathLength && path.StartsWith(Paths.MultipleQueries))
|
|
|
|
+ {
|
|
|
|
+ if (!Utf8Parser.TryParse(path.Slice(Paths.MultipleQueries.Length), out int queries, out _) || queries < 1)
|
|
|
|
+ {
|
|
|
|
+ queries = 1;
|
|
|
|
+ }
|
|
|
|
+ else if (queries > 500)
|
|
|
|
+ {
|
|
|
|
+ queries = 500;
|
|
|
|
+ }
|
|
|
|
+ _queries = queries;
|
|
|
|
+ requestType = RequestType.MultipleQueries;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
_requestType = requestType;
|
|
_requestType = requestType;
|
|
@@ -82,6 +104,14 @@ namespace PlatformBenchmarks
|
|
{
|
|
{
|
|
return Fortunes(Writer);
|
|
return Fortunes(Writer);
|
|
}
|
|
}
|
|
|
|
+ else if (_requestType == RequestType.SingleQuery)
|
|
|
|
+ {
|
|
|
|
+ return SingleQuery(Writer);
|
|
|
|
+ }
|
|
|
|
+ else if (_requestType == RequestType.MultipleQueries)
|
|
|
|
+ {
|
|
|
|
+ return MultipleQueries(Writer, _queries);
|
|
|
|
+ }
|
|
else
|
|
else
|
|
{
|
|
{
|
|
Default(Writer);
|
|
Default(Writer);
|
|
@@ -116,7 +146,9 @@ namespace PlatformBenchmarks
|
|
NotRecognized,
|
|
NotRecognized,
|
|
PlainText,
|
|
PlainText,
|
|
Json,
|
|
Json,
|
|
- Fortunes
|
|
|
|
|
|
+ Fortunes,
|
|
|
|
+ SingleQuery,
|
|
|
|
+ MultipleQueries
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|