diff --git a/src/Titanium.Web.Proxy.Mono.sln b/src/Titanium.Web.Proxy.Mono.sln deleted file mode 100644 index 4914496df..000000000 --- a/src/Titanium.Web.Proxy.Mono.sln +++ /dev/null @@ -1,61 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26906.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{B6DBABDC-C985-4872-9C38-B4E5079CBC4B}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentation", "{38EA62D0-D2CB-465D-AF4F-407C5B4D4A1E}" - ProjectSection(SolutionItems) = preProject - ..\LICENSE = ..\LICENSE - ..\PULL_REQUEST_TEMPLATE.md = ..\PULL_REQUEST_TEMPLATE.md - ..\README.md = ..\README.md - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{AC9AE37A-3059-4FDB-9A5C-363AD86F2EEF}" - ProjectSection(SolutionItems) = preProject - ..\.build\build.ps1 = ..\.build\build.ps1 - ..\.build\docfx.json = ..\.build\docfx.json - ..\.build\setup.ps1 = ..\.build\setup.ps1 - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Titanium.Web.Proxy.Mono", "Titanium.Web.Proxy\Titanium.Web.Proxy.Mono.csproj", "{5985EBC2-75E8-4555-B715-B2302D879F9B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Titanium.Web.Proxy.Examples.Basic.Mono", "..\examples\Titanium.Web.Proxy.Examples.Basic\Titanium.Web.Proxy.Examples.Basic.Mono.csproj", "{9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5985EBC2-75E8-4555-B715-B2302D879F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5985EBC2-75E8-4555-B715-B2302D879F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5985EBC2-75E8-4555-B715-B2302D879F9B}.Debug|x64.ActiveCfg = Debug|Any CPU - {5985EBC2-75E8-4555-B715-B2302D879F9B}.Debug|x64.Build.0 = Debug|Any CPU - {5985EBC2-75E8-4555-B715-B2302D879F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5985EBC2-75E8-4555-B715-B2302D879F9B}.Release|Any CPU.Build.0 = Release|Any CPU - {5985EBC2-75E8-4555-B715-B2302D879F9B}.Release|x64.ActiveCfg = Release|Any CPU - {5985EBC2-75E8-4555-B715-B2302D879F9B}.Release|x64.Build.0 = Release|Any CPU - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}.Debug|x64.ActiveCfg = Debug|Any CPU - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}.Debug|x64.Build.0 = Debug|Any CPU - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}.Release|Any CPU.Build.0 = Release|Any CPU - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}.Release|x64.ActiveCfg = Release|Any CPU - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09}.Release|x64.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {9B5FA6A0-8D7C-46AD-B4F5-3AF6E2720C09} = {B6DBABDC-C985-4872-9C38-B4E5079CBC4B} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EnterpriseLibraryConfigurationToolBinariesPath = .1.505.2\lib\NET35 - SolutionGuid = {625C1EB5-44CF-47DE-A85A-B4C8C40ED90A} - EndGlobalSection -EndGlobal diff --git a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs index f13ba0453..4e6630b10 100644 --- a/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs +++ b/src/Titanium.Web.Proxy/EventArguments/SessionEventArgs.cs @@ -606,7 +606,7 @@ public void Redirect(string url, bool closeServerConnection = false) var response = new RedirectResponse(); response.HttpVersion = HttpClient.Request.HttpVersion; response.Headers.AddHeader(KnownHeaders.Location, url); -#if NET45 +#if NET451 response.Body = Net45Compatibility.EmptyArray; #else response.Body = Array.Empty(); diff --git a/src/Titanium.Web.Proxy/AsyncEventHandler.cs b/src/Titanium.Web.Proxy/Handlers/AsyncEventHandler.cs similarity index 100% rename from src/Titanium.Web.Proxy/AsyncEventHandler.cs rename to src/Titanium.Web.Proxy/Handlers/AsyncEventHandler.cs diff --git a/src/Titanium.Web.Proxy/CertificateHandler.cs b/src/Titanium.Web.Proxy/Handlers/CertificateHandler.cs similarity index 100% rename from src/Titanium.Web.Proxy/CertificateHandler.cs rename to src/Titanium.Web.Proxy/Handlers/CertificateHandler.cs diff --git a/src/Titanium.Web.Proxy/ExceptionHandler.cs b/src/Titanium.Web.Proxy/Handlers/ExceptionHandler.cs similarity index 100% rename from src/Titanium.Web.Proxy/ExceptionHandler.cs rename to src/Titanium.Web.Proxy/Handlers/ExceptionHandler.cs diff --git a/src/Titanium.Web.Proxy/ProxyAuthorizationHandler.cs b/src/Titanium.Web.Proxy/Handlers/ProxyAuthorizationHandler.cs similarity index 100% rename from src/Titanium.Web.Proxy/ProxyAuthorizationHandler.cs rename to src/Titanium.Web.Proxy/Handlers/ProxyAuthorizationHandler.cs diff --git a/src/Titanium.Web.Proxy/WebSocketHandler.cs b/src/Titanium.Web.Proxy/Handlers/WebSocketHandler.cs similarity index 100% rename from src/Titanium.Web.Proxy/WebSocketHandler.cs rename to src/Titanium.Web.Proxy/Handlers/WebSocketHandler.cs diff --git a/src/Titanium.Web.Proxy/WinAuthHandler.cs b/src/Titanium.Web.Proxy/Handlers/WinAuthHandler.cs similarity index 100% rename from src/Titanium.Web.Proxy/WinAuthHandler.cs rename to src/Titanium.Web.Proxy/Handlers/WinAuthHandler.cs diff --git a/src/Titanium.Web.Proxy/Helpers/Net45Compatibility.cs b/src/Titanium.Web.Proxy/Helpers/Net45Compatibility.cs index e183d8fde..8fe9ca67f 100644 --- a/src/Titanium.Web.Proxy/Helpers/Net45Compatibility.cs +++ b/src/Titanium.Web.Proxy/Helpers/Net45Compatibility.cs @@ -1,4 +1,4 @@ -#if NET45 +#if NET451 using System; using System.Threading.Tasks; diff --git a/src/Titanium.Web.Proxy/Helpers/RunTime.cs b/src/Titanium.Web.Proxy/Helpers/RunTime.cs index 97a45f49e..c3a2ea9aa 100644 --- a/src/Titanium.Web.Proxy/Helpers/RunTime.cs +++ b/src/Titanium.Web.Proxy/Helpers/RunTime.cs @@ -13,7 +13,7 @@ public static class RunTime { private static readonly Lazy isRunningOnMono = new Lazy(() => Type.GetType("Mono.Runtime") != null); -#if NET45 || NET461 +#if NET451 || NET461 /// /// cache for Windows platform check /// diff --git a/src/Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs b/src/Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs index e20a7c677..56d21a355 100644 --- a/src/Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs +++ b/src/Titanium.Web.Proxy/Helpers/WinHttp/WinHttpWebProxyFinder.cs @@ -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(); diff --git a/src/Titanium.Web.Proxy/Http/HeaderBuilder.cs b/src/Titanium.Web.Proxy/Http/HeaderBuilder.cs index db957395f..2206425ba 100644 --- a/src/Titanium.Web.Proxy/Http/HeaderBuilder.cs +++ b/src/Titanium.Web.Proxy/Http/HeaderBuilder.cs @@ -94,7 +94,7 @@ public void Write(string str) public ArraySegment GetBuffer() { -#if NET45 +#if NET451 return new ArraySegment(stream.ToArray()); #else stream.TryGetBuffer(out var buffer); @@ -104,7 +104,7 @@ public ArraySegment GetBuffer() public string GetString(Encoding encoding) { -#if NET45 +#if NET451 return encoding.GetString(stream.ToArray()); #else stream.TryGetBuffer(out var buffer); diff --git a/src/Titanium.Web.Proxy/Http2/Hpack/Decoder.cs b/src/Titanium.Web.Proxy/Http2/Hpack/Decoder.cs index 89b624409..4448f4962 100644 --- a/src/Titanium.Web.Proxy/Http2/Hpack/Decoder.cs +++ b/src/Titanium.Web.Proxy/Http2/Hpack/Decoder.cs @@ -257,7 +257,7 @@ public void Decode(BinaryReader input, IHeaderListener headerListener) if (nameLength + HttpHeader.HttpHeaderOverhead > dynamicTable.Capacity) { dynamicTable.Clear(); -#if NET45 +#if NET451 name = Net45Compatibility.EmptyArray; #else name = Array.Empty(); @@ -378,7 +378,7 @@ public void Decode(BinaryReader input, IHeaderListener headerListener) if (valueLength == 0) { -#if NET45 +#if NET451 InsertHeader(headerListener, name, Net45Compatibility.EmptyArray, indexType); #else name = Array.Empty(); diff --git a/src/Titanium.Web.Proxy/Http2/Hpack/DynamicTable.cs b/src/Titanium.Web.Proxy/Http2/Hpack/DynamicTable.cs index 44ee27d1d..907eac83a 100644 --- a/src/Titanium.Web.Proxy/Http2/Hpack/DynamicTable.cs +++ b/src/Titanium.Web.Proxy/Http2/Hpack/DynamicTable.cs @@ -23,7 +23,7 @@ namespace Titanium.Web.Proxy.Http2.Hpack public class DynamicTable { // a circular queue of header fields -#if NET45 +#if NET451 HttpHeader[] headerFields = new HttpHeader[0]; #else HttpHeader[] headerFields = Array.Empty(); diff --git a/src/Titanium.Web.Proxy/Network/TcpConnection/TcpConnectionFactory.cs b/src/Titanium.Web.Proxy/Network/TcpConnection/TcpConnectionFactory.cs index 5d1c433fb..3194682fc 100644 --- a/src/Titanium.Web.Proxy/Network/TcpConnection/TcpConnectionFactory.cs +++ b/src/Titanium.Web.Proxy/Network/TcpConnection/TcpConnectionFactory.cs @@ -458,7 +458,7 @@ internal Task GetServerConnection(ProxyServer proxyServer, try { -#if NET45 +#if NET451 tcpServerSocket?.Close(); #else tcpServerSocket?.Dispose(); @@ -479,7 +479,7 @@ internal Task GetServerConnection(ProxyServer proxyServer, { // dispose the current TcpClient and try the next address lastException = e; -#if NET45 +#if NET451 tcpServerSocket?.Close(); #else tcpServerSocket?.Dispose(); diff --git a/src/Titanium.Web.Proxy/Network/Writers/NullWriter.cs b/src/Titanium.Web.Proxy/Network/Writers/NullWriter.cs index c3ef9dc82..fb917a8f9 100644 --- a/src/Titanium.Web.Proxy/Network/Writers/NullWriter.cs +++ b/src/Titanium.Web.Proxy/Network/Writers/NullWriter.cs @@ -20,7 +20,7 @@ public void Write(byte[] buffer, int offset, int count) public Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { -#if NET45 +#if NET451 return Net45Compatibility.CompletedTask; #else return Task.CompletedTask; diff --git a/src/Titanium.Web.Proxy/ProxyServer.cs b/src/Titanium.Web.Proxy/ProxyServer.cs index bd0f0872b..bf4f625bf 100644 --- a/src/Titanium.Web.Proxy/ProxyServer.cs +++ b/src/Titanium.Web.Proxy/ProxyServer.cs @@ -136,6 +136,11 @@ public ProxyServer(string? rootCertificateName, string? rootCertificateIssuerNam /// public bool ForwardToUpstreamGateway { get; set; } + /// + /// If set, the upstream proxy will be detected by a script that will be loaded from the provided Uri + /// + public Uri UpstreamProxyConfigurationScript { get; set; } + /// /// Enable disable Windows Authentication (NTLM/Kerberos). /// Note: NTLM/Kerberos will always send local credentials of current user @@ -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; } diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj deleted file mode 100644 index 510b66f60..000000000 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.Mono.csproj +++ /dev/null @@ -1,47 +0,0 @@ - - - - net461 - Titanium.Web.Proxy - false - True - StrongNameKey.snk - True - 8.0 - AnyCPU;x64 - - - - - - - - - - - - - - - True - True - - - True - True - - - True - True - - - True - True - - - True - True - - - - \ No newline at end of file diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj deleted file mode 100644 index 9bc3f43e3..000000000 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.NetCore.csproj +++ /dev/null @@ -1,52 +0,0 @@ - - - - netstandard2.1 - Titanium.Web.Proxy - false - True - StrongNameKey.snk - False - True - enable - 8.0 - - - - - - - - - - 5.0.0 - - - 5.0.0 - - - - - - True - True - - - True - True - - - True - True - - - True - True - - - True - True - - - - \ No newline at end of file diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj index c038ae86f..64890593a 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj @@ -1,7 +1,7 @@  - net45;net461;netstandard2.0;netstandard2.1 + net451;net461;netstandard2.0;netstandard2.1 Titanium.Web.Proxy false True @@ -23,7 +23,7 @@ - + 5.0.0 diff --git a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec index 585a2088e..908afe70f 100644 --- a/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec +++ b/src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec @@ -14,7 +14,7 @@ Copyright © Titanium. All rights reserved. - + @@ -48,7 +48,7 @@ - +