diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2021-04-16 19:20:20 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2021-04-16 19:20:20 +0200 |
| commit | 80ebf2b88b811a4b483e3abb79d7741646772cf0 (patch) | |
| tree | 453a1ecbaaeb24fd88e9892a854b2b0744cdd4f7 /src | |
| parent | 38390e2f882e4142e195f082045480260dc140d6 (diff) | |
| download | dotnet-helpers-80ebf2b88b811a4b483e3abb79d7741646772cf0.tar.xz dotnet-helpers-80ebf2b88b811a4b483e3abb79d7741646772cf0.zip | |
Rename HttpRequestHelpers.GetAppHost -> HttpRequestHelpers.GetRequestHost
Rename and add optional parameter to skip X-Forwarded-Host and X-Forwarded-Proto
Diffstat (limited to 'src')
| -rw-r--r-- | src/IOL.Helpers/HttpRequestHelpers.cs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/IOL.Helpers/HttpRequestHelpers.cs b/src/IOL.Helpers/HttpRequestHelpers.cs index 5a0e145..a5f015e 100644 --- a/src/IOL.Helpers/HttpRequestHelpers.cs +++ b/src/IOL.Helpers/HttpRequestHelpers.cs @@ -5,11 +5,19 @@ namespace IOL.Helpers { public static class HttpRequestHelpers { - public static string GetAppHost(this HttpRequest request) { - var forwardedHostHeader = request.Headers["X-Forwarded-Host"].ToString(); - var forwardedProtoHeader = request.Headers["X-Forwarded-Proto"].ToString(); - if (forwardedHostHeader.HasValue()) { - return (forwardedProtoHeader ?? "https") + "://" + forwardedHostHeader; + /// <summary> + /// Get's the scheme and host (scheme://host) value of the current HttpRequest + /// </summary> + /// <param name="request">HttpRequest to retrieve value from</param> + /// <param name="ignoreForwared">Ignore header values like X-Forwarded-Host|Proto</param> + /// <returns></returns> + public static string GetRequestHost(this HttpRequest request, bool ignoreForwared = false) { + if (!ignoreForwared) { + var forwardedHostHeader = request.Headers["X-Forwarded-Host"].ToString(); + var forwardedProtoHeader = request.Headers["X-Forwarded-Proto"].ToString(); + if (forwardedHostHeader.HasValue()) { + return (forwardedProtoHeader ?? "https") + "://" + forwardedHostHeader; + } } return request.Scheme + "://" + request.Host; |
