diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 9ca905a9df..29b528f38d 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -389,6 +389,9 @@ namespace Tgstation.Server.Host.Core // Final point where we wrap exceptions in a 500 (ErrorMessage) response applicationBuilder.UseServerErrorHandling(); + // Add the X-Powered-By response header + applicationBuilder.UseServerBranding(AssemblyInformationProvider); + // 503 requests made while the application is starting applicationBuilder.UseAsyncInitialization(async (cancellationToken) => { diff --git a/src/Tgstation.Server.Host/Extensions/ApplicationBuilderExtensions.cs b/src/Tgstation.Server.Host/Extensions/ApplicationBuilderExtensions.cs index 1165fddf85..28f3d93034 100644 --- a/src/Tgstation.Server.Host/Extensions/ApplicationBuilderExtensions.cs +++ b/src/Tgstation.Server.Host/Extensions/ApplicationBuilderExtensions.cs @@ -8,6 +8,7 @@ using System; using System.Globalization; using System.Net; using Tgstation.Server.Api.Models; +using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Extensions { @@ -113,5 +114,24 @@ namespace Tgstation.Server.Host.Extensions } }); } + + /// + /// Add the X-Powered-By response header. + /// + /// The to configure. + /// The to use. + public static void UseServerBranding(this IApplicationBuilder applicationBuilder, IAssemblyInformationProvider assemblyInformationProvider) + { + if (applicationBuilder == null) + throw new ArgumentNullException(nameof(applicationBuilder)); + if (assemblyInformationProvider == null) + throw new ArgumentNullException(nameof(assemblyInformationProvider)); + + applicationBuilder.Use(async (context, next) => + { + context.Response.Headers.Add("X-Powered-By", assemblyInformationProvider.VersionPrefix); + await next().ConfigureAwait(false); + }); + } } }