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
2 changed files with 38 additions and 20 deletions

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;
}
}
}