77
88import org .apache .hc .client5 .http .SystemDefaultDnsResolver ;
99import org .apache .hc .client5 .http .classic .methods .HttpUriRequestBase ;
10+ import org .apache .hc .client5 .http .config .ConnectionConfig ;
1011import org .apache .hc .client5 .http .config .RequestConfig ;
1112import org .apache .hc .client5 .http .impl .DefaultSchemePortResolver ;
1213import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
13- import org .apache .hc .client5 .http .impl .classic .CloseableHttpResponse ;
1414import org .apache .hc .client5 .http .impl .classic .HttpClients ;
1515import org .apache .hc .client5 .http .impl .io .DefaultHttpClientConnectionOperator ;
1616import org .apache .hc .client5 .http .impl .io .ManagedHttpClientConnectionFactory ;
1717import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManager ;
1818import org .apache .hc .client5 .http .io .HttpClientConnectionOperator ;
1919import org .apache .hc .client5 .http .ssl .DefaultClientTlsStrategy ;
2020import org .apache .hc .client5 .http .ssl .TlsSocketStrategy ;
21+ import org .apache .hc .core5 .http .ClassicHttpResponse ;
2122import org .apache .hc .core5 .http .ConnectionClosedException ;
2223import org .apache .hc .core5 .http .ContentLengthStrategy ;
2324import org .apache .hc .core5 .http .Header ;
2425import org .apache .hc .core5 .http .HttpHeaders ;
2526import org .apache .hc .core5 .http .HttpHost ;
2627import org .apache .hc .core5 .http .NameValuePair ;
2728import org .apache .hc .core5 .http .impl .DefaultContentLengthStrategy ;
28- import org .apache .hc .core5 .http .impl .io .EmptyInputStream ;
2929import org .apache .hc .core5 .http .io .SocketConfig ;
3030import org .apache .hc .core5 .http .io .entity .ByteArrayEntity ;
31+ import org .apache .hc .core5 .http .io .entity .EmptyInputStream ;
3132import org .apache .hc .core5 .http .io .entity .InputStreamEntity ;
32- import org .apache .hc .core5 .http .protocol .BasicHttpContext ;
3333import org .apache .hc .core5 .http .protocol .HttpContext ;
34+ import org .apache .hc .core5 .http .protocol .HttpCoreContext ;
3435import org .apache .hc .core5 .net .URIAuthority ;
3536import org .apache .hc .core5 .util .TimeValue ;
3637import org .apache .hc .core5 .util .Timeout ;
@@ -119,21 +120,19 @@ protected ApacheDockerHttpClientImpl(
119120 .setSoTimeout (Timeout .ZERO_MILLISECONDS )
120121 .build ()
121122 );
122- connectionManager .setValidateAfterInactivity (TimeValue .NEG_ONE_SECOND );
123123 connectionManager .setMaxTotal (maxConnections );
124124 connectionManager .setDefaultMaxPerRoute (maxConnections );
125- RequestConfig .Builder defaultRequest = RequestConfig .custom ();
126- if (connectionTimeout != null ) {
127- defaultRequest .setConnectTimeout (connectionTimeout .toNanos (), TimeUnit .NANOSECONDS );
128- }
129- if (responseTimeout != null ) {
130- defaultRequest .setResponseTimeout (responseTimeout .toNanos (), TimeUnit .NANOSECONDS );
131- }
125+ connectionManager .setDefaultConnectionConfig (ConnectionConfig .custom ()
126+ .setValidateAfterInactivity (TimeValue .NEG_ONE_SECOND )
127+ .setConnectTimeout (connectionTimeout != null ? Timeout .of (connectionTimeout .toNanos (), TimeUnit .NANOSECONDS ) : null )
128+ .build ());
132129
133130 httpClient = HttpClients .custom ()
134131 .setRequestExecutor (new HijackingHttpRequestExecutor (null ))
135132 .setConnectionManager (connectionManager )
136- .setDefaultRequestConfig (defaultRequest .build ())
133+ .setDefaultRequestConfig (RequestConfig .custom ()
134+ .setResponseTimeout (responseTimeout != null ? Timeout .of (responseTimeout .toNanos (), TimeUnit .NANOSECONDS ) : null )
135+ .build ())
137136 .disableConnectionState ()
138137 .build ();
139138 }
@@ -163,7 +162,7 @@ private HttpClientConnectionOperator createConnectionOperator(
163162
164163 @ Override
165164 public Response execute (Request request ) {
166- HttpContext context = new BasicHttpContext ();
165+ HttpContext context = new HttpCoreContext ();
167166 HttpUriRequestBase httpUriRequest = new HttpUriRequestBase (request .method (), URI .create (pathPrefix + request .path ()));
168167 httpUriRequest .setScheme (host .getSchemeName ());
169168 httpUriRequest .setAuthority (new URIAuthority (host .getHostName (), host .getPort ()));
@@ -187,7 +186,7 @@ public Response execute(Request request) {
187186 }
188187
189188 try {
190- CloseableHttpResponse response = httpClient .execute (host , httpUriRequest , context );
189+ ClassicHttpResponse response = httpClient .executeOpen (host , httpUriRequest , context );
191190
192191 return new ApacheResponse (httpUriRequest , response );
193192 } catch (IOException e ) {
@@ -206,9 +205,9 @@ static class ApacheResponse implements Response {
206205
207206 private final HttpUriRequestBase request ;
208207
209- private final CloseableHttpResponse response ;
208+ private final ClassicHttpResponse response ;
210209
211- ApacheResponse (HttpUriRequestBase httpUriRequest , CloseableHttpResponse response ) {
210+ ApacheResponse (HttpUriRequestBase httpUriRequest , ClassicHttpResponse response ) {
212211 this .request = httpUriRequest ;
213212 this .response = response ;
214213 }
0 commit comments