From 69d581033b227c38cf810d4943aebe9aa421e33a Mon Sep 17 00:00:00 2001 From: crobibero Date: Fri, 11 Dec 2020 07:17:06 -0700 Subject: Use a more descriptive middleware name --- .../Extensions/ApiApplicationBuilderExtensions.cs | 2 +- .../Middleware/LegacyEmbyRouteRewriteMiddleware.cs | 54 ++++++++++++++++++++++ Jellyfin.Server/Middleware/PathTrimMiddleware.cs | 54 ---------------------- 3 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 Jellyfin.Server/Middleware/LegacyEmbyRouteRewriteMiddleware.cs delete mode 100644 Jellyfin.Server/Middleware/PathTrimMiddleware.cs diff --git a/Jellyfin.Server/Extensions/ApiApplicationBuilderExtensions.cs b/Jellyfin.Server/Extensions/ApiApplicationBuilderExtensions.cs index 492adfbffc..88e2b4152b 100644 --- a/Jellyfin.Server/Extensions/ApiApplicationBuilderExtensions.cs +++ b/Jellyfin.Server/Extensions/ApiApplicationBuilderExtensions.cs @@ -128,7 +128,7 @@ namespace Jellyfin.Server.Extensions /// The updated application builder. public static IApplicationBuilder UsePathTrim(this IApplicationBuilder appBuilder) { - return appBuilder.UseMiddleware(); + return appBuilder.UseMiddleware(); } } } diff --git a/Jellyfin.Server/Middleware/LegacyEmbyRouteRewriteMiddleware.cs b/Jellyfin.Server/Middleware/LegacyEmbyRouteRewriteMiddleware.cs new file mode 100644 index 0000000000..fdd8974d2b --- /dev/null +++ b/Jellyfin.Server/Middleware/LegacyEmbyRouteRewriteMiddleware.cs @@ -0,0 +1,54 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.Server.Middleware +{ + /// + /// Removes /emby and /mediabrowser from requested route. + /// + public class LegacyEmbyRouteRewriteMiddleware + { + private const string EmbyPath = "/emby"; + private const string MediabrowserPath = "/mediabrowser"; + + private readonly RequestDelegate _next; + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + /// The next delegate in the pipeline. + /// The logger. + public LegacyEmbyRouteRewriteMiddleware( + RequestDelegate next, + ILogger logger) + { + _next = next; + _logger = 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 (localPath.StartsWith(EmbyPath, StringComparison.OrdinalIgnoreCase)) + { + httpContext.Request.Path = localPath[EmbyPath.Length..]; + _logger.LogDebug("Removing {EmbyPath} from route.", EmbyPath); + } + else if (localPath.StartsWith(MediabrowserPath, StringComparison.OrdinalIgnoreCase)) + { + httpContext.Request.Path = localPath[MediabrowserPath.Length..]; + _logger.LogDebug("Removing {MediabrowserPath} from route.", MediabrowserPath); + } + + await _next(httpContext).ConfigureAwait(false); + } + } +} \ No newline at end of file diff --git a/Jellyfin.Server/Middleware/PathTrimMiddleware.cs b/Jellyfin.Server/Middleware/PathTrimMiddleware.cs deleted file mode 100644 index 6360cba500..0000000000 --- a/Jellyfin.Server/Middleware/PathTrimMiddleware.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; - -namespace Jellyfin.Server.Middleware -{ - /// - /// Removes /emby and /mediabrowser from requested route. - /// - public class PathTrimMiddleware - { - private const string EmbyPath = "/emby"; - private const string MediabrowserPath = "/mediabrowser"; - - private readonly RequestDelegate _next; - private readonly ILogger _logger; - - /// - /// Initializes a new instance of the class. - /// - /// The next delegate in the pipeline. - /// The logger. - public PathTrimMiddleware( - RequestDelegate next, - ILogger logger) - { - _next = next; - _logger = 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 (localPath.StartsWith(EmbyPath, StringComparison.OrdinalIgnoreCase)) - { - httpContext.Request.Path = localPath[EmbyPath.Length..]; - _logger.LogDebug("Removing {EmbyPath} from route.", EmbyPath); - } - else if (localPath.StartsWith(MediabrowserPath, StringComparison.OrdinalIgnoreCase)) - { - httpContext.Request.Path = localPath[MediabrowserPath.Length..]; - _logger.LogDebug("Removing {MediabrowserPath} from route.", MediabrowserPath); - } - - await _next(httpContext).ConfigureAwait(false); - } - } -} \ No newline at end of file -- cgit v1.2.3