48
48
import org .apache .http .conn .ssl .SSLSocketFactory ;
49
49
import org .apache .http .entity .HttpEntityWrapper ;
50
50
import org .apache .http .impl .client .DefaultHttpClient ;
51
+ import org .apache .http .impl .client .DefaultRedirectHandler ;
51
52
import org .apache .http .impl .conn .tsccm .ThreadSafeClientConnManager ;
52
53
import org .apache .http .params .BasicHttpParams ;
53
54
import org .apache .http .params .HttpConnectionParams ;
92
93
*/
93
94
public class AsyncHttpClient {
94
95
// This property won't be available soon, don't use it
95
- @ Deprecated private static final String VERSION = "1.4.4" ;
96
+ @ Deprecated
97
+ private static final String VERSION = "1.4.4" ;
96
98
97
99
private static final int DEFAULT_MAX_CONNECTIONS = 10 ;
98
100
private static final int DEFAULT_SOCKET_TIMEOUT = 10 * 1000 ;
@@ -216,6 +218,21 @@ public void setThreadPool(ThreadPoolExecutor threadPool) {
216
218
this .threadPool = threadPool ;
217
219
}
218
220
221
+ /**
222
+ * Simple interface method, to enable or disable redirects.
223
+ * If you set manually RedirectHandler on underlying HttpClient, effects of this method will be canceled.
224
+ *
225
+ * @param enableRedirects boolean
226
+ */
227
+ public void setEnableRedirects (final boolean enableRedirects ) {
228
+ httpClient .setRedirectHandler (new DefaultRedirectHandler () {
229
+ @ Override
230
+ public boolean isRedirectRequested (HttpResponse response , HttpContext context ) {
231
+ return enableRedirects ;
232
+ }
233
+ });
234
+ }
235
+
219
236
/**
220
237
* Sets the User-Agent header to be sent with each request. By default,
221
238
* "Android Asynchronous Http Client/VERSION (http://loopj.com/android-async-http/)" is used.
@@ -314,7 +331,8 @@ public void cancelRequests(Context context, boolean mayInterruptIfRunning) {
314
331
315
332
/**
316
333
* Perform a HTTP HEAD request, without any parameters.
317
- * @param url the URL to send the request to.
334
+ *
335
+ * @param url the URL to send the request to.
318
336
* @param responseHandler the response handler instance that should handle the response.
319
337
*/
320
338
public void head (String url , AsyncHttpResponseHandler responseHandler ) {
@@ -323,8 +341,9 @@ public void head(String url, AsyncHttpResponseHandler responseHandler) {
323
341
324
342
/**
325
343
* Perform a HTTP HEAD request with parameters.
326
- * @param url the URL to send the request to.
327
- * @param params additional HEAD parameters to send with the request.
344
+ *
345
+ * @param url the URL to send the request to.
346
+ * @param params additional HEAD parameters to send with the request.
328
347
* @param responseHandler the response handler instance that should handle the response.
329
348
*/
330
349
public void head (String url , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
@@ -333,8 +352,9 @@ public void head(String url, RequestParams params, AsyncHttpResponseHandler resp
333
352
334
353
/**
335
354
* Perform a HTTP HEAD request without any parameters and track the Android Context which initiated the request.
336
- * @param context the Android Context which initiated the request.
337
- * @param url the URL to send the request to.
355
+ *
356
+ * @param context the Android Context which initiated the request.
357
+ * @param url the URL to send the request to.
338
358
* @param responseHandler the response handler instance that should handle the response.
339
359
*/
340
360
public void head (Context context , String url , AsyncHttpResponseHandler responseHandler ) {
@@ -343,9 +363,10 @@ public void head(Context context, String url, AsyncHttpResponseHandler responseH
343
363
344
364
/**
345
365
* Perform a HTTP HEAD request and track the Android Context which initiated the request.
346
- * @param context the Android Context which initiated the request.
347
- * @param url the URL to send the request to.
348
- * @param params additional HEAD parameters to send with the request.
366
+ *
367
+ * @param context the Android Context which initiated the request.
368
+ * @param url the URL to send the request to.
369
+ * @param params additional HEAD parameters to send with the request.
349
370
* @param responseHandler the response handler instance that should handle the response.
350
371
*/
351
372
public void head (Context context , String url , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
@@ -356,16 +377,16 @@ public void head(Context context, String url, RequestParams params, AsyncHttpRes
356
377
* Perform a HTTP HEAD request and track the Android Context which initiated
357
378
* the request with customized headers
358
379
*
359
- * @param context Context to execute request against
360
- * @param url the URL to send the request to.
361
- * @param headers set headers only for this request
362
- * @param params additional HEAD parameters to send with the request.
380
+ * @param context Context to execute request against
381
+ * @param url the URL to send the request to.
382
+ * @param headers set headers only for this request
383
+ * @param params additional HEAD parameters to send with the request.
363
384
* @param responseHandler the response handler instance that should handle
364
- * the response.
385
+ * the response.
365
386
*/
366
387
public void head (Context context , String url , Header [] headers , RequestParams params , AsyncHttpResponseHandler responseHandler ) {
367
388
HttpUriRequest request = new HttpHead (getUrlWithQueryString (url , params ));
368
- if (headers != null ) request .setHeaders (headers );
389
+ if (headers != null ) request .setHeaders (headers );
369
390
sendRequest (httpClient , httpContext , request , null , responseHandler ,
370
391
context );
371
392
}
0 commit comments