-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Extensions.Microsoft.Http/src/AddDefaultRequestHeaderHttpClientBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Extensions.Microsoft.Http; | ||
|
||
public static class AddDefaultRequestHeaderHttpClientBuilderExtensions | ||
{ | ||
public static IHttpClientBuilder AddDefaultRequestHeader(this IHttpClientBuilder builder, string name, string? value) | ||
=> builder.ConfigureHttpClient((serviceProvider, client) => client.DefaultRequestHeaders.Add(name, value)); | ||
|
||
public static IHttpClientBuilder AddDefaultRequestHeader(this IHttpClientBuilder builder, string name, Func<IServiceProvider, string?> configureValue) | ||
=> builder.ConfigureHttpClient((serviceProvider, client) => | ||
{ | ||
var value = configureValue(serviceProvider); | ||
client.DefaultRequestHeaders.Add(name, value); | ||
}); | ||
|
||
public static IHttpClientBuilder AddDefaultRequestHeader(this IHttpClientBuilder builder, string name, IEnumerable<string?> values) | ||
=> builder.ConfigureHttpClient((serviceProvider, client) => client.DefaultRequestHeaders.Add(name, values)); | ||
|
||
public static IHttpClientBuilder AddDefaultRequestHeader(this IHttpClientBuilder builder, string name, Func<IServiceProvider, IEnumerable<string?>> configureValues) | ||
=> builder.ConfigureHttpClient((serviceProvider, client) => | ||
{ | ||
var values = configureValues(serviceProvider); | ||
client.DefaultRequestHeaders.Add(name, values); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters