mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-29 16:11:05 +01:00
Merge pull request #1134 from tgstation/1113-EasiestShitIveEverSeen
Adds X-Powered-By response header
This commit is contained in:
@@ -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) =>
|
||||
{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add the X-Powered-By response header.
|
||||
/// </summary>
|
||||
/// <param name="applicationBuilder">The <see cref="IApplicationBuilder"/> to configure.</param>
|
||||
/// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> to use.</param>
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user