mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
server: use Any()
This commit is contained in:
@@ -370,23 +370,31 @@ namespace Jackett.Server.Services
|
|||||||
public string GetServerUrl(HttpRequest request)
|
public string GetServerUrl(HttpRequest request)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(config.BaseUrlOverride))
|
if (!string.IsNullOrEmpty(config.BaseUrlOverride))
|
||||||
|
{
|
||||||
return $"{config.BaseUrlOverride}{BasePath()}/";
|
return $"{config.BaseUrlOverride}{BasePath()}/";
|
||||||
|
}
|
||||||
|
|
||||||
var scheme = request.Scheme;
|
var scheme = request.Scheme;
|
||||||
var port = request.HttpContext.Request.Host.Port;
|
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
|
// 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();
|
var xForwardedProto = request.Headers.Where(x => x.Key == "X-Forwarded-Proto").Select(x => x.Value).FirstOrDefault();
|
||||||
if (xForwardedProto.Count > 0)
|
if (xForwardedProto.Count > 0)
|
||||||
|
{
|
||||||
scheme = xForwardedProto.First();
|
scheme = xForwardedProto.First();
|
||||||
|
}
|
||||||
// Front-End-Https: Non-standard header field used by Microsoft applications and load-balancers
|
// 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";
|
scheme = "https";
|
||||||
|
}
|
||||||
|
|
||||||
//default to 443 if the Host header doesn't contain the port (needed for reverse proxy setups)
|
//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(":"))
|
if (scheme == "https" && !request.HttpContext.Request.Host.Value.Contains(":"))
|
||||||
|
{
|
||||||
port = 443;
|
port = 443;
|
||||||
|
}
|
||||||
|
|
||||||
return $"{scheme}://{request.HttpContext.Request.Host.Host}:{port}{BasePath()}/";
|
return $"{scheme}://{request.HttpContext.Request.Host.Host}:{port}{BasePath()}/";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user