< Summary - Jellyfin

Information
Class: Jellyfin.Server.Extensions.WebHostBuilderExtensions
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Extensions/WebHostBuilderExtensions.cs
Line coverage
100%
Covered lines: 54
Uncovered lines: 0
Coverable lines: 54
Total lines: 90
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
ConfigureWebHostBuilder(...)100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Extensions/WebHostBuilderExtensions.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Net;
 4using Jellyfin.Server.Helpers;
 5using MediaBrowser.Common.Configuration;
 6using MediaBrowser.Controller.Extensions;
 7using Microsoft.AspNetCore.Hosting;
 8using Microsoft.Extensions.Configuration;
 9using Microsoft.Extensions.Hosting;
 10using Microsoft.Extensions.Logging;
 11
 12namespace Jellyfin.Server.Extensions;
 13
 14/// <summary>
 15/// Extensions for configuring the web host builder.
 16/// </summary>
 17public static class WebHostBuilderExtensions
 18{
 19    /// <summary>
 20    /// Configure the web host builder.
 21    /// </summary>
 22    /// <param name="builder">The builder to configure.</param>
 23    /// <param name="appHost">The application host.</param>
 24    /// <param name="startupConfig">The application configuration.</param>
 25    /// <param name="appPaths">The application paths.</param>
 26    /// <param name="logger">The logger.</param>
 27    /// <returns>The configured web host builder.</returns>
 28    public static IWebHostBuilder ConfigureWebHostBuilder(
 29        this IWebHostBuilder builder,
 30        CoreAppHost appHost,
 31        IConfiguration startupConfig,
 32        IApplicationPaths appPaths,
 33        ILogger logger)
 34    {
 2235        return builder
 2236            .UseKestrel((builderContext, options) =>
 2237            {
 2238                var addresses = appHost.NetManager.GetAllBindInterfaces(false);
 2239
 2240                bool flagged = false;
 2241                foreach (var netAdd in addresses)
 2242                {
 2243                    var address = netAdd.Address;
 2244                    logger.LogInformation("Kestrel is listening on {Address}", address.Equals(IPAddress.IPv6Any) ? "all 
 2245                    options.Listen(netAdd.Address, appHost.HttpPort);
 2246                    if (appHost.ListenWithHttps)
 2247                    {
 2248                        options.Listen(
 2249                            address,
 2250                            appHost.HttpsPort,
 2251                            listenOptions => listenOptions.UseHttps(appHost.Certificate));
 2252                    }
 2253                    else if (builderContext.HostingEnvironment.IsDevelopment())
 2254                    {
 2255                        try
 2256                        {
 2257                            options.Listen(
 2258                                address,
 2259                                appHost.HttpsPort,
 2260                                listenOptions => listenOptions.UseHttps());
 2261                        }
 2262                        catch (InvalidOperationException)
 2263                        {
 2264                            if (!flagged)
 2265                            {
 2266                                logger.LogWarning("Failed to listen to HTTPS using the ASP.NET Core HTTPS development ce
 2267                                flagged = true;
 2268                            }
 2269                        }
 2270                    }
 2271                }
 2272
 2273                // Bind to unix socket (only on unix systems)
 2274                if (startupConfig.UseUnixSocket() && Environment.OSVersion.Platform == PlatformID.Unix)
 2275                {
 2276                    var socketPath = StartupHelpers.GetUnixSocketPath(startupConfig, appPaths);
 2277
 2278                    // Workaround for https://github.com/aspnet/AspNetCore/issues/14134
 2279                    if (File.Exists(socketPath))
 2280                    {
 2281                        File.Delete(socketPath);
 2282                    }
 2283
 2284                    options.ListenUnixSocket(socketPath);
 2285                    logger.LogInformation("Kestrel listening to unix socket {SocketPath}", socketPath);
 2286                }
 2287            })
 2288            .UseStartup(_ => new Startup(appHost));
 89    }
 90}