diff options
| author | Anthony Lavado <anthony@lavado.ca> | 2020-09-03 09:45:17 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-03 09:45:17 -0400 |
| commit | a2d6ea2eed58b5cd1ecb519e3eda820f336d5485 (patch) | |
| tree | 6b0de55286f857587df1562a30c350432f33c1c7 /Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs | |
| parent | 8c28824c8878e409ca426e4860dc3f05521f39b8 (diff) | |
| parent | 993c46f98d995bd1c06b6040833be554717bd0ca (diff) | |
Merge pull request #4043 from cvium/remove_shit_and_shit_adjacent_shit
Split HttpListenerHost into middlewares
Diffstat (limited to 'Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs')
| -rw-r--r-- | Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs b/Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs new file mode 100644 index 000000000..ea81c03a2 --- /dev/null +++ b/Jellyfin.Server/Middleware/ServerStartupMessageMiddleware.cs @@ -0,0 +1,49 @@ +using System.Net.Mime; +using System.Threading.Tasks; +using MediaBrowser.Controller; +using MediaBrowser.Model.Globalization; +using Microsoft.AspNetCore.Http; + +namespace Jellyfin.Server.Middleware +{ + /// <summary> + /// Shows a custom message during server startup. + /// </summary> + public class ServerStartupMessageMiddleware + { + private readonly RequestDelegate _next; + + /// <summary> + /// Initializes a new instance of the <see cref="ServerStartupMessageMiddleware"/> class. + /// </summary> + /// <param name="next">The next delegate in the pipeline.</param> + public ServerStartupMessageMiddleware(RequestDelegate next) + { + _next = next; + } + + /// <summary> + /// Executes the middleware action. + /// </summary> + /// <param name="httpContext">The current HTTP context.</param> + /// <param name="serverApplicationHost">The server application host.</param> + /// <param name="localizationManager">The localization manager.</param> + /// <returns>The async task.</returns> + public async Task Invoke( + HttpContext httpContext, + IServerApplicationHost serverApplicationHost, + ILocalizationManager localizationManager) + { + if (serverApplicationHost.CoreStartupHasCompleted) + { + await _next(httpContext).ConfigureAwait(false); + return; + } + + var message = localizationManager.GetLocalizedString("StartupEmbyServerIsLoading"); + httpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable; + httpContext.Response.ContentType = MediaTypeNames.Text.Html; + await httpContext.Response.WriteAsync(message, httpContext.RequestAborted).ConfigureAwait(false); + } + } +} |
