diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 41effa0094..3daa375299 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -463,6 +463,9 @@ namespace Tgstation.Server.Host.Core // Add the X-Powered-By response header applicationBuilder.UseServerBranding(assemblyInformationProvider); + // Add the X-Accel-Buffering response header + applicationBuilder.UseDisabledNginxProxyBuffering(); + // suppress OperationCancelledExceptions, they are just aborted HTTP requests applicationBuilder.UseCancelledRequestSuppression(); diff --git a/src/Tgstation.Server.Host/Extensions/ApplicationBuilderExtensions.cs b/src/Tgstation.Server.Host/Extensions/ApplicationBuilderExtensions.cs index 53d953afe5..bc2a6dd3d7 100644 --- a/src/Tgstation.Server.Host/Extensions/ApplicationBuilderExtensions.cs +++ b/src/Tgstation.Server.Host/Extensions/ApplicationBuilderExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.Net; @@ -165,6 +165,23 @@ namespace Tgstation.Server.Host.Extensions }); } + /// + /// Add the X-Accel-Buffering response header. + /// + /// The to configure. + /// This is used to avoid interruption to SignalR streams by Nginx. + public static void UseDisabledNginxProxyBuffering(this IApplicationBuilder applicationBuilder) + { + ArgumentNullException.ThrowIfNull(applicationBuilder); + + // https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-buffering + applicationBuilder.Use((context, next) => + { + context.Response.Headers.Add("X-Accel-Buffering", "no"); + return next(); + }); + } + /// /// Adds additional global to the request pipeline. ///