HeaderPropagation 2.0.0
See the version list below for details.
dotnet add package HeaderPropagation --version 2.0.0
NuGet\Install-Package HeaderPropagation -Version 2.0.0
<PackageReference Include="HeaderPropagation" Version="2.0.0" />
paket add HeaderPropagation --version 2.0.0
#r "nuget: HeaderPropagation, 2.0.0"
// Install HeaderPropagation as a Cake Addin #addin nuget:?package=HeaderPropagation&version=2.0.0 // Install HeaderPropagation as a Cake Tool #tool nuget:?package=HeaderPropagation&version=2.0.0
This is a backport to ASP.NET Core 2.1 (and 2.2) of the HeaderPropagation middleware I had recently contributed to the ASP.NET Core project. All code is licensed under the Apache License, Version 2.0 and copyrighted by the .NET Foundation.
Motivation
I believe it is a common use case which deserves to be included in ASP.NET Core. Its main use case is probably to track distributed transaction which requires the ability to pass through a transaction identifier as well as generating a new one when not present.
Given the ASP.NET Core 3.0 release is quite far away, and the current policy doesn't allow to backport new features to already shipped releases, I have created this package as recommended so it can be used today on projects based on ASP.NET Core 2.1 or 2.2.
Usage
In Startup.Configure
enable the middleware:
app.UseHeaderPropagation();
In Startup.ConfigureServices
add the required services, eventually specifying a configuration action:
services.AddHeaderPropagation(o =>
{
// propagate the header if present
o.Headers.Add("User-Agent");
// if still missing, set it with a value factory
o.Headers.Add("User-Agent", context => "Mozilla/5.0 (trust me, I'm really Mozilla!)");
// propagate the header if present, using a different name in the outbound request
o.Headers.Add("Accept-Language", "Lang");
});
If you are using the HttpClientFactory
, add the DelegatingHandler
to the client configuration using the AddHeaderPropagation
extension method.
services.AddHttpClient<GitHubClient>(c =>
{
c.BaseAddress = new Uri("https://api.github.com/");
c.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
}).AddHeaderPropagation();
Behaviour
HeaderPropagationOptions
contains a dictionary where the key represent the name of the header to consume from the incoming request.
Each entry define the behaviour to propagate that header as follows:
OutboundHeaderName
determines the name of the header to be used for the outbound http requests.When present, the
ValueFactory
is the only method used to set the value. The factory should returnStringValues.Empty
to not add the header.If multiple configurations for the same header are present, the first which returns a value wins.
Please note the factory is called only once per incoming request and the same value will be used by all the outbound calls.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Http (>= 2.1.1)
- Microsoft.Extensions.DependencyInjection (>= 2.1.1)
- Microsoft.Extensions.Http (>= 2.1.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on HeaderPropagation:
Package | Downloads |
---|---|
ASK.HAL.Mvc
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.