mirror of
https://github.com/Jackett/Jackett
synced 2025-03-04 18:59:01 +00:00
server: use Any()
This commit is contained in:
parent
e5c9266328
commit
049124c9a8
1 changed files with 10 additions and 2 deletions
|
@ -370,23 +370,31 @@ namespace Jackett.Server.Services
|
|||
public string GetServerUrl(HttpRequest request)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(config.BaseUrlOverride))
|
||||
{
|
||||
return $"{config.BaseUrlOverride}{BasePath()}/";
|
||||
}
|
||||
|
||||
var scheme = request.Scheme;
|
||||
var port = request.HttpContext.Request.Host.Port;
|
||||
|
||||
// Check for protocol headers added by reverse proxys
|
||||
// Check for protocol headers added by reverse proxies
|
||||
// X-Forwarded-Proto: A de facto standard for identifying the originating protocol of an HTTP request
|
||||
var xForwardedProto = request.Headers.Where(x => x.Key == "X-Forwarded-Proto").Select(x => x.Value).FirstOrDefault();
|
||||
if (xForwardedProto.Count > 0)
|
||||
{
|
||||
scheme = xForwardedProto.First();
|
||||
}
|
||||
// Front-End-Https: Non-standard header field used by Microsoft applications and load-balancers
|
||||
else if (request.Headers.Where(x => x.Key == "Front-End-Https" && x.Value.FirstOrDefault() == "on").Any())
|
||||
else if (request.Headers.Any(x => x.Key == "Front-End-Https" && x.Value.FirstOrDefault() == "on"))
|
||||
{
|
||||
scheme = "https";
|
||||
}
|
||||
|
||||
//default to 443 if the Host header doesn't contain the port (needed for reverse proxy setups)
|
||||
if (scheme == "https" && !request.HttpContext.Request.Host.Value.Contains(":"))
|
||||
{
|
||||
port = 443;
|
||||
}
|
||||
|
||||
return $"{scheme}://{request.HttpContext.Request.Host.Host}:{port}{BasePath()}/";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue