/// <summary> /// Constructor. /// </summary> /// <param name="settings">The settings</param> public DockerClient(DockerSettings settings) { Covenant.Requires <ArgumentNullException>(settings != null); // Select a custom managed handler when Docker is listening on a Unix // domain socket, otherwise use the standard handler. if (settings.Uri.Scheme.Equals("unix", StringComparison.OrdinalIgnoreCase)) { baseUri = "http://unix.sock"; handler = new ManagedHandler( async(string host, int port, CancellationToken cancellationToken) => { var sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); // $todo(jeff.lill): // // It looks like .NET Core 3.0 (and presumably .NET Standard 2.1 in the near future // implements this as [System.Net.Sockets.UnixDomainSocketEndPoint]. Look into // converting to this standard class in the future and dumping my hacked implementation. await sock.ConnectAsync(new Microsoft.Net.Http.Client.UnixDomainSocketEndPoint(settings.Uri.LocalPath)); return(sock); }); } else { baseUri = settings.Uri.ToString(); handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip }; } // Ensure that the [baseUri] doesn't end with a "/". if (baseUri.EndsWith("/")) { baseUri = baseUri.Substring(0, baseUri.Length - 1); } this.Settings = settings; this.JsonClient = new JsonClient(handler, disposeHandler: true) { SafeRetryPolicy = settings.RetryPolicy }; }
/// <summary> /// Constructor. /// </summary> /// <param name="settings">The settings</param> public DockerClient(DockerSettings settings) { Covenant.Requires <ArgumentNullException>(settings != null); // Select a custom managed handler when Docker is listening on a Unix // domain socket, otherwise use the standard handler. if (settings.Uri.Scheme.Equals("unix", StringComparison.OrdinalIgnoreCase)) { baseUri = "http://unix.sock"; handler = new ManagedHandler( async(string host, int port, CancellationToken cancellationToken) => { var sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); await sock.ConnectAsync(new UnixDomainSocketEndPoint(settings.Uri.LocalPath)); return(sock); }); } else { baseUri = settings.Uri.ToString(); handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip }; } // Ensure that the [baseUri] doesn't end with a "/". if (baseUri.EndsWith("/")) { baseUri = baseUri.Substring(0, baseUri.Length - 1); } this.Settings = settings; this.JsonClient = new JsonClient(handler, disposeHandler: true) { SafeRetryPolicy = settings.RetryPolicy }; }