using System; using Microsoft.AspNetCore.Cors.Infrastructure; namespace Jellyfin.Server.Models { /// /// Server Cors Policy. /// public class ServerCorsPolicy { /// /// Default policy name. /// public const string DefaultPolicyName = nameof(ServerCorsPolicy); /// /// Initializes a new instance of the class. /// /// The configured cors hosts. public ServerCorsPolicy(string[] corsHosts) { var builder = new CorsPolicyBuilder() .AllowAnyMethod() .AllowAnyHeader(); // No hosts configured or only default configured. if (corsHosts.Length == 0 || (corsHosts.Length == 1 && string.Equals(corsHosts[0], "*", StringComparison.Ordinal))) { builder.AllowAnyOrigin(); } else { builder.WithOrigins(corsHosts) .AllowCredentials(); } Policy = builder.Build(); } /// /// Gets the cors policy. /// public CorsPolicy Policy { get; } } }