1
0
Fork 0
mirror of https://github.com/Jackett/Jackett synced 2024-12-26 09:48:37 +00:00

DotNet Core preparation (#3046)

.NET core uses HttpRequest instead of HttpRequestMessage
This commit is contained in:
flightlevel 2018-05-01 21:06:18 +10:00 committed by GitHub
parent 2d0e82159d
commit 42beb6018e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 20 deletions

View file

@ -12,7 +12,9 @@ namespace Jackett.Common.Services.Interfaces
void ReserveUrls(bool doInstall = true);
Uri ConvertToProxyLink(Uri link, string serverUrl, string indexerId, string action = "dl", string file = "t");
string BasePath();
string GetServerUrl(HttpRequestMessage Request);
List<string> notices { get; }
string GetServerUrl(object Request); //TODO: Once Mono is removed, change type to HttpRequest
List<string> notices { get; }
string GetBlackholeDirectory();
string GetApiKey();
}
}

View file

@ -335,30 +335,46 @@ namespace Jackett.Services
}
}
public string GetServerUrl(HttpRequestMessage Request)
public string GetServerUrl(Object obj)
{
var scheme = Request.RequestUri.Scheme;
var port = Request.RequestUri.Port;
string serverUrl = "";
// Check for protocol headers added by reverse proxys
// X-Forwarded-Proto: A de facto standard for identifying the originating protocol of an HTTP request
var X_Forwarded_Proto = Request.Headers.Where(x => x.Key == "X-Forwarded-Proto").Select(x => x.Value).FirstOrDefault();
if (X_Forwarded_Proto != null)
if (obj is HttpRequestMessage request)
{
scheme = X_Forwarded_Proto.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())
{
scheme = "https";
var scheme = request.RequestUri.Scheme;
var port = request.RequestUri.Port;
// Check for protocol headers added by reverse proxys
// X-Forwarded-Proto: A de facto standard for identifying the originating protocol of an HTTP request
var X_Forwarded_Proto = request.Headers.Where(x => x.Key == "X-Forwarded-Proto").Select(x => x.Value).FirstOrDefault();
if (X_Forwarded_Proto != null)
{
scheme = X_Forwarded_Proto.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())
{
scheme = "https";
}
// default to 443 if the Host header doesn't contain the port (needed for reverse proxy setups)
if (scheme == "https" && !request.RequestUri.Authority.Contains(":"))
port = 443;
serverUrl = string.Format("{0}://{1}:{2}{3}/", scheme, request.RequestUri.Host, port, BasePath());
}
// default to 443 if the Host header doesn't contain the port (needed for reverse proxy setups)
if (scheme == "https" && !Request.RequestUri.Authority.Contains(":"))
port = 443;
var serverUrl = string.Format("{0}://{1}:{2}{3}/", scheme, Request.RequestUri.Host, port, BasePath());
return serverUrl;
}
public string GetBlackholeDirectory()
{
return config.BlackholeDir;
}
public string GetApiKey()
{
return config.APIKey;
}
}
}