Commit b2c7c691 authored by Honfika's avatar Honfika

Prepare for .NET standard version

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