![]() |
VOOZH | about |
dotnet add package Microsoft.AspNetCore.HeaderParsing --version 10.7.0
NuGet\Install-Package Microsoft.AspNetCore.HeaderParsing -Version 10.7.0
<PackageReference Include="Microsoft.AspNetCore.HeaderParsing" Version="10.7.0" />
<PackageVersion Include="Microsoft.AspNetCore.HeaderParsing" Version="10.7.0" />Directory.Packages.props
<PackageReference Include="Microsoft.AspNetCore.HeaderParsing" />Project file
paket add Microsoft.AspNetCore.HeaderParsing --version 10.7.0
#r "nuget: Microsoft.AspNetCore.HeaderParsing, 10.7.0"
#:package Microsoft.AspNetCore.HeaderParsing@10.7.0
#addin nuget:?package=Microsoft.AspNetCore.HeaderParsing&version=10.7.0Install as a Cake Addin
#tool nuget:?package=Microsoft.AspNetCore.HeaderParsing&version=10.7.0Install as a Cake Tool
This package provides services for strongly typed header parsing and value caching.
In particular:
From the command-line:
dotnet add package Microsoft.AspNetCore.HeaderParsing
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.HeaderParsing" Version="[CURRENTVERSION]" />
</ItemGroup>
The services can be registered using one of the AddHeaderParsing overloads:
public static IServiceCollection AddHeaderParsing(this IServiceCollection services)
public static IServiceCollection AddHeaderParsing(this IServiceCollection services, Action<HeaderParsingOptions> configure)
public static IServiceCollection AddHeaderParsing(this IServiceCollection services, IConfigurationSection section)
For example:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHeaderParsing();
var app = builder.Build();
For each header that you want to parse, you need to register an instance of a HeaderSetup class which will define how a named parser should be parsed, and if the resulting strongly-typed values should be cached in memory.
Instances of HeaderSetup for the most common headers are available in the CommonHeaders class.
Instances of HeaderSetup should be reused during the application lifetime. It is recommended to keep their reference in objects registered as singletons.
var headerRegistry = app.Services.GetRequiredService<IHeaderRegistry>();
var encodingKey = headerRegistry.Register(CommonHeaders.AcceptEncoding);
The following example parses the Accept-Encoding request header to return a list of values:
app.MapGet("/", string (HttpContext context) =>
{
if (context.Request.TryGetHeaderValue(encodingKey, out var encoding))
{
return string.Join(", ", encoding);
}
return "";
});
The CommonHeaders class contains the following reusable header parsers:
X-Forwarded-For)The HeaderParsingOptions class is used to configure common behaviors for this feature.
DefaultValues option.MaxCachedValuesPerHeader option. If not configured the DefaultMaxCachedValuesPerHeader value will be used.The package generates the following metrics:
| Metric name | Metric value | Dimension | Dimension value |
|---|---|---|---|
HeaderParsing.ParsingErrors |
Increased by 1 with every parsing error | HeaderName |
Header name |
Kind |
Error message returned by the TryParse() method |
||
HeaderParsing.CacheAccess |
Increased by 1 with every cache hit or miss | HeaderName |
Header name |
Type |
Either Hit or Miss for the internal header cache hits and misses respectively |
Although this package provides support for parsing many HTTP headers, you sometimes need to parse custom headers.
You can easily extend the header parsing model to support your custom headers by implementing the abstract class HeaderParser and then register an
instance of this class in the IHeaderRegistry interface.
We welcome feedback and contributions in our GitHub repo.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.7.0 | 108 | 6/9/2026 |
| 10.6.0 | 239 | 5/12/2026 |
| 10.5.0 | 302 | 4/15/2026 |
| 10.4.0 | 363 | 3/10/2026 |
| 10.3.0 | 495 | 2/10/2026 |
| 10.2.0 | 459 | 1/13/2026 |
| 10.1.0 | 596 | 12/9/2025 |
| 10.0.0 | 459 | 11/11/2025 |
| 9.10.0 | 321 | 10/14/2025 |
| 9.9.0 | 268 | 9/9/2025 |
| 9.8.0 | 250 | 8/12/2025 |
| 9.7.0 | 227 | 7/8/2025 |
| 9.6.0 | 407 | 6/10/2025 |
| 9.5.0 | 385 | 5/13/2025 |
| 9.4.0 | 1,323 | 4/8/2025 |
| 9.3.0 | 339 | 3/11/2025 |
| 9.2.0 | 368 | 2/11/2025 |
| 9.1.0 | 245 | 1/14/2025 |
| 9.0.0 | 1,192 | 11/12/2024 |
| 8.10.0 | 735 | 10/8/2024 |