diff --git a/src/Jackett.Server/Services/ServerService.cs b/src/Jackett.Server/Services/ServerService.cs index 3cae47086..719d3d353 100644 --- a/src/Jackett.Server/Services/ServerService.cs +++ b/src/Jackett.Server/Services/ServerService.cs @@ -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()}/"; }