< Summary - Jellyfin

Information
Class: Jellyfin.Api.Middleware.RobotsRedirectionMiddleware
Assembly: Jellyfin.Api
File(s): /srv/git/jellyfin/Jellyfin.Api/Middleware/RobotsRedirectionMiddleware.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 45
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/RobotsRedirectionMiddleware.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/// Redirect requests to robots.txt to web/robots.txt.
 10/// </summary>
 11public class RobotsRedirectionMiddleware
 12{
 13    private readonly RequestDelegate _next;
 14    private readonly ILogger<RobotsRedirectionMiddleware> _logger;
 15
 16    /// <summary>
 17    /// Initializes a new instance of the <see cref="RobotsRedirectionMiddleware"/> class.
 18    /// </summary>
 19    /// <param name="next">The next delegate in the pipeline.</param>
 20    /// <param name="logger">The logger.</param>
 21    public RobotsRedirectionMiddleware(
 22        RequestDelegate next,
 23        ILogger<RobotsRedirectionMiddleware> logger)
 24    {
 2225        _next = next;
 2226        _logger = logger;
 2227    }
 28
 29    /// <summary>
 30    /// Executes the middleware action.
 31    /// </summary>
 32    /// <param name="httpContext">The current HTTP context.</param>
 33    /// <returns>The async task.</returns>
 34    public async Task Invoke(HttpContext httpContext)
 35    {
 36        if (httpContext.Request.Path.Equals("/robots.txt", StringComparison.OrdinalIgnoreCase))
 37        {
 38            _logger.LogDebug("Redirecting robots.txt request to web/robots.txt");
 39            httpContext.Response.Redirect("web/robots.txt");
 40            return;
 41        }
 42
 43        await _next(httpContext).ConfigureAwait(false);
 44    }
 45}