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

Commit c008bff

Browse files
Gil MirmovitchGil Mirmovitch
authored andcommitted
#884 Allow explicitly setting PAC file for determining upstream proxy
1 parent e6837be commit c008bff

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ public void LoadFromIE()
144144
proxy = new WebProxy(new Uri("http://localhost"), BypassOnLocal, pi.BypassList);
145145
}
146146

147+
internal void UsePacFile(Uri upstreamProxyConfigurationScript)
148+
{
149+
AutomaticallyDetectSettings = true;
150+
AutomaticConfigurationScript = upstreamProxyConfigurationScript;
151+
BypassLoopback = true;
152+
BypassOnLocal = false;
153+
proxy = new WebProxy(new Uri("http://localhost"), BypassOnLocal);
154+
}
155+
156+
147157
private ProxyInfo getProxyInfo()
148158
{
149159
var proxyConfig = new NativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG();

src/Titanium.Web.Proxy/ProxyServer.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ public ProxyServer(string? rootCertificateName, string? rootCertificateIssuerNam
136136
/// </summary>
137137
public bool ForwardToUpstreamGateway { get; set; }
138138

139+
/// <summary>
140+
/// If set, the upstream proxy will be detected by a script that will be loaded from the provided Uri
141+
/// </summary>
142+
public Uri UpstreamProxyConfigurationScript { get; set; }
143+
139144
/// <summary>
140145
/// Enable disable Windows Authentication (NTLM/Kerberos).
141146
/// Note: NTLM/Kerberos will always send local credentials of current user
@@ -628,9 +633,17 @@ public void Start(bool changeSystemProxySettings = true)
628633

629634
if (ForwardToUpstreamGateway && GetCustomUpStreamProxyFunc == null && systemProxySettingsManager != null)
630635
{
631-
// Use WinHttp to handle PAC/WAPD scripts.
632636
systemProxyResolver = new WinHttpWebProxyFinder();
633-
systemProxyResolver.LoadFromIE();
637+
if (UpstreamProxyConfigurationScript != null)
638+
{
639+
//Use the provided proxy configuration script
640+
systemProxyResolver.UsePacFile(UpstreamProxyConfigurationScript);
641+
}
642+
else
643+
{
644+
// Use WinHttp to handle PAC/WAPD scripts.
645+
systemProxyResolver.LoadFromIE();
646+
}
634647

635648
GetCustomUpStreamProxyFunc = getSystemUpStreamProxy;
636649
}

0 commit comments

Comments
 (0)