-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename MessageBus to ServiceBus; apply file-scoped namespace * S1940 Use the opposite operator ('<') instead * comment DO NOT enable `app.UseHsts()` by mistake * Cleanup * Get multi version of certificates * Add multi connections query * Add Diagnostics/GetInfo with application assembly info and timezone info * Consolidate Directory.Build.targets * Update ApiExplorer * Use nuget NetLah.Extensions.HttpOverrides
- Loading branch information
Showing
23 changed files
with
589 additions
and
727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,55 @@ | ||
namespace EchoServiceApi | ||
namespace EchoServiceApi; | ||
|
||
public class HttpContextInfo | ||
{ | ||
public class HttpContextInfo | ||
private readonly HttpContext _httpContext; | ||
private readonly Lazy<HostAndPort> _getHostAndPort; | ||
|
||
public HttpContextInfo(IHttpContextAccessor httpContextAccessor) | ||
{ | ||
private readonly HttpContext _httpContext; | ||
private readonly Lazy<HostAndPort> _getHostAndPort; | ||
_httpContext = httpContextAccessor?.HttpContext ?? throw new ArgumentNullException(nameof(httpContextAccessor), "HttpContext is required"); | ||
_getHostAndPort = new Lazy<HostAndPort>(GetHostAndPort); | ||
} | ||
|
||
public HttpContextInfo(IHttpContextAccessor httpContextAccessor) | ||
private HostAndPort GetHostAndPort() | ||
{ | ||
var request = _httpContext.Request; | ||
var hostMayWithPort = request.Host; | ||
var host = hostMayWithPort.Host; | ||
if (hostMayWithPort.Port is { } port) | ||
{ | ||
_httpContext = httpContextAccessor?.HttpContext ?? throw new ArgumentNullException(nameof(httpContextAccessor), "HttpContext is required"); | ||
_getHostAndPort = new Lazy<HostAndPort>(GetHostAndPort); | ||
return new HostAndPort(host, port); | ||
} | ||
|
||
private HostAndPort GetHostAndPort() | ||
if (request.Headers["X-FORWARDED-PORT"] is { } headerValues && | ||
headerValues.FirstOrDefault() is { } headerValue && | ||
int.TryParse(headerValue, out var portValue2)) | ||
{ | ||
var request = _httpContext.Request; | ||
var hostMayWithPort = request.Host; | ||
var host = hostMayWithPort.Host; | ||
if (hostMayWithPort.Port is { } port) | ||
{ | ||
return new HostAndPort(host, port); | ||
} | ||
|
||
if (request.Headers["X-FORWARDED-PORT"] is { } headerValues && | ||
headerValues.FirstOrDefault() is { } headerValue && | ||
int.TryParse(headerValue, out var portValue2)) | ||
{ | ||
return new HostAndPort(host, portValue2); | ||
} | ||
else | ||
{ | ||
var connection = _httpContext.Connection; | ||
var localPort = connection.LocalPort; | ||
var unexpectedPort = request.Scheme == "https" ? 80 : 443; | ||
var defaultPortScheme = request.Scheme == "https" ? 443 : 80; | ||
var portValue3 = localPort == unexpectedPort ? defaultPortScheme : localPort; | ||
return new HostAndPort(host, portValue3); | ||
} | ||
return new HostAndPort(host, portValue2); | ||
} | ||
else | ||
{ | ||
var connection = _httpContext.Connection; | ||
var localPort = connection.LocalPort; | ||
var unexpectedPort = request.Scheme == "https" ? 80 : 443; | ||
var defaultPortScheme = request.Scheme == "https" ? 443 : 80; | ||
var portValue3 = localPort == unexpectedPort ? defaultPortScheme : localPort; | ||
return new HostAndPort(host, portValue3); | ||
} | ||
} | ||
|
||
public string Host => _getHostAndPort.Value.Host; | ||
public int Port => _getHostAndPort.Value.Port; | ||
public string Host => _getHostAndPort.Value.Host; | ||
public int Port => _getHostAndPort.Value.Port; | ||
|
||
private class HostAndPort | ||
private sealed class HostAndPort | ||
{ | ||
public HostAndPort(string host, int port) | ||
{ | ||
public HostAndPort(string host, int port) | ||
{ | ||
Host = host; | ||
Port = port; | ||
} | ||
|
||
public string Host { get; } | ||
public int Port { get; } | ||
Host = host; | ||
Port = port; | ||
} | ||
|
||
public string Host { get; } | ||
public int Port { get; } | ||
} | ||
} |
Oops, something went wrong.