< Summary - Jellyfin

Information
Class: Jellyfin.Server.Filters.FileResponseFilter
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Filters/FileResponseFilter.cs
Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 58
Line coverage: 95%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 11/28/2025 - 12:11:11 AM Line coverage: 100% (18/18) Branch coverage: 100% (8/8) Total lines: 532/27/2026 - 12:13:29 AM Line coverage: 95% (19/20) Branch coverage: 83.3% (10/12) Total lines: 58 11/28/2025 - 12:11:11 AM Line coverage: 100% (18/18) Branch coverage: 100% (8/8) Total lines: 532/27/2026 - 12:13:29 AM Line coverage: 95% (19/20) Branch coverage: 83.3% (10/12) Total lines: 58

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
Apply(...)83.33%121291.66%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Filters/FileResponseFilter.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using Jellyfin.Api.Attributes;
 4using Microsoft.OpenApi;
 5using Swashbuckle.AspNetCore.SwaggerGen;
 6
 7namespace Jellyfin.Server.Filters
 8{
 9    /// <inheritdoc />
 10    public class FileResponseFilter : IOperationFilter
 11    {
 12        private const string SuccessCode = "200";
 113        private static readonly OpenApiMediaType _openApiMediaType = new OpenApiMediaType
 114        {
 115            Schema = new OpenApiSchema
 116            {
 117                Type = JsonSchemaType.String,
 118                Format = "binary"
 119            }
 120        };
 21
 22        /// <inheritdoc />
 23        public void Apply(OpenApiOperation operation, OperationFilterContext context)
 24        {
 38725            if (operation.Responses is null)
 26            {
 027                return;
 28            }
 29
 913630            foreach (var attribute in context.ApiDescription.ActionDescriptor.EndpointMetadata)
 31            {
 421532                if (attribute is ProducesFileAttribute producesFileAttribute)
 33                {
 34                    // Get operation response values.
 6835                    var response = operation.Responses
 6836                        .FirstOrDefault(o => o.Key.Equals(SuccessCode, StringComparison.Ordinal));
 37
 38                    // Operation doesn't have a response.
 6839                    if (response.Value?.Content is null)
 40                    {
 41                        continue;
 42                    }
 43
 44                    // Clear existing responses.
 6845                    response.Value.Content.Clear();
 46
 47                    // Add all content-types as file.
 27848                    foreach (var contentType in producesFileAttribute.ContentTypes)
 49                    {
 7150                        response.Value.Content.Add(contentType, _openApiMediaType);
 51                    }
 52
 6853                    break;
 54                }
 55            }
 38756        }
 57    }
 58}