8
8
import com .cloudinary .utils .StringUtils ;
9
9
import org .apache .hc .client5 .http .classic .methods .HttpPost ;
10
10
import org .apache .hc .client5 .http .classic .methods .HttpUriRequestBase ;
11
+ import org .apache .hc .client5 .http .config .RequestConfig ;
11
12
import org .apache .hc .client5 .http .entity .mime .ByteArrayBody ;
12
13
import org .apache .hc .client5 .http .entity .mime .FileBody ;
13
14
import org .apache .hc .client5 .http .entity .mime .HttpMultipartMode ;
14
15
import org .apache .hc .client5 .http .entity .mime .MultipartEntityBuilder ;
15
16
import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
16
17
import org .apache .hc .client5 .http .impl .classic .CloseableHttpResponse ;
18
+ import org .apache .hc .client5 .http .impl .classic .HttpClientBuilder ;
17
19
import org .apache .hc .client5 .http .impl .classic .HttpClients ;
20
+ import org .apache .hc .client5 .http .io .HttpClientConnectionManager ;
18
21
import org .apache .hc .core5 .http .ContentType ;
22
+ import org .apache .hc .core5 .http .HttpHost ;
19
23
import org .apache .hc .core5 .http .ParseException ;
20
24
import org .apache .hc .core5 .http .io .entity .EntityUtils ;
25
+ import org .apache .hc .core5 .util .Timeout ;
21
26
22
27
import java .io .File ;
23
28
import java .io .IOException ;
@@ -35,11 +40,39 @@ public class UploaderStrategy extends AbstractUploaderStrategy {
35
40
public void init (Uploader uploader ) {
36
41
super .init (uploader );
37
42
38
- this .client = HttpClients .custom ()
39
- .setUserAgent (cloudinary ().getUserAgent () + " ApacheHttpClient/" + APACHE_HTTP_CLIENT_VERSION )
43
+ HttpClientBuilder clientBuilder = HttpClients .custom ();
44
+ clientBuilder .useSystemProperties ().setUserAgent (cloudinary ().getUserAgent () + " ApacheHttpClient/" + APACHE_HTTP_CLIENT_VERSION );
45
+
46
+ HttpClientConnectionManager connectionManager = (HttpClientConnectionManager ) cloudinary ().config .properties .get ("connectionManager" );
47
+ if (connectionManager != null ) {
48
+ clientBuilder .setConnectionManager (connectionManager );
49
+ }
50
+
51
+ RequestConfig requestConfig = buildRequestConfig ();
52
+
53
+ client = clientBuilder
54
+ .setDefaultRequestConfig (requestConfig )
40
55
.build ();
41
56
}
42
57
58
+ public RequestConfig buildRequestConfig () {
59
+ RequestConfig .Builder requestConfigBuilder = RequestConfig .custom ();
60
+
61
+ if (cloudinary ().config .proxyHost != null && cloudinary ().config .proxyPort != 0 ) {
62
+ HttpHost proxy = new HttpHost (cloudinary ().config .proxyHost , cloudinary ().config .proxyPort );
63
+ requestConfigBuilder .setProxy (proxy );
64
+ }
65
+
66
+ int timeout = cloudinary ().config .timeout ;
67
+ if (timeout > 0 ) {
68
+ requestConfigBuilder .setResponseTimeout (Timeout .ofSeconds (timeout ))
69
+ .setConnectionRequestTimeout (Timeout .ofSeconds (timeout ))
70
+ .setConnectTimeout (Timeout .ofSeconds (timeout ));
71
+ }
72
+
73
+ return requestConfigBuilder .build ();
74
+ }
75
+
43
76
@ SuppressWarnings ({"rawtypes" , "unchecked" })
44
77
@ Override
45
78
public Map callApi (String action , Map <String , Object > params , Map options , Object file , ProgressCallback progressCallback ) throws IOException {
0 commit comments