Skip to content

Commit 7058936

Browse files
committed
fix: handle X-Forwarded- headers
1 parent 17506ea commit 7058936

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

WebApi/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.AspNetCore.DataProtection;
1010
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
1111
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
12+
using Microsoft.AspNetCore.HttpOverrides;
1213
using Microsoft.AspNetCore.Mvc;
1314
using Microsoft.Data.Sqlite;
1415
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
@@ -72,6 +73,8 @@
7273

7374
var app = builder.Build();
7475

76+
app.UseForwardedHeaders();
77+
7578
// Configure the HTTP request pipeline.
7679
app.UseSwagger(c =>
7780
{
@@ -113,6 +116,11 @@ static void ConfigureOptions(IServiceCollection services, IConfiguration configu
113116
{
114117
services.Configure<RedditSettings>(configuration.GetSection("RedditSettings"));
115118
services.Configure<HostingOptions>(configuration.GetSection("Hosting"));
119+
120+
services.Configure<ForwardedHeadersOptions>(options =>
121+
{
122+
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
123+
});
116124
}
117125

118126
static void ConfigureServices(IServiceCollection services, IConfiguration configuration)

0 commit comments

Comments
 (0)