-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFixedHeaderAuthenticatedMessageProvider.cs
35 lines (30 loc) · 1.26 KB
/
FixedHeaderAuthenticatedMessageProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Arcane.Framework.Sources.RestApi.Services.AuthenticatedMessageProviders.Base;
namespace Arcane.Framework.Sources.RestApi.Services.AuthenticatedMessageProviders;
/// <summary>
/// Authenticated message provider that adds fixed headers to the request.
/// </summary>
public record FixedHeaderAuthenticatedMessageProvider : IRestApiAuthenticatedMessageProvider
{
private readonly Dictionary<string, string> customHeaders;
/// <summary>
/// Authenticated message provider that adds fixed headers to the request.
/// </summary>
/// <param name="customHeaders">Headers collection to add to the HTTP message</param>
public FixedHeaderAuthenticatedMessageProvider(Dictionary<string, string> customHeaders)
{
this.customHeaders = customHeaders;
}
/// <inheritdoc cref="IRestApiAuthenticatedMessageProvider.GetAuthenticatedMessage"/>
public Task<HttpRequestMessage> GetAuthenticatedMessage(HttpClient httpClient = null)
{
var msg = new HttpRequestMessage();
foreach (var (header, headerValue) in this.customHeaders)
{
msg.Headers.Add(header, headerValue);
}
return Task.FromResult(msg);
}
}