< Summary - Jellyfin

Information
Class: Jellyfin.Api.Middleware.LegacyEmbyRouteRewriteMiddleware
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Middleware/LegacyEmbyRouteRewriteMiddleware.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 53
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/LegacyEmbyRouteRewriteMiddleware.cs

#LineLine coverage
 1using System;
 2using System.Threading.Tasks;
 3using Microsoft.AspNetCore.Http;
 4using Microsoft.Extensions.Logging;
 5
 6namespace Jellyfin.Api.Middleware;
 7
 8/// <summary>
 9/// Removes /emby and /mediabrowser from requested route.
 10/// </summary>
 11public class LegacyEmbyRouteRewriteMiddleware
 12{
 13    private const string EmbyPath = "/emby";
 14    private const string MediabrowserPath = "/mediabrowser";
 15
 16    private readonly RequestDelegate _next;
 17    private readonly ILogger<LegacyEmbyRouteRewriteMiddleware> _logger;
 18
 19    /// <summary>
 20    /// Initializes a new instance of the <see cref="LegacyEmbyRouteRewriteMiddleware"/> class.
 21    /// </summary>
 22    /// <param name="next">The next delegate in the pipeline.</param>
 23    /// <param name="logger">The logger.</param>
 24    public LegacyEmbyRouteRewriteMiddleware(
 25        RequestDelegate next,
 26        ILogger<LegacyEmbyRouteRewriteMiddleware> logger)
 27    {
 2228        _next = next;
 2229        _logger = logger;
 2230    }
 31
 32    /// <summary>
 33    /// Executes the middleware action.
 34    /// </summary>
 35    /// <param name="httpContext">The current HTTP context.</param>
 36    /// <returns>The async task.</returns>
 37    public async Task Invoke(HttpContext httpContext)
 38    {
 39        var localPath = httpContext.Request.Path.ToString();
 40        if (localPath.StartsWith(EmbyPath, StringComparison.OrdinalIgnoreCase))
 41        {
 42            httpContext.Request.Path = localPath[EmbyPath.Length..];
 43            _logger.LogDebug("Removing {EmbyPath} from route.", EmbyPath);
 44        }
 45        else if (localPath.StartsWith(MediabrowserPath, StringComparison.OrdinalIgnoreCase))
 46        {
 47            httpContext.Request.Path = localPath[MediabrowserPath.Length..];
 48            _logger.LogDebug("Removing {MediabrowserPath} from route.", MediabrowserPath);
 49        }
 50
 51        await _next(httpContext).ConfigureAwait(false);
 52    }
 53}