49
49
import org .apache .http .client .methods .HttpUriRequest ;
50
50
import org .apache .http .client .params .ClientPNames ;
51
51
import org .apache .http .client .protocol .ClientContext ;
52
+ import org .apache .http .conn .ClientConnectionManager ;
52
53
import org .apache .http .conn .params .ConnManagerParams ;
53
54
import org .apache .http .conn .params .ConnPerRouteBean ;
54
55
import org .apache .http .conn .params .ConnRoutePNames ;
@@ -237,7 +238,8 @@ public AsyncHttpClient(SchemeRegistry schemeRegistry) {
237
238
238
239
HttpProtocolParams .setVersion (httpParams , HttpVersion .HTTP_1_1 );
239
240
240
- ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager (httpParams , schemeRegistry );
241
+ ClientConnectionManager cm = createConnectionManager (schemeRegistry , httpParams );
242
+ Utils .asserts (cm != null , "Custom implementation of #createConnectionManager(SchemeRegistry, BasicHttpParams) returned null" );
241
243
242
244
threadPool = getDefaultThreadPool ();
243
245
requestMap = Collections .synchronizedMap (new WeakHashMap <Context , List <RequestHandle >>());
@@ -382,6 +384,17 @@ protected ExecutorService getDefaultThreadPool() {
382
384
return Executors .newCachedThreadPool ();
383
385
}
384
386
387
+ /**
388
+ * Provided so it is easier for developers to provide custom ThreadSafeClientConnManager implementation
389
+ *
390
+ * @param schemeRegistry SchemeRegistry, usually provided by {@link #getDefaultSchemeRegistry(boolean, int, int)}
391
+ * @param httpParams BasicHttpParams
392
+ * @return ClientConnectionManager instance
393
+ */
394
+ protected ClientConnectionManager createConnectionManager (SchemeRegistry schemeRegistry , BasicHttpParams httpParams ) {
395
+ return new ThreadSafeClientConnManager (httpParams , schemeRegistry );
396
+ }
397
+
385
398
/**
386
399
* Simple interface method, to enable or disable redirects. If you set manually RedirectHandler
387
400
* on underlying HttpClient, effects of this method will be canceled. <p> </p> Default
@@ -1065,7 +1078,7 @@ public RequestHandle put(Context context, String url, Header[] headers, HttpEnti
1065
1078
if (headers != null ) request .setHeaders (headers );
1066
1079
return sendRequest (httpClient , httpContext , request , contentType , responseHandler , context );
1067
1080
}
1068
-
1081
+
1069
1082
/**
1070
1083
* Perform a HTTP PATCH request, without any parameters.
1071
1084
*
@@ -1101,20 +1114,19 @@ public RequestHandle patch(String url, RequestParams params, ResponseHandlerInte
1101
1114
public RequestHandle patch (Context context , String url , RequestParams params , ResponseHandlerInterface responseHandler ) {
1102
1115
return patch (context , url , paramsToEntity (params , responseHandler ), null , responseHandler );
1103
1116
}
1104
-
1117
+
1105
1118
/**
1106
1119
* Perform a HTTP PATCH request and track the Android Context which initiated the request.
1107
1120
*
1108
1121
* @param context the Android Context which initiated the request.
1109
1122
* @param url the URL to send the request to.
1110
- * @param params additional PUT parameters or files to send with the request.
1111
1123
* @param responseHandler the response handler instance that should handle the response.
1112
1124
* @return RequestHandle of future request process
1113
1125
*/
1114
1126
public RequestHandle patch (Context context , String url , HttpEntity entity , String contentType , ResponseHandlerInterface responseHandler ) {
1115
1127
return sendRequest (httpClient , httpContext , addEntityToRequestBase (new HttpPatch (URI .create (url ).normalize ()), entity ), contentType , responseHandler , context );
1116
1128
}
1117
-
1129
+
1118
1130
/**
1119
1131
* Perform a HTTP PATCH request and track the Android Context which initiated the request. And set
1120
1132
* one-time headers for the request
@@ -1131,11 +1143,11 @@ public RequestHandle patch(Context context, String url, HttpEntity entity, Strin
1131
1143
* @return RequestHandle of future request process
1132
1144
*/
1133
1145
public RequestHandle patch (Context context , String url , Header [] headers , HttpEntity entity , String contentType , ResponseHandlerInterface responseHandler ) {
1134
- HttpEntityEnclosingRequestBase request = addEntityToRequestBase (new HttpPatch (URI .create (url ).normalize ()), entity );
1135
- if (headers != null ) request .setHeaders (headers );
1136
- return sendRequest (httpClient , httpContext , request , contentType , responseHandler , context );
1146
+ HttpEntityEnclosingRequestBase request = addEntityToRequestBase (new HttpPatch (URI .create (url ).normalize ()), entity );
1147
+ if (headers != null ) request .setHeaders (headers );
1148
+ return sendRequest (httpClient , httpContext , request , contentType , responseHandler , context );
1137
1149
}
1138
-
1150
+
1139
1151
// [-] HTTP PUT
1140
1152
// [+] HTTP DELETE
1141
1153
0 commit comments