mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Make parameter type HttpRequest
Code tidy
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
<PackageReference Include="CommandLineParser" Version="2.4.3" />
|
<PackageReference Include="CommandLineParser" Version="2.4.3" />
|
||||||
<PackageReference Include="CsQuery.NETStandard" Version="1.3.6.1" />
|
<PackageReference Include="CsQuery.NETStandard" Version="1.3.6.1" />
|
||||||
<PackageReference Include="DotNet4.SocksProxy" Version="1.4.0.1" />
|
<PackageReference Include="DotNet4.SocksProxy" Version="1.4.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
|
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
||||||
<PackageReference Include="MimeMapping" Version="1.0.1.12" />
|
<PackageReference Include="MimeMapping" Version="1.0.1.12" />
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace Jackett.Common.Services.Interfaces
|
namespace Jackett.Common.Services.Interfaces
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,7 @@ namespace Jackett.Common.Services.Interfaces
|
|||||||
void ReserveUrls(bool doInstall = true);
|
void ReserveUrls(bool doInstall = true);
|
||||||
Uri ConvertToProxyLink(Uri link, string serverUrl, string indexerId, string action = "dl", string file = "t");
|
Uri ConvertToProxyLink(Uri link, string serverUrl, string indexerId, string action = "dl", string file = "t");
|
||||||
string BasePath();
|
string BasePath();
|
||||||
string GetServerUrl(object Request); //TODO: Once Mono is removed, change type to HttpRequest
|
string GetServerUrl(HttpRequest Request);
|
||||||
List<string> notices { get; }
|
List<string> notices { get; }
|
||||||
string GetBlackholeDirectory();
|
string GetBlackholeDirectory();
|
||||||
string GetApiKey();
|
string GetApiKey();
|
||||||
|
@@ -314,36 +314,33 @@ namespace Jackett.Server.Services
|
|||||||
// Only needed for Owin
|
// Only needed for Owin
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetServerUrl(Object obj)
|
public string GetServerUrl(HttpRequest request)
|
||||||
{
|
{
|
||||||
string serverUrl = "";
|
string serverUrl = "";
|
||||||
|
|
||||||
if (obj is HttpRequest request)
|
var scheme = request.Scheme;
|
||||||
|
var port = request.HttpContext.Request.Host.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.Count > 0)
|
||||||
{
|
{
|
||||||
var scheme = request.Scheme;
|
scheme = X_Forwarded_Proto.First();
|
||||||
var port = request.HttpContext.Request.Host.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.Count > 0)
|
|
||||||
{
|
|
||||||
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.HttpContext.Request.Host.Value.Contains(":"))
|
|
||||||
{
|
|
||||||
port = 443;
|
|
||||||
}
|
|
||||||
|
|
||||||
serverUrl = string.Format("{0}://{1}:{2}{3}/", scheme, request.HttpContext.Request.Host.Host, port, BasePath());
|
|
||||||
}
|
}
|
||||||
|
// 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.HttpContext.Request.Host.Value.Contains(":"))
|
||||||
|
{
|
||||||
|
port = 443;
|
||||||
|
}
|
||||||
|
|
||||||
|
serverUrl = string.Format("{0}://{1}:{2}{3}/", scheme, request.HttpContext.Request.Host.Host, port, BasePath());
|
||||||
|
|
||||||
return serverUrl;
|
return serverUrl;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user