tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
ApiHeadersProvider.cs
Go to the documentation of this file.
1using System;
2
3using Microsoft.AspNetCore.Http;
4
6
8{
11 {
15 : CreateApiHeaders(false);
16
18 public HeadersException? HeadersException { get; private set; }
19
23 readonly IHttpContextAccessor httpContextAccessor;
24
29
34
39 public ApiHeadersProvider(IHttpContextAccessor httpContextAccessor)
40 {
41 this.httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
42 }
43
46
53 {
54 if (httpContextAccessor.HttpContext == null)
55 throw new InvalidOperationException("httpContextAccessor has no HttpContext!");
56
57 var typedHeaders = httpContextAccessor.HttpContext.Request.GetTypedHeaders();
58 if (!authless)
60
61 try
62 {
63 var headers = new ApiHeaders(typedHeaders, authless, !authless);
64 if (!authless)
65 apiHeaders = headers;
66
67 return headers;
68 }
69 catch (HeadersException ex) when (!authless)
70 {
72 return null;
73 }
74 }
75 }
76}
Represents the header that must be present for every server request.
Definition ApiHeaders.cs:25
Thrown when trying to generate ApiHeaders from Microsoft.AspNetCore.Http.Headers.RequestHeaders fails...
ApiHeadersProvider(IHttpContextAccessor httpContextAccessor)
Initializes a new instance of the ApiHeadersProvider class.
bool attemptedApiHeadersCreation
If populating ApiHeaders was previously attempted.
ApiHeaders CreateAuthlessHeaders()
Attempt to create Api.ApiHeaders without checking for the presence of an Microsoft....
readonly IHttpContextAccessor httpContextAccessor
The IHttpContextAccessor for the ApiHeadersProvider.
ApiHeaders? ApiHeaders
The created Api.ApiHeaders, if any.
ApiHeaders? CreateApiHeaders(bool authless)
Attempt to parse Api.ApiHeaders from the HttpContext, optionally populating the class properties.
ApiHeaders? apiHeaders
Backing field for ApiHeaders.