|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.IO;
|
4 |
| -using System.IO.Pipes; |
5 | 4 | using System.Linq;
|
6 | 5 | using System.Net;
|
7 | 6 | using System.Net.Http;
|
@@ -47,78 +46,8 @@ internal DockerClient(DockerClientConfiguration configuration, Version requested
|
47 | 46 | Plugin = new PluginOperations(this);
|
48 | 47 | Exec = new ExecOperations(this);
|
49 | 48 |
|
50 |
| - ManagedHandler handler; |
51 |
| - var uri = Configuration.EndpointBaseUri; |
52 |
| - switch (uri.Scheme.ToLowerInvariant()) |
53 |
| - { |
54 |
| - case "npipe": |
55 |
| - if (Configuration.Credentials.IsTlsCredentials()) |
56 |
| - { |
57 |
| - throw new Exception("TLS not supported over npipe"); |
58 |
| - } |
59 |
| - |
60 |
| - var segments = uri.Segments; |
61 |
| - if (segments.Length != 3 || !segments[1].Equals("pipe/", StringComparison.OrdinalIgnoreCase)) |
62 |
| - { |
63 |
| - throw new ArgumentException($"{Configuration.EndpointBaseUri} is not a valid npipe URI"); |
64 |
| - } |
65 |
| - |
66 |
| - var serverName = uri.Host; |
67 |
| - if (string.Equals(serverName, "localhost", StringComparison.OrdinalIgnoreCase)) |
68 |
| - { |
69 |
| - // npipe schemes dont work with npipe://localhost/... and need npipe://./... so fix that for a client here. |
70 |
| - serverName = "."; |
71 |
| - } |
72 |
| - |
73 |
| - var pipeName = uri.Segments[2]; |
74 |
| - |
75 |
| - uri = new UriBuilder("http", pipeName).Uri; |
76 |
| - handler = new ManagedHandler(async (host, port, cancellationToken) => |
77 |
| - { |
78 |
| - var timeout = (int)Configuration.NamedPipeConnectTimeout.TotalMilliseconds; |
79 |
| - var stream = new NamedPipeClientStream(serverName, pipeName, PipeDirection.InOut, PipeOptions.Asynchronous); |
80 |
| - var dockerStream = new DockerPipeStream(stream); |
81 |
| - |
82 |
| - await stream.ConnectAsync(timeout, cancellationToken) |
83 |
| - .ConfigureAwait(false); |
84 |
| - |
85 |
| - return dockerStream; |
86 |
| - }); |
87 |
| - break; |
88 |
| - |
89 |
| - case "tcp": |
90 |
| - case "http": |
91 |
| - var builder = new UriBuilder(uri) |
92 |
| - { |
93 |
| - Scheme = configuration.Credentials.IsTlsCredentials() ? "https" : "http" |
94 |
| - }; |
95 |
| - uri = builder.Uri; |
96 |
| - handler = new ManagedHandler(); |
97 |
| - break; |
98 |
| - |
99 |
| - case "https": |
100 |
| - handler = new ManagedHandler(); |
101 |
| - break; |
102 |
| - |
103 |
| - case "unix": |
104 |
| - var pipeString = uri.LocalPath; |
105 |
| - handler = new ManagedHandler(async (host, port, cancellationToken) => |
106 |
| - { |
107 |
| - var sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); |
108 |
| - |
109 |
| - await sock.ConnectAsync(new Microsoft.Net.Http.Client.UnixDomainSocketEndPoint(pipeString)) |
110 |
| - .ConfigureAwait(false); |
111 |
| - |
112 |
| - return sock; |
113 |
| - }); |
114 |
| - uri = new UriBuilder("http", uri.Segments.Last()).Uri; |
115 |
| - break; |
116 |
| - |
117 |
| - default: |
118 |
| - throw new Exception($"Unknown URL scheme {configuration.EndpointBaseUri.Scheme}"); |
119 |
| - } |
120 |
| - |
121 |
| - _endpointBaseUri = uri; |
| 49 | + var (url, handler) = Configuration.GetHandler(); |
| 50 | + _endpointBaseUri = url; |
122 | 51 |
|
123 | 52 | _client = new HttpClient(Configuration.Credentials.GetHandler(handler), true);
|
124 | 53 | _client.Timeout = SInfiniteTimeout;
|
|
0 commit comments