tgstation-server
6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
src
Tgstation.Server.Host
Utils
ApiHeadersProvider.cs
Go to the documentation of this file.
1
using
System;
2
3
using
Microsoft.AspNetCore.Http;
4
5
using
Tgstation.Server.Api
;
6
7
namespace
Tgstation.Server.Host.Utils
8
{
10
sealed
class
ApiHeadersProvider
:
IApiHeadersProvider
11
{
13
public
ApiHeaders
?
ApiHeaders
=>
attemptedApiHeadersCreation
14
?
apiHeaders
15
:
CreateApiHeaders
(
false
);
16
18
public
HeadersException
?
HeadersException
{
get
;
private
set
; }
19
23
readonly IHttpContextAccessor
httpContextAccessor
;
24
28
ApiHeaders
?
apiHeaders
;
29
33
bool
attemptedApiHeadersCreation
;
34
39
public
ApiHeadersProvider
(IHttpContextAccessor
httpContextAccessor
)
40
{
41
this.httpContextAccessor =
httpContextAccessor
??
throw
new
ArgumentNullException(nameof(
httpContextAccessor
));
42
}
43
45
public
ApiHeaders
CreateAuthlessHeaders
() =>
CreateApiHeaders
(
true
)!;
46
52
ApiHeaders
?
CreateApiHeaders
(
bool
authless)
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)
59
attemptedApiHeadersCreation
=
true
;
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
{
71
HeadersException
= ex;
72
return
null
;
73
}
74
}
75
}
76
}
Tgstation.Server.Api.ApiHeaders
Represents the header that must be present for every server request.
Definition
ApiHeaders.cs:25
Tgstation.Server.Api.HeadersException
Thrown when trying to generate ApiHeaders from Microsoft.AspNetCore.Http.Headers.RequestHeaders fails...
Definition
HeadersException.cs:9
Tgstation.Server.Host.Utils.ApiHeadersProvider
Definition
ApiHeadersProvider.cs:11
Tgstation.Server.Host.Utils.ApiHeadersProvider.ApiHeadersProvider
ApiHeadersProvider(IHttpContextAccessor httpContextAccessor)
Initializes a new instance of the ApiHeadersProvider class.
Definition
ApiHeadersProvider.cs:39
Tgstation.Server.Host.Utils.ApiHeadersProvider.attemptedApiHeadersCreation
bool attemptedApiHeadersCreation
If populating ApiHeaders was previously attempted.
Definition
ApiHeadersProvider.cs:33
Tgstation.Server.Host.Utils.ApiHeadersProvider.CreateAuthlessHeaders
ApiHeaders CreateAuthlessHeaders()
Attempt to create Api.ApiHeaders without checking for the presence of an Microsoft....
Tgstation.Server.Host.Utils.ApiHeadersProvider.httpContextAccessor
readonly IHttpContextAccessor httpContextAccessor
The IHttpContextAccessor for the ApiHeadersProvider.
Definition
ApiHeadersProvider.cs:23
Tgstation.Server.Host.Utils.ApiHeadersProvider.ApiHeaders
ApiHeaders? ApiHeaders
The created Api.ApiHeaders, if any.
Definition
ApiHeadersProvider.cs:13
Tgstation.Server.Host.Utils.ApiHeadersProvider.CreateApiHeaders
ApiHeaders? CreateApiHeaders(bool authless)
Attempt to parse Api.ApiHeaders from the HttpContext, optionally populating the class properties.
Definition
ApiHeadersProvider.cs:52
Tgstation.Server.Host.Utils.ApiHeadersProvider.apiHeaders
ApiHeaders? apiHeaders
Backing field for ApiHeaders.
Definition
ApiHeadersProvider.cs:28
Tgstation.Server.Host.Utils.IApiHeadersProvider
Provides ApiHeaders.
Definition
IApiHeadersProvider.cs:9
Tgstation.Server.Api
Definition
ApiHeaders.cs:20
Tgstation.Server.Host.Utils
Definition
AbstractHttpClientFactory.cs:10
Generated by
1.9.8