From f5f890e68562e55d4bed16c454c4b4305152b296 Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Tue, 31 Jan 2023 12:18:10 +0100 Subject: Migrate to file-scoped namespaces --- .../Middleware/RobotsRedirectionMiddleware.cs | 63 +++++++++++----------- 1 file changed, 31 insertions(+), 32 deletions(-) (limited to 'Jellyfin.Api/Middleware/RobotsRedirectionMiddleware.cs') diff --git a/Jellyfin.Api/Middleware/RobotsRedirectionMiddleware.cs b/Jellyfin.Api/Middleware/RobotsRedirectionMiddleware.cs index 2e69580be..8bf626035 100644 --- a/Jellyfin.Api/Middleware/RobotsRedirectionMiddleware.cs +++ b/Jellyfin.Api/Middleware/RobotsRedirectionMiddleware.cs @@ -3,45 +3,44 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -namespace Jellyfin.Api.Middleware +namespace Jellyfin.Api.Middleware; + +/// +/// Redirect requests to robots.txt to web/robots.txt. +/// +public class RobotsRedirectionMiddleware { + private readonly RequestDelegate _next; + private readonly ILogger _logger; + /// - /// Redirect requests to robots.txt to web/robots.txt. + /// Initializes a new instance of the class. /// - public class RobotsRedirectionMiddleware + /// The next delegate in the pipeline. + /// The logger. + public RobotsRedirectionMiddleware( + RequestDelegate next, + ILogger logger) { - private readonly RequestDelegate _next; - private readonly ILogger _logger; + _next = next; + _logger = logger; + } - /// - /// Initializes a new instance of the class. - /// - /// The next delegate in the pipeline. - /// The logger. - public RobotsRedirectionMiddleware( - RequestDelegate next, - ILogger logger) + /// + /// Executes the middleware action. + /// + /// The current HTTP context. + /// The async task. + public async Task Invoke(HttpContext httpContext) + { + var localPath = httpContext.Request.Path.ToString(); + if (string.Equals(localPath, "/robots.txt", StringComparison.OrdinalIgnoreCase)) { - _next = next; - _logger = logger; + _logger.LogDebug("Redirecting robots.txt request to web/robots.txt"); + httpContext.Response.Redirect("web/robots.txt"); + return; } - /// - /// Executes the middleware action. - /// - /// The current HTTP context. - /// The async task. - public async Task Invoke(HttpContext httpContext) - { - var localPath = httpContext.Request.Path.ToString(); - if (string.Equals(localPath, "/robots.txt", StringComparison.OrdinalIgnoreCase)) - { - _logger.LogDebug("Redirecting robots.txt request to web/robots.txt"); - httpContext.Response.Redirect("web/robots.txt"); - return; - } - - await _next(httpContext).ConfigureAwait(false); - } + await _next(httpContext).ConfigureAwait(false); } } -- cgit v1.2.3