Add X-Accel-Buffering: no response header

This commit is contained in:
Jordan Dominion
2023-11-17 22:25:22 -05:00
parent 3abf0b69f2
commit f9f712a05b
2 changed files with 21 additions and 1 deletions
@@ -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();
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Net;
@@ -165,6 +165,23 @@ namespace Tgstation.Server.Host.Extensions
});
}
/// <summary>
/// Add the X-Accel-Buffering response header.
/// </summary>
/// <param name="applicationBuilder">The <see cref="IApplicationBuilder"/> to configure.</param>
/// <remarks>This is used to avoid interruption to SignalR streams by Nginx.</remarks>
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();
});
}
/// <summary>
/// Adds additional global <see cref="LogContext"/> to the request pipeline.
/// </summary>