Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit c2994bc

Browse files
committed
system proxy do not support non-windows env
1 parent fc15352 commit c2994bc

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/Titanium.Web.Proxy/Network/CertificateManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Diagnostics;
@@ -149,7 +149,7 @@ public CertificateEngine CertificateEngine
149149
set
150150
{
151151
// For Mono (or Non-Windows) only Bouncy Castle is supported
152-
if (!RunTime.IsWindows || RunTime.IsRunningOnMono)
152+
if (!RunTime.IsWindows)
153153
{
154154
value = CertificateEngine.BouncyCastle;
155155
}
@@ -662,7 +662,7 @@ public void TrustRootCertificate(bool machineTrusted = false)
662662
/// <returns>True if success.</returns>
663663
public bool TrustRootCertificateAsAdmin(bool machineTrusted = false)
664664
{
665-
if (!RunTime.IsWindows || RunTime.IsRunningOnMono)
665+
if (!RunTime.IsWindows)
666666
{
667667
return false;
668668
}
@@ -805,7 +805,7 @@ public void RemoveTrustedRootCertificate(bool machineTrusted = false)
805805
/// <returns>Should also remove from machine store?</returns>
806806
public bool RemoveTrustedRootCertificateAsAdmin(bool machineTrusted = false)
807807
{
808-
if (!RunTime.IsWindows || RunTime.IsRunningOnMono)
808+
if (!RunTime.IsWindows)
809809
{
810810
return false;
811811
}

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private async Task<TcpServerConnection> createServerConnection(string remoteHost
280280
};
281281

282282
//linux has a bug with socket reuse in .net core.
283-
if (proxyServer.ReuseSocket && (RunTime.IsWindows || RunTime.IsRunningOnMono))
283+
if (proxyServer.ReuseSocket && RunTime.IsWindows)
284284
{
285285
tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
286286
}

src/Titanium.Web.Proxy/ProxyServer.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName,
102102

103103
ProxyEndPoints = new List<ProxyEndPoint>();
104104
tcpConnectionFactory = new TcpConnectionFactory(this);
105-
if (!RunTime.IsRunningOnMono && RunTime.IsWindows && !RunTime.IsUwpOnWindows)
105+
if (RunTime.IsWindows && !RunTime.IsUwpOnWindows)
106106
{
107107
systemProxySettingsManager = new SystemProxyManager();
108108
}
@@ -511,9 +511,10 @@ public void DisableSystemHttpsProxy()
511511
/// </summary>
512512
public void DisableSystemProxy(ProxyProtocolType protocolType)
513513
{
514-
if (RunTime.IsRunningOnMono)
514+
if (!RunTime.IsWindows)
515515
{
516-
throw new Exception("Mono Runtime do not support system proxy settings.");
516+
throw new NotSupportedException(@"Setting system proxy settings are only supported in Windows.
517+
Please manually confugure you operating system to use this proxy's port and address.");
517518
}
518519

519520
systemProxySettingsManager.RemoveProxy(protocolType);
@@ -524,9 +525,10 @@ public void DisableSystemProxy(ProxyProtocolType protocolType)
524525
/// </summary>
525526
public void DisableAllSystemProxies()
526527
{
527-
if (RunTime.IsRunningOnMono)
528+
if (!RunTime.IsWindows)
528529
{
529-
throw new Exception("Mono Runtime do not support system proxy settings.");
530+
throw new NotSupportedException(@"Setting system proxy settings are only supported in Windows.
531+
Please manually confugure you operating system to use this proxy's port and address.");
530532
}
531533

532534
systemProxySettingsManager.DisableAllProxy();
@@ -600,7 +602,7 @@ public void Stop()
600602
throw new Exception("Proxy is not running.");
601603
}
602604

603-
if (!RunTime.IsRunningOnMono && RunTime.IsWindows && !RunTime.IsUwpOnWindows)
605+
if (RunTime.IsWindows && !RunTime.IsUwpOnWindows)
604606
{
605607
bool setAsSystemProxy = ProxyEndPoints.OfType<ExplicitProxyEndPoint>()
606608
.Any(x => x.IsSystemHttpProxy || x.IsSystemHttpsProxy);
@@ -633,7 +635,7 @@ private void listen(ProxyEndPoint endPoint)
633635
endPoint.Listener = new TcpListener(endPoint.IpAddress, endPoint.Port);
634636

635637
//linux/macOS has a bug with socket reuse in .net core.
636-
if (ReuseSocket && (RunTime.IsWindows || RunTime.IsRunningOnMono))
638+
if (ReuseSocket && RunTime.IsWindows)
637639
{
638640
endPoint.Listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
639641
}

src/Titanium.Web.Proxy/RequestHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Titanium.Web.Proxy
2727
public partial class ProxyServer
2828
{
2929
private bool isWindowsAuthenticationEnabledAndSupported =>
30-
EnableWinAuth && RunTime.IsWindows && !RunTime.IsRunningOnMono;
30+
EnableWinAuth && RunTime.IsWindows;
3131

3232
/// <summary>
3333
/// This is the core request handler method for a particular connection from client.

0 commit comments

Comments
 (0)