Skip to content

Commit 99ca01f

Browse files
committed
Improved proxy support by only using it in logging contexts
1 parent 123e431 commit 99ca01f

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

Program.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,14 @@
152152

153153

154154
var app = builder.Build();
155-
app.UseForwardedHeaders(new ForwardedHeadersOptions
156-
{
157-
ForwardedHeaders = ForwardedHeaders.XForwardedProto | ForwardedHeaders.XForwardedFor
158-
});
159-
160155
app.UseSerilogRequestLogging(options =>
161156
{
162157
options.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
163158
{
159+
var proto = httpContext.Request.Headers["X-Forwarded-Proto"].FirstOrDefault() ?? httpContext.Request.Scheme;
164160
diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value);
165161
diagnosticContext.Set("HttpRequestType", httpContext.Request.Method);
166-
diagnosticContext.Set("HttpRequestUrl", $"{httpContext.Request.Scheme}://{httpContext.Request.Host}{httpContext.Request.Path}{httpContext.Request.QueryString}");
162+
diagnosticContext.Set("HttpRequestUrl", $"{proto}://{httpContext.Request.Host}{httpContext.Request.Path}{httpContext.Request.QueryString}");
167163
diagnosticContext.Set("HttpRequestId", httpContext.TraceIdentifier);
168164
};
169165
});

0 commit comments

Comments
 (0)