Skip to content

Commit e6d72f4

Browse files
committed
Throwing malformed URL fixes android-async-http#115, Throwing Interrupted exception fixes android-async-http#323
1 parent 8760193 commit e6d72f4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.io.IOException;
3030
import java.net.ConnectException;
31+
import java.net.MalformedURLException;
3132
import java.net.SocketException;
3233
import java.net.SocketTimeoutException;
3334
import java.net.UnknownHostException;
@@ -74,16 +75,19 @@ public void run() {
7475
}
7576
}
7677

77-
private void makeRequest() throws IOException {
78+
private void makeRequest() throws IOException, InterruptedException {
7879
if (!Thread.currentThread().isInterrupted()) {
7980
try {
81+
// Fixes #115
82+
if (request.getURI().getScheme() == null)
83+
throw new MalformedURLException("No valid URI scheme was provided");
8084
HttpResponse response = client.execute(request, context);
8185
if (!Thread.currentThread().isInterrupted()) {
8286
if (responseHandler != null) {
8387
responseHandler.sendResponseMessage(response);
8488
}
8589
} else {
86-
//TODO: should raise InterruptedException? this block is reached whenever the request is cancelled before its response is received
90+
throw new InterruptedException("makeRequest was interrupted");
8791
}
8892
} catch (IOException e) {
8993
if (!Thread.currentThread().isInterrupted()) {
@@ -104,7 +108,7 @@ private void makeRequestWithRetries() throws ConnectException {
104108
makeRequest();
105109
return;
106110
} catch (ClientProtocolException e) {
107-
if(responseHandler != null) {
111+
if (responseHandler != null) {
108112
responseHandler.sendFailureMessage(e, "cannot repeat the request");
109113
}
110114
return;
@@ -137,6 +141,9 @@ private void makeRequestWithRetries() throws ConnectException {
137141
// http://code.google.com/p/android/issues/detail?id=5255
138142
cause = new IOException("NPE in HttpClient" + e.getMessage());
139143
retry = retryHandler.retryRequest(cause, ++executionCount, context);
144+
} catch (InterruptedException e) {
145+
cause = new IOException("Request was interrupted while executing");
146+
retry = retryHandler.retryRequest(cause, ++executionCount, context);
140147
}
141148
}
142149

0 commit comments

Comments
 (0)