You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LoggingHttpMessageHandler changes HttpHeaders added with TryAddWithoutValidation when Trace logging is enabled #132009
LoggingHttpMessageHandler changes the observable behavior of HttpRequestMessage when a known header is added using HttpHeaders.TryAddWithoutValidation().
When LogLevel.Trace is enabled for Microsoft.Extensions.Http, the logging pipeline enumerates HttpHeaders, which causes lazily stored raw header values to become materialized as typed headers.
As a result, the request sent over the wire differs from the original request.
This does not happen when:
using new HttpClient();
or calling RemoveAllLoggers() on IHttpClientBuilder;
or disabling Trace logging.
Reproduction Steps
Mimimal reproduction:
var services = new ServiceCollection();
services.AddLogging(builder =>
{
builder.SetMinimumLevel(LogLevel.Trace);
});
services.AddHttpClient("test");
var provider = services.BuildServiceProvider();
var factory = provider.GetRequiredService<IHttpClientFactory>();
var client = factory.CreateClient("test");
var request = new HttpRequestMessage(HttpMethod.Get, "https://example.com");
request.Headers.TryAddWithoutValidation(
"Accept",
"application/vnd.example+json;version=1");
await client.SendAsync(request);
Thanks for the report. We should be enumerating via the NonValidated API if our goal is to log the values. We don't need them to be parsed (waste of perf + possible subtle differences as noted here)
Activity
dotnet-policy-service commentedon Aug 7, 2026
Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.
MihaZupan commentedon Aug 7, 2026
Thanks for the report. We should be enumerating via the NonValidated API if our goal is to log the values. We don't need them to be parsed (waste of perf + possible subtle differences as noted here)