Skip to content

Commit 74f974a

Browse files
authored
Add a snippet about header propogation
1 parent e2b2df1 commit 74f974a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

aspnetcore/fundamentals/http-requests.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,43 @@ In the following example:
957957

958958
[!code-csharp[](http-requests/samples/2.x/HttpClientFactoryConsoleSample/Program.cs?highlight=14-15,20,26-27,59-62)]
959959

960+
## Header propogation middleware
961+
962+
Header propogation is an ASP.NET Core middleware to propagate HTTP headers from the incoming request to the outgoing HTTP Client requests. To use it,
963+
964+
* Reference the [`Microsoft.AspNetCore.HeaderPropagation`](https://www.nuget.org/packages/Microsoft.AspNetCore.HeaderPropagation) package. For projects targeting .NET Core 2.1, consider using the community supported port of the package - [`HeaderPropogation`](https://www.nuget.org/packages/HeaderPropagation).
965+
966+
* Configure the middleware and HttpClient in your Startup:
967+
968+
```C#
969+
// Startup.cs
970+
public void ConfigureServices(IServiceCollection services)
971+
{
972+
services.AddHeaderPropagation(options =>
973+
{
974+
options.Headers.Add("Trace-Id");
975+
}
976+
977+
services.AddHttpClient("MyForwardingClient")
978+
.AddHeaderPropogation();
979+
}
980+
981+
public void Configure(IApplicationBuilder app)
982+
{
983+
app.UseHeaderPropogation();
984+
app.UseRouting();
985+
...
986+
}
987+
```
988+
989+
* The client will include the configured headers on outbound requests:
990+
991+
```C#
992+
var client = clientFactory.CreateClient("MyForwardingClient");
993+
var response = client.GetAsync(...);
994+
```
995+
996+
960997
## Additional resources
961998

962999
* [Use HttpClientFactory to implement resilient HTTP requests](/dotnet/standard/microservices-architecture/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests)

0 commit comments

Comments
 (0)