Skip to content

Commit

Permalink
Perf improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla committed Dec 12, 2023
1 parent ffc1740 commit 2cb0e4a
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ internal class HttpInListener : ListenerHandler
private const string DiagnosticSourceName = "Microsoft.AspNetCore";
private const string UnknownHostName = "UNKNOWN-HOST";

private static readonly Func<HttpRequest, string, IEnumerable<string>> HttpRequestHeaderValuesGetter = (request, name) => request.Headers[name];
private static readonly Func<HttpRequest, string, IEnumerable<string>> HttpRequestHeaderValuesGetter = (request, name) =>
{
if (request.Headers.TryGetValue(name, out var value))
{
// This causes allocation as the `StringValues` struct has to be casted to an `IEnumerable<string>` object.
return value;
}

return Enumerable.Empty<string>();
};

private static readonly PropertyFetcher<Exception> ExceptionPropertyFetcher = new("Exception");

#if !NET6_0_OR_GREATER
Expand Down

0 comments on commit 2cb0e4a

Please sign in to comment.