Skip to content

Commit 5f47d1a

Browse files
committed
1 parent c7231d8 commit 5f47d1a

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

library/src/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.apache.http.conn.ssl.SSLSocketFactory;
4949
import org.apache.http.entity.HttpEntityWrapper;
5050
import org.apache.http.impl.client.DefaultHttpClient;
51+
import org.apache.http.impl.client.DefaultRedirectHandler;
5152
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
5253
import org.apache.http.params.BasicHttpParams;
5354
import org.apache.http.params.HttpConnectionParams;
@@ -92,7 +93,8 @@
9293
*/
9394
public class AsyncHttpClient {
9495
// 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";
9698

9799
private static final int DEFAULT_MAX_CONNECTIONS = 10;
98100
private static final int DEFAULT_SOCKET_TIMEOUT = 10 * 1000;
@@ -216,6 +218,21 @@ public void setThreadPool(ThreadPoolExecutor threadPool) {
216218
this.threadPool = threadPool;
217219
}
218220

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+
219236
/**
220237
* Sets the User-Agent header to be sent with each request. By default,
221238
* "Android Asynchronous Http Client/VERSION (http://loopj.com/android-async-http/)" is used.
@@ -314,7 +331,8 @@ public void cancelRequests(Context context, boolean mayInterruptIfRunning) {
314331

315332
/**
316333
* 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.
318336
* @param responseHandler the response handler instance that should handle the response.
319337
*/
320338
public void head(String url, AsyncHttpResponseHandler responseHandler) {
@@ -323,8 +341,9 @@ public void head(String url, AsyncHttpResponseHandler responseHandler) {
323341

324342
/**
325343
* 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.
328347
* @param responseHandler the response handler instance that should handle the response.
329348
*/
330349
public void head(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
@@ -333,8 +352,9 @@ public void head(String url, RequestParams params, AsyncHttpResponseHandler resp
333352

334353
/**
335354
* 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.
338358
* @param responseHandler the response handler instance that should handle the response.
339359
*/
340360
public void head(Context context, String url, AsyncHttpResponseHandler responseHandler) {
@@ -343,9 +363,10 @@ public void head(Context context, String url, AsyncHttpResponseHandler responseH
343363

344364
/**
345365
* 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.
349370
* @param responseHandler the response handler instance that should handle the response.
350371
*/
351372
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
356377
* Perform a HTTP HEAD request and track the Android Context which initiated
357378
* the request with customized headers
358379
*
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.
363384
* @param responseHandler the response handler instance that should handle
364-
* the response.
385+
* the response.
365386
*/
366387
public void head(Context context, String url, Header[] headers, RequestParams params, AsyncHttpResponseHandler responseHandler) {
367388
HttpUriRequest request = new HttpHead(getUrlWithQueryString(url, params));
368-
if(headers != null) request.setHeaders(headers);
389+
if (headers != null) request.setHeaders(headers);
369390
sendRequest(httpClient, httpContext, request, null, responseHandler,
370391
context);
371392
}

0 commit comments

Comments
 (0)