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

Commit

Permalink
Merge pull request #885 from mirgil/explicit-pac-file
Browse files Browse the repository at this point in the history
Allow explicitly setting a PAC file for determining upstream proxy #884
  • Loading branch information
honfika authored Nov 9, 2021
2 parents e6837be + a8930c3 commit 26f971d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ public void LoadFromIE()
proxy = new WebProxy(new Uri("http://localhost"), BypassOnLocal, pi.BypassList);
}

internal void UsePacFile(Uri upstreamProxyConfigurationScript)
{
AutomaticallyDetectSettings = true;
AutomaticConfigurationScript = upstreamProxyConfigurationScript;
BypassLoopback = true;
BypassOnLocal = false;
proxy = new WebProxy(new Uri("http://localhost"), BypassOnLocal);
}

private ProxyInfo getProxyInfo()
{
var proxyConfig = new NativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG();
Expand Down
17 changes: 15 additions & 2 deletions src/Titanium.Web.Proxy/ProxyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public ProxyServer(string? rootCertificateName, string? rootCertificateIssuerNam
/// </summary>
public bool ForwardToUpstreamGateway { get; set; }

/// <summary>
/// If set, the upstream proxy will be detected by a script that will be loaded from the provided Uri
/// </summary>
public Uri UpstreamProxyConfigurationScript { get; set; }

/// <summary>
/// Enable disable Windows Authentication (NTLM/Kerberos).
/// Note: NTLM/Kerberos will always send local credentials of current user
Expand Down Expand Up @@ -628,9 +633,17 @@ public void Start(bool changeSystemProxySettings = true)

if (ForwardToUpstreamGateway && GetCustomUpStreamProxyFunc == null && systemProxySettingsManager != null)
{
// Use WinHttp to handle PAC/WAPD scripts.
systemProxyResolver = new WinHttpWebProxyFinder();
systemProxyResolver.LoadFromIE();
if (UpstreamProxyConfigurationScript != null)
{
//Use the provided proxy configuration script
systemProxyResolver.UsePacFile(UpstreamProxyConfigurationScript);
}
else
{
// Use WinHttp to handle PAC/WAPD scripts.
systemProxyResolver.LoadFromIE();
}

GetCustomUpStreamProxyFunc = getSystemUpStreamProxy;
}
Expand Down

0 comments on commit 26f971d

Please sign in to comment.