Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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