Skip to content

Commit

Permalink
Avoid allocations in 'Transfer-Encoding: Chunked' check (dotnet#81253)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan authored Jan 27, 2023
1 parent f388963 commit d2eed6c
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,25 @@ public DateTimeOffset? Date

internal static bool? GetTransferEncodingChunked(HttpHeaders parent, HttpGeneralHeaders? headers)
{
if (parent.ContainsParsedValue(KnownHeaders.TransferEncoding.Descriptor, HeaderUtilities.TransferEncodingChunked))
if (parent.TryGetHeaderValue(KnownHeaders.TransferEncoding.Descriptor, out object? value))
{
return true;
// Fast-path for the very common case where "chunked" is the only value.
if (value is string stringValue && stringValue.Equals("chunked", StringComparison.OrdinalIgnoreCase))
{
return true;
}

if (parent.ContainsParsedValue(KnownHeaders.TransferEncoding.Descriptor, HeaderUtilities.TransferEncodingChunked))
{
return true;
}
}

if (headers != null && headers._transferEncodingChunkedSet)
{
return false;
}

return null;
}

Expand Down

0 comments on commit d2eed6c

Please sign in to comment.