Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

issue #6 fix - canceling requests #28

Merged
merged 1 commit into from

3 participants

@felipesabino

Regarding issue #6 - canceling requests
#6

Added xpapazaf code to check for thread interruption at the request class

@loopj loopj merged commit c774527 into loopj:master
@scottanderson

I don't think DefaultHttpClient is even interruptable, is it? It may make more sense to support a cancel mechanism through the API. One of the things I've noticed is that, if a context is finishing, the response is posted to the dead thread anyway, since there's no isFinishing() check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 6 deletions.
  1. +12 −6 src/com/loopj/android/http/AsyncHttpRequest.java
View
18 src/com/loopj/android/http/AsyncHttpRequest.java
@@ -59,12 +59,18 @@ public void run() {
}
}
}
-
+
private void makeRequest() throws IOException {
- HttpResponse response = client.execute(request, context);
- if(responseHandler != null) {
- responseHandler.sendResponseMessage(response);
- }
+ if(!Thread.currentThread().isInterrupted()) {
+ HttpResponse response = client.execute(request, context);
+ if(!Thread.currentThread().isInterrupted()) {
+ if(responseHandler != null) {
+ responseHandler.sendResponseMessage(response);
+ }
+ } else{
+ //TODO: should raise InterruptedException? this block is reached whenever the request is cancelled before its response is received
+ }
+ }
}
private void makeRequestWithRetries() throws ConnectException {
@@ -86,7 +92,7 @@ private void makeRequestWithRetries() throws ConnectException {
// http://code.google.com/p/android/issues/detail?id=5255
cause = new IOException("NPE in HttpClient" + e.getMessage());
retry = retryHandler.retryRequest(cause, ++executionCount, context);
- }
+ }
}
// no retries left, crap out with exception
Something went wrong with that request. Please try again.