using System.Net.Mime;
using System.Threading.Tasks;
using MediaBrowser.Model.Globalization;
using Microsoft.AspNetCore.Http;
namespace Jellyfin.Server.Middleware
{
///
/// Shows a custom message during server startup.
///
public class ServerStartupMessageMiddleware
{
private readonly RequestDelegate _next;
///
/// Initializes a new instance of the class.
///
/// The next delegate in the pipeline.
public ServerStartupMessageMiddleware(RequestDelegate next)
{
_next = next;
}
///
/// Executes the middleware action.
///
/// The current HTTP context.
/// The localization manager.
/// The async task.
public async Task Invoke(HttpContext httpContext, ILocalizationManager localizationManager)
{
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);
}
}
}