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

Commit 26f971d

Browse files
authored
Merge pull request #885 from mirgil/explicit-pac-file
Allow explicitly setting a PAC file for determining upstream proxy #884
2 parents e6837be + a8930c3 commit 26f971d

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ 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+
147156
private ProxyInfo getProxyInfo()
148157
{
149158
var proxyConfig = new NativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG();

src/Titanium.Web.Proxy/ProxyServer.cs

+15-2
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)