-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Running the Http1ConnectionParsingOverheadBenchmark benchmark in Kestrel (https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionParsingOverheadBenchmark.cs), the value returned by
aspnetcore/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.cs
Lines 111 to 138 in 0f37ede
| public static string GetRequestHeaderString(this ReadOnlySpan<byte> span, string name, Func<string, Encoding?> encodingSelector) | |
| { | |
| if (ReferenceEquals(KestrelServerOptions.DefaultHeaderEncodingSelector, encodingSelector)) | |
| { | |
| return span.GetAsciiOrUTF8StringNonNullCharacters(DefaultRequestHeaderEncoding); | |
| } | |
| var encoding = encodingSelector(name); | |
| if (encoding is null) | |
| { | |
| return span.GetAsciiOrUTF8StringNonNullCharacters(DefaultRequestHeaderEncoding); | |
| } | |
| if (ReferenceEquals(encoding, Encoding.Latin1)) | |
| { | |
| return span.GetLatin1StringNonNullCharacters(); | |
| } | |
| try | |
| { | |
| return encoding.GetString(span); | |
| } | |
| catch (DecoderFallbackException ex) | |
| { | |
| throw new InvalidOperationException(ex.Message, ex); | |
| } | |
| } |
CR LF CR LF for the final header sent:
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.HttpUtilities.GetRequestHeaderString(ReadOnlySpan
1 span, String name, Func2 encodingSelector) in C:\code\aspnet\aspnetcore\src\Servers\Kestrel\Core\src\Internal\Infrastructure\HttpUtilities.cs:line 151
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestHeaders.Append(ReadOnlySpan1 name, ReadOnlySpan1 value) in C:\code\aspnet\aspnetcore\src\Servers\Kestrel\Core\src\Internal\Http\HttpHeaders.Generated.cs:line 7433
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.OnHeader(ReadOnlySpan1 name, ReadOnlySpan1 value) in C:\code\aspnet\aspnetcore\src\Servers\Kestrel\Core\src\Internal\Http\HttpProtocol.cs:line 524
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ParsingHandler.OnHeader(ReadOnlySpan1 name, ReadOnlySpan1 value) in C:\code\aspnet\aspnetcore\src\Servers\Kestrel\Core\src\Internal\Http\Http1ParsingHandler.cs:line 34
at Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks.NullParser1.ParseHeaders(TRequestHandler handler, SequenceReader1& reader) in C:\code\aspnet\aspnetcore\src\Servers\Kestrel\perf\Microbenchmarks\Mocks\NullParser.cs:line 27
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.TakeMessageHeaders(SequenceReader`1& reader, Boolean trailers) in C:\code\aspnet\aspnetcore\src\Servers\Kestrel\Core\src\Internal\Http\Http1Connection.cs:line 221
at Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks.Http1ConnectionParsingOverheadBenchmark.ParseRequest() in C:\code\aspnet\aspnetcore\src\Servers\Kestrel\perf\Microbenchmarks\Http1ConnectionParsingOverheadBenchmark.cs:line 86
at Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks.Http1ConnectionParsingOverheadBenchmark.Http1ConnectionOverheadTotal() in C:\code\aspnet\aspnetcore\src\Servers\Kestrel\perf\Microbenchmarks\Http1ConnectionParsingOverheadBenchmark.cs:line 54
Specifically, the string returned is text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7\r\n\r\n, from here: https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/perf/Microbenchmarks/RequestParsingData.cs
HTTP1 should trim these control characters before calling the method.