4
4
import com .github .dockerjava .transport .NamedPipeSocket ;
5
5
import com .github .dockerjava .transport .SSLConfig ;
6
6
import com .github .dockerjava .transport .UnixSocket ;
7
+
8
+ import org .apache .hc .client5 .http .SystemDefaultDnsResolver ;
7
9
import org .apache .hc .client5 .http .classic .methods .HttpUriRequestBase ;
8
10
import org .apache .hc .client5 .http .config .RequestConfig ;
11
+ import org .apache .hc .client5 .http .impl .DefaultSchemePortResolver ;
9
12
import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
10
13
import org .apache .hc .client5 .http .impl .classic .CloseableHttpResponse ;
11
14
import org .apache .hc .client5 .http .impl .classic .HttpClients ;
15
+ import org .apache .hc .client5 .http .impl .io .DefaultHttpClientConnectionOperator ;
12
16
import org .apache .hc .client5 .http .impl .io .ManagedHttpClientConnectionFactory ;
13
17
import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManager ;
14
- import org .apache .hc .client5 .http .socket . ConnectionSocketFactory ;
15
- import org .apache .hc .client5 .http .socket . PlainConnectionSocketFactory ;
16
- import org .apache .hc .client5 .http .ssl .SSLConnectionSocketFactory ;
18
+ import org .apache .hc .client5 .http .io . HttpClientConnectionOperator ;
19
+ import org .apache .hc .client5 .http .ssl . DefaultClientTlsStrategy ;
20
+ import org .apache .hc .client5 .http .ssl .TlsSocketStrategy ;
17
21
import org .apache .hc .core5 .http .ConnectionClosedException ;
18
22
import org .apache .hc .core5 .http .ContentLengthStrategy ;
19
23
import org .apache .hc .core5 .http .Header ;
20
24
import org .apache .hc .core5 .http .HttpHeaders ;
21
25
import org .apache .hc .core5 .http .HttpHost ;
22
26
import org .apache .hc .core5 .http .NameValuePair ;
23
- import org .apache .hc .core5 .http .config .Registry ;
24
- import org .apache .hc .core5 .http .config .RegistryBuilder ;
25
27
import org .apache .hc .core5 .http .impl .DefaultContentLengthStrategy ;
26
28
import org .apache .hc .core5 .http .impl .io .EmptyInputStream ;
27
29
import org .apache .hc .core5 .http .io .SocketConfig ;
38
40
import javax .net .ssl .SSLContext ;
39
41
import java .io .IOException ;
40
42
import java .io .InputStream ;
41
- import java .net .InetSocketAddress ;
42
43
import java .net .Socket ;
43
44
import java .net .URI ;
44
45
import java .time .Duration ;
@@ -61,7 +62,13 @@ protected ApacheDockerHttpClientImpl(
61
62
Duration connectionTimeout ,
62
63
Duration responseTimeout
63
64
) {
64
- Registry <ConnectionSocketFactory > socketFactoryRegistry = createConnectionSocketFactoryRegistry (sslConfig , dockerHost );
65
+ SSLContext sslContext ;
66
+ try {
67
+ sslContext = sslConfig != null ? sslConfig .getSSLContext () : null ;
68
+ } catch (Exception e ) {
69
+ throw new RuntimeException (e );
70
+ }
71
+ HttpClientConnectionOperator connectionOperator = createConnectionOperator (dockerHost , sslContext );
65
72
66
73
switch (dockerHost .getScheme ()) {
67
74
case "unix" :
@@ -75,7 +82,7 @@ protected ApacheDockerHttpClientImpl(
75
82
? rawPath .substring (0 , rawPath .length () - 1 )
76
83
: rawPath ;
77
84
host = new HttpHost (
78
- socketFactoryRegistry . lookup ( "https" ) != null ? "https" : "http" ,
85
+ sslContext != null ? "https" : "http" ,
79
86
dockerHost .getHost (),
80
87
dockerHost .getPort ()
81
88
);
@@ -85,7 +92,10 @@ protected ApacheDockerHttpClientImpl(
85
92
}
86
93
87
94
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager (
88
- socketFactoryRegistry ,
95
+ connectionOperator ,
96
+ null ,
97
+ null ,
98
+ null ,
89
99
new ManagedHttpClientConnectionFactory (
90
100
null ,
91
101
null ,
@@ -128,53 +138,27 @@ protected ApacheDockerHttpClientImpl(
128
138
.build ();
129
139
}
130
140
131
- private Registry < ConnectionSocketFactory > createConnectionSocketFactoryRegistry (
132
- SSLConfig sslConfig ,
133
- URI dockerHost
141
+ private HttpClientConnectionOperator createConnectionOperator (
142
+ URI dockerHost ,
143
+ SSLContext sslContext
134
144
) {
135
- RegistryBuilder <ConnectionSocketFactory > socketFactoryRegistryBuilder = RegistryBuilder .create ();
136
-
137
- if (sslConfig != null ) {
138
- try {
139
- SSLContext sslContext = sslConfig .getSSLContext ();
140
- if (sslContext != null ) {
141
- socketFactoryRegistryBuilder .register ("https" , new SSLConnectionSocketFactory (sslContext ));
142
- }
143
- } catch (Exception e ) {
144
- throw new RuntimeException (e );
145
- }
146
- }
147
-
148
- return socketFactoryRegistryBuilder
149
- .register ("tcp" , PlainConnectionSocketFactory .INSTANCE )
150
- .register ("http" , PlainConnectionSocketFactory .INSTANCE )
151
- .register ("unix" , new ConnectionSocketFactory () {
152
- @ Override
153
- public Socket createSocket (HttpContext context ) throws IOException {
154
- return UnixSocket .get (dockerHost .getPath ());
155
- }
156
-
157
- @ Override
158
- public Socket connectSocket (TimeValue timeValue , Socket socket , HttpHost httpHost , InetSocketAddress inetSocketAddress ,
159
- InetSocketAddress inetSocketAddress1 , HttpContext httpContext ) throws IOException {
160
- return PlainConnectionSocketFactory .INSTANCE .connectSocket (timeValue , socket , httpHost , inetSocketAddress ,
161
- inetSocketAddress1 , httpContext );
162
- }
163
- })
164
- .register ("npipe" , new ConnectionSocketFactory () {
165
- @ Override
166
- public Socket createSocket (HttpContext context ) {
167
- return new NamedPipeSocket (dockerHost .getPath ());
145
+ String dockerHostScheme = dockerHost .getScheme ();
146
+ String dockerHostPath = dockerHost .getPath ();
147
+ TlsSocketStrategy tlsSocketStrategy = sslContext != null ?
148
+ new DefaultClientTlsStrategy (sslContext ) : DefaultClientTlsStrategy .createSystemDefault ();
149
+ return new DefaultHttpClientConnectionOperator (
150
+ socksProxy -> {
151
+ if ("unix" .equalsIgnoreCase (dockerHostScheme )) {
152
+ return UnixSocket .get (dockerHostPath );
153
+ } else if ("npipe" .equalsIgnoreCase (dockerHostScheme )) {
154
+ return new NamedPipeSocket (dockerHostPath );
155
+ } else {
156
+ return socksProxy == null ? new Socket () : new Socket (socksProxy );
168
157
}
169
-
170
- @ Override
171
- public Socket connectSocket (TimeValue timeValue , Socket socket , HttpHost httpHost , InetSocketAddress inetSocketAddress ,
172
- InetSocketAddress inetSocketAddress1 , HttpContext httpContext ) throws IOException {
173
- return PlainConnectionSocketFactory .INSTANCE .connectSocket (timeValue , socket , httpHost , inetSocketAddress ,
174
- inetSocketAddress1 , httpContext );
175
- }
176
- })
177
- .build ();
158
+ },
159
+ DefaultSchemePortResolver .INSTANCE ,
160
+ SystemDefaultDnsResolver .INSTANCE ,
161
+ name -> "https" .equalsIgnoreCase (name ) ? tlsSocketStrategy : null );
178
162
}
179
163
180
164
@ Override
0 commit comments