From 883315bc3051c5429106f6870afa4e0d99fdea79 Mon Sep 17 00:00:00 2001 From: xRain Date: Tue, 29 Dec 2020 17:18:02 +0800 Subject: [PATCH] add forwardheaders --- SimApiExtensions.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SimApiExtensions.cs b/SimApiExtensions.cs index 7f475a3..a3552b6 100644 --- a/SimApiExtensions.cs +++ b/SimApiExtensions.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerUI; using SimApi.Middlewares; +using Microsoft.AspNetCore.HttpOverrides; namespace SimApi { @@ -28,7 +29,16 @@ namespace SimApi public static IServiceCollection AddSimApi(this IServiceCollection builder, string title, string description = null) { - return builder.AddSimApiAuth().AddSimApiDoc(title, description).AddCors().AddSimApiUpload(); + return builder.AddSimApiAuth().AddSimApiDoc(title, description).AddCors().AddSimApiUpload().Configure(options => + { + options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | + ForwardedHeaders.XForwardedProto; + // Only loopback proxies are allowed by default. + // Clear that restriction because forwarders are enabled by explicit + // configuration. + options.KnownNetworks.Clear(); + options.KnownProxies.Clear(); + }); ; } /// @@ -41,7 +51,7 @@ namespace SimApi /// public static IApplicationBuilder UseSimApi(this IApplicationBuilder builder, params SubmitMethod[] submitMethods) { - return builder.UseSimApiException().UseSimApiDoc(submitMethods).UseMiddleware().UseCors(x => x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()).UseSimApiUpload(); + return builder.UseSimApiException().UseSimApiDoc(submitMethods).UseMiddleware().UseCors(x => x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()).UseSimApiUpload().UseForwardedHeaders(); }