< Summary - Jellyfin

Information
Class: Jellyfin.Api.Middleware.ServerStartupMessageMiddleware
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Middleware/ServerStartupMessageMiddleware.cs
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 50
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Api/Middleware/ServerStartupMessageMiddleware.cs

#LineLine coverage
 1using System;
 2using System.Net.Mime;
 3using System.Threading.Tasks;
 4using MediaBrowser.Controller;
 5using MediaBrowser.Model.Globalization;
 6using Microsoft.AspNetCore.Http;
 7
 8namespace Jellyfin.Api.Middleware;
 9
 10/// <summary>
 11/// Shows a custom message during server startup.
 12/// </summary>
 13public class ServerStartupMessageMiddleware
 14{
 15    private readonly RequestDelegate _next;
 16
 17    /// <summary>
 18    /// Initializes a new instance of the <see cref="ServerStartupMessageMiddleware"/> class.
 19    /// </summary>
 20    /// <param name="next">The next delegate in the pipeline.</param>
 21    public ServerStartupMessageMiddleware(RequestDelegate next)
 22    {
 2223        _next = next;
 2224    }
 25
 26    /// <summary>
 27    /// Executes the middleware action.
 28    /// </summary>
 29    /// <param name="httpContext">The current HTTP context.</param>
 30    /// <param name="serverApplicationHost">The server application host.</param>
 31    /// <param name="localizationManager">The localization manager.</param>
 32    /// <returns>The async task.</returns>
 33    public async Task Invoke(
 34        HttpContext httpContext,
 35        IServerApplicationHost serverApplicationHost,
 36        ILocalizationManager localizationManager)
 37    {
 38        if (serverApplicationHost.CoreStartupHasCompleted
 39            || httpContext.Request.Path.Equals("/system/ping", StringComparison.OrdinalIgnoreCase))
 40        {
 41            await _next(httpContext).ConfigureAwait(false);
 42            return;
 43        }
 44
 45        var message = localizationManager.GetLocalizedString("StartupEmbyServerIsLoading");
 46        httpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
 47        httpContext.Response.ContentType = MediaTypeNames.Text.Html;
 48        await httpContext.Response.WriteAsync(message, httpContext.RequestAborted).ConfigureAwait(false);
 49    }
 50}