Skip to content

HTTP1 not trimming trailing CRLF's in final header #34402

@wtgodbe

Description

@wtgodbe

Running the Http1ConnectionParsingOverheadBenchmark benchmark in Kestrel (https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/perf/Microbenchmarks/Http1ConnectionParsingOverheadBenchmark.cs), the value returned by

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);
}
}
will end with CR LF CR LF for the final header sent:

at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.HttpUtilities.GetRequestHeaderString(ReadOnlySpan1 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.

CC @Tratcher @halter73 @BrennanConroy @JamesNK

Metadata

Metadata

Assignees

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions