Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Read system proxy information on macOS #36177

Merged
merged 5 commits into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -38,7 +38,7 @@ namespace Microsoft.Win32.SafeHandles
{
internal sealed class SafeCFArrayHandle : SafeHandle
{
internal SafeCFArrayHandle()
private SafeCFArrayHandle()
: base(IntPtr.Zero, ownsHandle: true)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.Win32.SafeHandles
{
internal sealed class SafeCFDictionaryHandle : SafeHandle
{
internal SafeCFDictionaryHandle()
private SafeCFDictionaryHandle()
: base(IntPtr.Zero, ownsHandle: true)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/Common/src/Interop/OSX/Interop.CoreFoundation.CFProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal class CFProxy

static CFProxy()
{
IntPtr lib = Interop.Libdl.dlopen(Interop.Libraries.CFNetworkLibrary, Interop.Libdl.RTLD_LAZY);
IntPtr lib = NativeLibrary.Load(Interop.Libraries.CFNetworkLibrary);
if (lib != IntPtr.Zero)
{
kCFProxyTypeAutoConfigurationURL = LoadCFStringSymbol(lib, "kCFProxyTypeAutoConfigurationURL");
Expand All @@ -94,7 +94,7 @@ public CFProxy(SafeCFDictionaryHandle dictionary)

private static IntPtr LoadSymbol(IntPtr lib, string name)
{
IntPtr indirect = Interop.Libdl.dlsym(lib, name);
IntPtr indirect = NativeLibrary.GetExport(lib, name);
return indirect == IntPtr.Zero ? IntPtr.Zero : Marshal.ReadIntPtr(indirect);
filipnavara marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
8 changes: 1 addition & 7 deletions src/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
</ItemGroup>
<!-- SocketsHttpHandler platform parts -->
<ItemGroup Condition=" '$(TargetsUnix)' == 'true' And '$(TargetGroup)' == 'netcoreapp'">
<Compile Include="System\Net\Http\SocketsHttpHandler\HttpEnvironmentProxy.cs" />
<Compile Include="$(CommonPath)\System\Net\ContextAwareResult.Unix.cs">
<Link>Common\System\Net\ContextAwareResult.Unix.cs</Link>
</Compile>
Expand Down Expand Up @@ -256,7 +257,6 @@
</ItemGroup>
<ItemGroup Condition=" '$(TargetsUnix)' == 'true' And '$(TargetsOSX)' != 'true' And '$(TargetGroup)' == 'netcoreapp'">
<Compile Include="System\Net\Http\SocketsHttpHandler\SystemProxyInfo.Unix.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\HttpEnvironmentProxy.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsOSX)' == 'true' And '$(TargetGroup)' == 'netcoreapp'">
<Compile Include="System\Net\Http\SocketsHttpHandler\SystemProxyInfo.OSX.cs" />
Expand Down Expand Up @@ -294,12 +294,6 @@
<Compile Include="$(CommonPath)\Interop\OSX\Interop.Libraries.cs">
<Link>Common\Interop\OSX\Interop.Libraries.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Unix\libdl\Interop.dlopen.cs">
<Link>Common\Interop\Unix\libdl\Interop.dlopen.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Interop\Unix\libdl\Interop.dlsym.cs">
<Link>Common\Interop\Unix\libdl\Interop.dlsym.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\Microsoft\Win32\SafeHandles\SafeCreateHandle.OSX.cs">
<Link>Common\Microsoft\Win32\SafeHandles\SafeCreateHandle.OSX.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using static Interop.RunLoop;

using CFRunLoopRef = System.IntPtr;
using CFRunLoopSourceRef = System.IntPtr;

namespace System.Net.Http
{
Expand All @@ -22,9 +23,9 @@ public ICredentials Credentials
set => throw new NotSupportedException();
}

static Uri GetProxyUri(string scheme, CFProxy proxy)
private static Uri GetProxyUri(string scheme, CFProxy proxy)
{
var uriBuilder = new UriBuilder(
UriBuilder uriBuilder = new UriBuilder(
filipnavara marked this conversation as resolved.
Show resolved Hide resolved
scheme,
proxy.HostName,
proxy.PortNumber);
Expand Down Expand Up @@ -65,20 +66,22 @@ public Uri ExecuteProxyAutoConfiguration(SafeCreateHandle cfurl, CFProxy proxy)
CFRunLoopStop(runLoop);
};

var clientContext = new CFStreamClientContext();
var loopSource =
CFStreamClientContext clientContext = new CFStreamClientContext();
filipnavara marked this conversation as resolved.
Show resolved Hide resolved
CFRunLoopSourceRef loopSource =
proxy.ProxyType == CFProxy.kCFProxyTypeAutoConfigurationURL ?
CFNetworkExecuteProxyAutoConfigurationURL(proxy.AutoConfigurationURL, cfurl, cb, ref clientContext) :
CFNetworkExecuteProxyAutoConfigurationScript(proxy.AutoConfigurationJavaScript, cfurl, cb, ref clientContext);

using (var mode = CFStringCreateWithCString("System.Net.Http.MacProxy"))
using (var mode = CFStringCreateWithCString(typeof(MacProxy).FullName))
{
IntPtr modeHandle = mode.DangerousGetHandle();
CFRunLoopAddSource(runLoop, loopSource, modeHandle);
int resultz = CFRunLoopRunInMode(modeHandle, double.MaxValue, 0);
CFRunLoopRunInMode(modeHandle, double.MaxValue, 0);
CFRunLoopSourceInvalidate(loopSource);
}

GC.KeepAlive(cb);

return result;
}

Expand Down Expand Up @@ -116,7 +119,7 @@ public Uri GetProxy(Uri targetUri)
public bool IsBypassed(Uri targetUri)
{
if (targetUri == null)
throw new ArgumentNullException ("targetUri");
throw new ArgumentNullException(nameof(targetUri));

Uri proxyUri = GetProxy(targetUri);
return Equals(proxyUri, targetUri) || proxyUri == null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class SystemProxyInfo
// On Unix we get default proxy configuration from environment variables
public static IWebProxy ConstructSystemProxy()
{
return new MacProxy();
return HttpEnvironmentProxy.TryCreate(out IWebProxy proxy) ? proxy : new MacProxy();
}
}
}
Expand Down