aspnet / BasicMiddleware

[Archived] Basic middleware components for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
169 stars 84 forks source link

RFC 7239 Forwarded support #284

Closed asbjornu closed 6 years ago

asbjornu commented 6 years ago

The app.UseForwardedHeaders() method adds support for the de-facto standard X-Forwarded-* headers, which is nice:

https://github.com/aspnet/BasicMiddleware/blob/8f0cc61808e09d646ba6c32e8785a6cd8f56be29/src/Microsoft.AspNetCore.HttpOverrides/ForwardedHeadersExtensions.cs#L17-L25

But it would be even nicer if it added support for the Forwarded header defined in RFC 7239 as well, since this is a more versatile and well-defined header than the de-facto ones.

With Forwarded, all information about the forwarding of a request is kept inside one header, instead of three. So this:

X-Forwarded-For: 82.115.151.177
X-Forwarded-Host: example.com
X-Forwarded-Proto: https

Is condensed to this:

Forwarded: for=82.115.151.177; host=example.com; proto=https

While a 31% reduction is nice in and of itself, the Forwarded header also defines the order of elements in each header and groups them together in a way that is both undefined and complex to replicate with the three X-Forwarded-* headers.

Tratcher commented 6 years ago

Duplicate of https://github.com/aspnet/BasicMiddleware/issues/28