From e97ccd87fb74c34222eccf03493a56144065eaa4 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 31 Aug 2020 07:21:07 -0600 Subject: [PATCH] Remove DynamicCorsMiddleware --- .../Middleware/DynamicCorsMiddleware.cs | 66 ------------------- Jellyfin.Server/Startup.cs | 2 +- 2 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 Jellyfin.Server/Middleware/DynamicCorsMiddleware.cs diff --git a/Jellyfin.Server/Middleware/DynamicCorsMiddleware.cs b/Jellyfin.Server/Middleware/DynamicCorsMiddleware.cs deleted file mode 100644 index c4c491cdd8..0000000000 --- a/Jellyfin.Server/Middleware/DynamicCorsMiddleware.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Cors.Infrastructure; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; -using Microsoft.Net.Http.Headers; - -namespace Jellyfin.Server.Middleware -{ - /// - /// Dynamic cors middleware. - /// - public class DynamicCorsMiddleware - { - private readonly RequestDelegate _next; - private readonly ILogger _logger; - private readonly CorsMiddleware _corsMiddleware; - - /// - /// Initializes a new instance of the class. - /// - /// Next request delegate. - /// Instance of the interface. - /// Instance of the interface. - /// The cors policy name. - public DynamicCorsMiddleware( - RequestDelegate next, - ICorsService corsService, - ILoggerFactory loggerFactory, - string policyName) - { - _corsMiddleware = new CorsMiddleware(next, corsService, loggerFactory, policyName); - _next = next; - _logger = loggerFactory.CreateLogger(); - } - - /// - /// Invoke request. - /// - /// Request context. - /// Instance of the interface. - /// Task. - /// - public async Task Invoke(HttpContext context, ICorsPolicyProvider corsPolicyProvider) - { - // Only execute if is preflight request. - if (string.Equals(context.Request.Method, CorsConstants.PreflightHttpMethod, StringComparison.OrdinalIgnoreCase)) - { - // Invoke original cors middleware. - await _corsMiddleware.Invoke(context, corsPolicyProvider).ConfigureAwait(false); - if (context.Response.Headers.TryGetValue(HeaderNames.AccessControlAllowOrigin, out var headerValue) - && string.Equals(headerValue, "*", StringComparison.Ordinal)) - { - context.Response.Headers[HeaderNames.AccessControlAllowOrigin] = context.Request.Host.Value; - - // Always allow credentials. - context.Response.Headers[HeaderNames.AccessControlAllowCredentials] = "true"; - _logger.LogDebug("Overwriting CORS response header: {HeaderName}: {HeaderValue}", HeaderNames.AccessControlAllowOrigin, context.Request.Host.Value); - } - } - - // Call the next delegate/middleware in the pipeline - await this._next(context).ConfigureAwait(false); - } - } -} diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs index 76f5e69ced..966587a6a0 100644 --- a/Jellyfin.Server/Startup.cs +++ b/Jellyfin.Server/Startup.cs @@ -80,7 +80,7 @@ namespace Jellyfin.Server app.UseAuthentication(); app.UseJellyfinApiSwagger(_serverConfigurationManager); app.UseRouting(); - app.UseMiddleware(ServerCorsPolicy.DefaultPolicyName); + app.UseCors(ServerCorsPolicy.DefaultPolicyName); app.UseAuthorization(); if (_serverConfigurationManager.Configuration.EnableMetrics) {