Commit b2c7c691 authored by Honfika's avatar Honfika

Prepare for .NET standard version

parent a6a60cd0
...@@ -109,6 +109,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -109,6 +109,7 @@ namespace Titanium.Web.Proxy.EventArguments
WebSession.ProcessId = new Lazy<int>(() => WebSession.ProcessId = new Lazy<int>(() =>
{ {
#if NET45
var remoteEndPoint = (IPEndPoint)ProxyClient.TcpClient.Client.RemoteEndPoint; var remoteEndPoint = (IPEndPoint)ProxyClient.TcpClient.Client.RemoteEndPoint;
//If client is localhost get the process id //If client is localhost get the process id
...@@ -119,6 +120,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -119,6 +120,9 @@ namespace Titanium.Web.Proxy.EventArguments
//can't access process Id of remote request from remote machine //can't access process Id of remote request from remote machine
return -1; return -1;
#else
throw new PlatformNotSupportedException();
#endif
}); });
} }
......
...@@ -6,6 +6,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -6,6 +6,7 @@ namespace Titanium.Web.Proxy.Helpers
{ {
internal class NetworkHelper internal class NetworkHelper
{ {
#if NET45
private static int FindProcessIdFromLocalPort(int port, IpVersion ipVersion) private static int FindProcessIdFromLocalPort(int port, IpVersion ipVersion)
{ {
var tcpRow = TcpHelper.GetTcpRowByLocalPort(ipVersion, port); var tcpRow = TcpHelper.GetTcpRowByLocalPort(ipVersion, port);
...@@ -24,6 +25,7 @@ namespace Titanium.Web.Proxy.Helpers ...@@ -24,6 +25,7 @@ namespace Titanium.Web.Proxy.Helpers
return FindProcessIdFromLocalPort(port, IpVersion.Ipv6); return FindProcessIdFromLocalPort(port, IpVersion.Ipv6);
} }
#endif
/// <summary> /// <summary>
/// Adapated from below link /// Adapated from below link
......
...@@ -39,11 +39,13 @@ namespace Titanium.Web.Proxy.Network ...@@ -39,11 +39,13 @@ namespace Titanium.Web.Proxy.Network
get { return engine; } get { return engine; }
set set
{ {
#if NET45
//For Mono only Bouncy Castle is supported //For Mono only Bouncy Castle is supported
if (RunTime.IsRunningOnMono) if (RunTime.IsRunningOnMono)
{ {
value = CertificateEngine.BouncyCastle; value = CertificateEngine.BouncyCastle;
} }
#endif
if (value != engine) if (value != engine)
{ {
...@@ -220,6 +222,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -220,6 +222,7 @@ namespace Titanium.Web.Proxy.Network
TrustRootCertificate(StoreLocation.LocalMachine); TrustRootCertificate(StoreLocation.LocalMachine);
} }
#if NET45
/// <summary> /// <summary>
/// Puts the certificate to the local machine's certificate store. /// Puts the certificate to the local machine's certificate store.
/// Needs elevated permission. Works only on Windows. /// Needs elevated permission. Works only on Windows.
...@@ -264,6 +267,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -264,6 +267,7 @@ namespace Titanium.Web.Proxy.Network
return true; return true;
} }
#endif
/// <summary> /// <summary>
/// Removes the trusted certificates. /// Removes the trusted certificates.
...@@ -277,6 +281,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -277,6 +281,7 @@ namespace Titanium.Web.Proxy.Network
RemoveTrustedRootCertificates(StoreLocation.LocalMachine); RemoveTrustedRootCertificates(StoreLocation.LocalMachine);
} }
#if NET45
/// <summary> /// <summary>
/// Removes the trusted certificates from the local machine's certificate store. /// Removes the trusted certificates from the local machine's certificate store.
/// Needs elevated permission. Works only on Windows. /// Needs elevated permission. Works only on Windows.
...@@ -316,6 +321,7 @@ namespace Titanium.Web.Proxy.Network ...@@ -316,6 +321,7 @@ namespace Titanium.Web.Proxy.Network
return true; return true;
} }
#endif
/// <summary> /// <summary>
/// Determines whether the root certificate is trusted. /// Determines whether the root certificate is trusted.
......
...@@ -10,7 +10,9 @@ using System.Threading.Tasks; ...@@ -10,7 +10,9 @@ using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Extensions; using Titanium.Web.Proxy.Extensions;
using Titanium.Web.Proxy.Helpers; using Titanium.Web.Proxy.Helpers;
#if NET45
using Titanium.Web.Proxy.Helpers.WinHttp; using Titanium.Web.Proxy.Helpers.WinHttp;
#endif
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
using Titanium.Web.Proxy.Network; using Titanium.Web.Proxy.Network;
using Titanium.Web.Proxy.Network.Tcp; using Titanium.Web.Proxy.Network.Tcp;
...@@ -38,7 +40,9 @@ namespace Titanium.Web.Proxy ...@@ -38,7 +40,9 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
private Action<Exception> exceptionFunc; private Action<Exception> exceptionFunc;
#if NET45
private WinHttpWebProxyFinder systemProxyResolver; private WinHttpWebProxyFinder systemProxyResolver;
#endif
/// <summary> /// <summary>
/// Backing field for corresponding public property /// Backing field for corresponding public property
...@@ -60,10 +64,12 @@ namespace Titanium.Web.Proxy ...@@ -60,10 +64,12 @@ namespace Titanium.Web.Proxy
/// </summary> /// </summary>
private TcpConnectionFactory tcpConnectionFactory { get; } private TcpConnectionFactory tcpConnectionFactory { get; }
#if NET45
/// <summary> /// <summary>
/// Manage system proxy settings /// Manage system proxy settings
/// </summary> /// </summary>
private SystemProxyManager systemProxySettingsManager { get; } private SystemProxyManager systemProxySettingsManager { get; }
#endif
/// <summary> /// <summary>
/// Set firefox to use default system proxy /// Set firefox to use default system proxy
...@@ -296,10 +302,12 @@ namespace Titanium.Web.Proxy ...@@ -296,10 +302,12 @@ namespace Titanium.Web.Proxy
ProxyEndPoints = new List<ProxyEndPoint>(); ProxyEndPoints = new List<ProxyEndPoint>();
tcpConnectionFactory = new TcpConnectionFactory(); tcpConnectionFactory = new TcpConnectionFactory();
#if NET45
if (!RunTime.IsRunningOnMono) if (!RunTime.IsRunningOnMono)
{ {
systemProxySettingsManager = new SystemProxyManager(); systemProxySettingsManager = new SystemProxyManager();
} }
#endif
CertificateManager = new CertificateManager(ExceptionFunc); CertificateManager = new CertificateManager(ExceptionFunc);
if (rootCertificateName != null) if (rootCertificateName != null)
...@@ -352,6 +360,7 @@ namespace Titanium.Web.Proxy ...@@ -352,6 +360,7 @@ namespace Titanium.Web.Proxy
} }
} }
#if NET45
/// <summary> /// <summary>
/// Set the given explicit end point as the default proxy server for current machine /// Set the given explicit end point as the default proxy server for current machine
/// </summary> /// </summary>
...@@ -497,6 +506,7 @@ namespace Titanium.Web.Proxy ...@@ -497,6 +506,7 @@ namespace Titanium.Web.Proxy
systemProxySettingsManager.DisableAllProxy(); systemProxySettingsManager.DisableAllProxy();
} }
#endif
/// <summary> /// <summary>
/// Start this proxy server /// Start this proxy server
...@@ -508,6 +518,7 @@ namespace Titanium.Web.Proxy ...@@ -508,6 +518,7 @@ namespace Titanium.Web.Proxy
throw new Exception("Proxy is already running."); throw new Exception("Proxy is already running.");
} }
#if NET45
//clear any system proxy settings which is pointing to our own endpoint //clear any system proxy settings which is pointing to our own endpoint
//due to non gracious proxy shutdown before //due to non gracious proxy shutdown before
if (systemProxySettingsManager != null) if (systemProxySettingsManager != null)
...@@ -543,6 +554,7 @@ namespace Titanium.Web.Proxy ...@@ -543,6 +554,7 @@ namespace Titanium.Web.Proxy
GetCustomUpStreamHttpProxyFunc = GetSystemUpStreamProxy; GetCustomUpStreamHttpProxyFunc = GetSystemUpStreamProxy;
GetCustomUpStreamHttpsProxyFunc = GetSystemUpStreamProxy; GetCustomUpStreamHttpsProxyFunc = GetSystemUpStreamProxy;
} }
#endif
foreach (var endPoint in ProxyEndPoints) foreach (var endPoint in ProxyEndPoints)
{ {
...@@ -551,11 +563,13 @@ namespace Titanium.Web.Proxy ...@@ -551,11 +563,13 @@ namespace Titanium.Web.Proxy
CertificateManager.ClearIdleCertificates(CertificateCacheTimeOutMinutes); CertificateManager.ClearIdleCertificates(CertificateCacheTimeOutMinutes);
#if NET45
if (!RunTime.IsRunningOnMono) if (!RunTime.IsRunningOnMono)
{ {
//clear orphaned windows auth states every 2 minutes //clear orphaned windows auth states every 2 minutes
WinAuthEndPoint.ClearIdleStates(2); WinAuthEndPoint.ClearIdleStates(2);
} }
#endif
proxyRunning = true; proxyRunning = true;
} }
...@@ -571,6 +585,7 @@ namespace Titanium.Web.Proxy ...@@ -571,6 +585,7 @@ namespace Titanium.Web.Proxy
throw new Exception("Proxy is not running."); throw new Exception("Proxy is not running.");
} }
#if NET45
if (!RunTime.IsRunningOnMono) if (!RunTime.IsRunningOnMono)
{ {
bool setAsSystemProxy = ProxyEndPoints.OfType<ExplicitProxyEndPoint>().Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy); bool setAsSystemProxy = ProxyEndPoints.OfType<ExplicitProxyEndPoint>().Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy);
...@@ -580,6 +595,7 @@ namespace Titanium.Web.Proxy ...@@ -580,6 +595,7 @@ namespace Titanium.Web.Proxy
systemProxySettingsManager.RestoreOriginalSettings(); systemProxySettingsManager.RestoreOriginalSettings();
} }
} }
#endif
foreach (var endPoint in ProxyEndPoints) foreach (var endPoint in ProxyEndPoints)
{ {
...@@ -639,6 +655,7 @@ namespace Titanium.Web.Proxy ...@@ -639,6 +655,7 @@ namespace Titanium.Web.Proxy
} }
} }
#if NET45
/// <summary> /// <summary>
/// Gets the system up stream proxy. /// Gets the system up stream proxy.
/// </summary> /// </summary>
...@@ -649,7 +666,7 @@ namespace Titanium.Web.Proxy ...@@ -649,7 +666,7 @@ namespace Titanium.Web.Proxy
var proxy = systemProxyResolver.GetProxy(sessionEventArgs.WebSession.Request.RequestUri); var proxy = systemProxyResolver.GetProxy(sessionEventArgs.WebSession.Request.RequestUri);
return Task.FromResult(proxy); return Task.FromResult(proxy);
} }
#endif
private void EnsureRootCertificate() private void EnsureRootCertificate()
{ {
......
...@@ -338,6 +338,7 @@ namespace Titanium.Web.Proxy ...@@ -338,6 +338,7 @@ namespace Titanium.Web.Proxy
PrepareRequestHeaders(args.WebSession.Request.RequestHeaders); PrepareRequestHeaders(args.WebSession.Request.RequestHeaders);
args.WebSession.Request.Host = args.WebSession.Request.RequestUri.Authority; args.WebSession.Request.Host = args.WebSession.Request.RequestUri.Authority;
#if NET45
//if win auth is enabled //if win auth is enabled
//we need a cache of request body //we need a cache of request body
//so that we can send it after authentication in WinAuthHandler.cs //so that we can send it after authentication in WinAuthHandler.cs
...@@ -345,6 +346,7 @@ namespace Titanium.Web.Proxy ...@@ -345,6 +346,7 @@ namespace Titanium.Web.Proxy
{ {
await args.GetRequestBody(); await args.GetRequestBody();
} }
#endif
//If user requested interception do it //If user requested interception do it
if (BeforeRequest != null) if (BeforeRequest != null)
......
...@@ -33,6 +33,7 @@ namespace Titanium.Web.Proxy ...@@ -33,6 +33,7 @@ namespace Titanium.Web.Proxy
var response = args.WebSession.Response; var response = args.WebSession.Response;
#if NET45
//check for windows authentication //check for windows authentication
if (EnableWinAuth if (EnableWinAuth
&& !RunTime.IsRunningOnMono && !RunTime.IsRunningOnMono
...@@ -45,6 +46,7 @@ namespace Titanium.Web.Proxy ...@@ -45,6 +46,7 @@ namespace Titanium.Web.Proxy
return true; return true;
} }
} }
#endif
args.ReRequest = false; args.ReRequest = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment