tgstation-server 6.12.3
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AuthorizationMessageHandler.cs
Go to the documentation of this file.
1using System.Net.Http;
2using System.Net.Http.Headers;
3using System.Threading;
4using System.Threading.Tasks;
5
7{
12 {
16 public static AsyncLocal<AuthenticationHeaderValue?> Header { get; } = new AsyncLocal<AuthenticationHeaderValue?>();
17
21 readonly AuthenticationHeaderValue? headerOverride;
22
27 public AuthorizationMessageHandler(AuthenticationHeaderValue? headerOverride)
28 {
29 this.headerOverride = headerOverride;
30 }
31
33 protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
34 {
35 var currentAuthHeader = headerOverride ?? Header.Value;
36 if (currentAuthHeader != null)
37 request.Headers.Authorization = currentAuthHeader;
38
39 return base.SendAsync(request, cancellationToken);
40 }
41 }
42}
DelegatingHandler that applies the AuthenticationHeaderValue.
override Task< HttpResponseMessage > SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
static AsyncLocal< AuthenticationHeaderValue?> Header
The AsyncLocal<T> AuthenticationHeaderValue to be applied.
AuthorizationMessageHandler(AuthenticationHeaderValue? headerOverride)
Initializes a new instance of the AuthorizationMessageHandler class.
readonly? AuthenticationHeaderValue headerOverride
class override for Header.