2using System.Globalization;
5using Microsoft.AspNetCore.Builder;
6using Microsoft.AspNetCore.Http;
7using Microsoft.AspNetCore.Mvc;
8using Microsoft.EntityFrameworkCore;
9using Microsoft.Extensions.DependencyInjection;
10using Microsoft.Extensions.Logging;
31 internal static bool LogSwarmIdentifier {
get;
set; }
39 ArgumentNullException.ThrowIfNull(applicationBuilder);
41 applicationBuilder.Use(async (context, next) =>
48 catch (DbUpdateException e)
50 if (e.InnerException is OperationCanceledException)
52 logger.LogTrace(e,
"Rethrowing DbUpdateException as OperationCanceledException");
53 throw e.InnerException;
56 logger.LogDebug(e,
"Database conflict!");
59 AdditionalData = String.Format(CultureInfo.InvariantCulture, (e.InnerException ?? e).Message),
60 }).ExecuteResultAsync(
new ActionContext
62 HttpContext = context,
74 ArgumentNullException.ThrowIfNull(applicationBuilder);
75 applicationBuilder.Use(async (context, next) =>
82 catch (OperationCanceledException ex)
84 logger.LogDebug(ex,
"Request cancelled!");
95 ArgumentNullException.ThrowIfNull(applicationBuilder);
97 applicationBuilder.Use(async (context, next) =>
106 logger.LogError(e,
"Failed request!");
107 await
new JsonResult(
110 AdditionalData = e.ToString(),
113 StatusCode = (int)HttpStatusCode.InternalServerError,
115 .ExecuteResultAsync(
new ActionContext
117 HttpContext = context,
129 ArgumentNullException.ThrowIfNull(applicationBuilder);
131 applicationBuilder.Use(async (context, next) =>
133 var apiHeadersProvider = context.RequestServices.GetRequiredService<
IApiHeadersProvider>();
134 if (apiHeadersProvider.ApiHeaders?.Compatible(
138 await
new BadRequestObjectResult(
140 .ExecuteResultAsync(
new ActionContext
142 HttpContext = context,
158 ArgumentNullException.ThrowIfNull(applicationBuilder);
159 ArgumentNullException.ThrowIfNull(assemblyInformationProvider);
161 applicationBuilder.Use((context, next) =>
163 context.Response.Headers.Add(
"X-Powered-By", assemblyInformationProvider.
VersionPrefix);
175 ArgumentNullException.ThrowIfNull(applicationBuilder);
178 applicationBuilder.Use((context, next) =>
180 context.Response.Headers.Add(
"X-Accel-Buffering",
"no");
192 ArgumentNullException.ThrowIfNull(applicationBuilder);
193 ArgumentNullException.ThrowIfNull(swarmConfiguration);
195 if (LogSwarmIdentifier && swarmConfiguration.
Identifier !=
null)
196 applicationBuilder.Use(async (context, next) =>
string? Identifier
The server's identifier.
Represents an error message returned by the server.
Configuration for the server swarm system.
Extensions for IApplicationBuilder.
static void UseServerBranding(this IApplicationBuilder applicationBuilder, IAssemblyInformationProvider assemblyInformationProvider)
Add the X-Powered-By response header.
static void UseDisabledNginxProxyBuffering(this IApplicationBuilder applicationBuilder)
Add the X-Accel-Buffering response header.
static void UseServerErrorHandling(this IApplicationBuilder applicationBuilder)
Suppress all in flight Exceptions for the request with error 500.
static ILogger GetLogger(HttpContext httpContext)
Gets a ILogger from a given httpContext .
static void UseDbConflictHandling(this IApplicationBuilder applicationBuilder)
Return a ConflictObjectResult for DbUpdateExceptions.
static void UseCancelledRequestSuppression(this IApplicationBuilder applicationBuilder)
Suppress global::System.Threading.Tasks.TaskCanceledException warnings when a user aborts a request.
static void UseAdditionalRequestLoggingContext(this IApplicationBuilder applicationBuilder, SwarmConfiguration swarmConfiguration)
Adds additional global LogContext to the request pipeline.
static void UseApiCompatibility(this IApplicationBuilder applicationBuilder)
Check that the API version is the current major version if it's present in the headers.
Attribute for bringing in the master versions list from MSBuild that aren't embedded into assemblies ...
string RawGraphQLVersion
The Version string of the TGS GraphQL API.
static MasterVersionsAttribute Instance
Return the Assembly's instance of the MasterVersionsAttribute.
Helpers for manipulating the Serilog.Context.LogContext.
const string SwarmIdentifierContextProperty
The Serilog.Context.LogContext property name for Api.Models.Internal.SwarmServer.Identifiers.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.