Skip to content

Support setting ASP.NET Core HttpOverrides from configuration

License

Notifications You must be signed in to change notification settings

NetLah/http-overrides

Repository files navigation

NetLah.Extensions.HttpOverrides - .NET Library

NetLah.Extensions.HttpOverrides is a library support setting ASP.NET Core HttpOverrides from configuration.

Nuget package

NuGet

Build Status

Build Status

Getting started

1. Add/Update PackageReference to .csproj

<ItemGroup>
  <PackageReference Include="NetLah.Extensions.HttpOverrides" Version="1.0.0" />
</ItemGroup>

2. Settings From Configuration

builder.Services.AddHttpOverrides(builder.Configuration);

3. Applies Http Overrides

app.UseHttpOverrides(logger);

Overrided by ASPNETCORE_FORWARDEDHEADERS_ENABLED

This HttpOverrides will check configuration ASPNETCORE_FORWARDEDHEADERS_ENABLED or ForwardedHeaders_Enabled not turned on to not override default behavior of ASP.NETCore.

Reference ForwardedHeadersOptionsSetup.cs

Sample and default configuration

{
  "HealthCheck": {
    "IsEnabled": true,
    "IsAzureAppServiceContainer": false,    // will include /healthz and /robots933456.txt
    "LogLevel": "Debug",
    "Path": "/healthz",
    "Paths": [ "/healthz", "/robots933456.txt" ],
    "Port": null,
    "Prefix": null,
    "Suffix": null,
    "RemoveResponseWriter": false
  },
  "HttpOverrides": {
    "ClearForwardLimit": false,
    "ClearKnownProxies": false,
    "ClearKnownNetworks": false,
    "ForwardLimit": 1,
    "KnownProxies": "::1",
    "KnownNetworks": "127.0.0.1/8",
    "ForwardedForHeaderName": "X-Forwarded-For",
    "ForwardedHostHeaderName": "X-Forwarded-Host",
    "ForwardedProtoHeaderName": "X-Forwarded-Proto",
    "OriginalForHeaderName": "X-Original-For",
    "OriginalHostHeaderName": "X-Original-Host",
    "OriginalProtoHeaderName": "X-Original-Proto",
    "ForwardedHeaders": "", // XForwardedFor,XForwardedHost,XForwardedProto
    "AllowedHosts": "" // "*"
  }  
}