Skip to content

Commit a35e7b0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into response-headers
Conflicts: src/com/loopj/android/http/AsyncHttpResponseHandler.java
2 parents a5e55eb + c8cfff9 commit a35e7b0

9 files changed

+51
-29
lines changed

AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.loopj.android.http"
4-
android:versionName="1.4.1"
4+
android:versionName="1.4.3"
55
android:versionCode="1">
66
<application
77
android:name="android_async_http">

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
import org.apache.http.impl.client.DefaultHttpClient;
6161
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
6262
import org.apache.http.params.BasicHttpParams;
63-
import org.apache.http.params.HttpParams;
6463
import org.apache.http.params.HttpConnectionParams;
64+
import org.apache.http.params.HttpParams;
6565
import org.apache.http.params.HttpProtocolParams;
6666
import org.apache.http.protocol.BasicHttpContext;
6767
import org.apache.http.protocol.HttpContext;
@@ -90,7 +90,7 @@
9090
* </pre>
9191
*/
9292
public class AsyncHttpClient {
93-
private static final String VERSION = "1.4.1";
93+
private static final String VERSION = "1.4.3";
9494

9595
private static final int DEFAULT_MAX_CONNECTIONS = 10;
9696
private static final int DEFAULT_SOCKET_TIMEOUT = 10 * 1000;
@@ -135,6 +135,7 @@ public AsyncHttpClient() {
135135
httpContext = new SyncBasicHttpContext(new BasicHttpContext());
136136
httpClient = new DefaultHttpClient(cm, httpParams);
137137
httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
138+
@Override
138139
public void process(HttpRequest request, HttpContext context) {
139140
if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
140141
request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
@@ -146,6 +147,7 @@ public void process(HttpRequest request, HttpContext context) {
146147
});
147148

148149
httpClient.addResponseInterceptor(new HttpResponseInterceptor() {
150+
@Override
149151
public void process(HttpResponse response, HttpContext context) {
150152
final HttpEntity entity = response.getEntity();
151153
if (entity == null) {

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public AsyncHttpRequest(AbstractHttpClient client, HttpContext context, HttpUriR
4848
}
4949
}
5050

51+
@Override
5152
public void run() {
5253
try {
5354
if(responseHandler != null){
@@ -73,14 +74,20 @@ public void run() {
7374

7475
private void makeRequest() throws IOException {
7576
if(!Thread.currentThread().isInterrupted()) {
76-
HttpResponse response = client.execute(request, context);
77-
if(!Thread.currentThread().isInterrupted()) {
78-
if(responseHandler != null) {
79-
responseHandler.sendResponseMessage(response);
80-
}
81-
} else{
82-
//TODO: should raise InterruptedException? this block is reached whenever the request is cancelled before its response is received
83-
}
77+
try {
78+
HttpResponse response = client.execute(request, context);
79+
if(!Thread.currentThread().isInterrupted()) {
80+
if(responseHandler != null) {
81+
responseHandler.sendResponseMessage(response);
82+
}
83+
} else{
84+
//TODO: should raise InterruptedException? this block is reached whenever the request is cancelled before its response is received
85+
}
86+
} catch (IOException e) {
87+
if(!Thread.currentThread().isInterrupted()) {
88+
throw e;
89+
}
90+
}
8491
}
8592
}
8693

src/com/loopj/android/http/AsyncHttpResponseHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
import android.os.Looper;
2323
import android.os.Message;
2424
import org.apache.http.Header;
25+
import java.io.IOException;
2526
import org.apache.http.HttpEntity;
2627
import org.apache.http.HttpResponse;
2728
import org.apache.http.StatusLine;
2829
import org.apache.http.client.HttpResponseException;
2930
import org.apache.http.entity.BufferedHttpEntity;
3031
import org.apache.http.util.EntityUtils;
3132

32-
import java.io.IOException;
33+
import android.os.Handler;
34+
import android.os.Looper;
35+
import android.os.Message;
3336

3437
/**
3538
* Used to intercept and handle the responses from requests made using
@@ -81,6 +84,7 @@ public AsyncHttpResponseHandler() {
8184
// Set up a handler to post events back to the correct thread if possible
8285
if(Looper.myLooper() != null) {
8386
handler = new Handler(){
87+
@Override
8488
public void handleMessage(Message msg){
8589
AsyncHttpResponseHandler.this.handleMessage(msg);
8690
}
@@ -134,6 +138,7 @@ public void onSuccess(int statusCode, String content)
134138
* @param error the underlying cause of the failure
135139
* @deprecated use {@link #onFailure(Throwable, String)}
136140
*/
141+
@Deprecated
137142
public void onFailure(Throwable error) {}
138143

139144
/**

src/com/loopj/android/http/BinaryHttpResponseHandler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
package com.loopj.android.http;
2020

21-
import android.os.Message;
21+
import java.io.IOException;
22+
2223
import org.apache.http.Header;
2324
import org.apache.http.HttpEntity;
2425
import org.apache.http.HttpResponse;
@@ -27,7 +28,7 @@
2728
import org.apache.http.entity.BufferedHttpEntity;
2829
import org.apache.http.util.EntityUtils;
2930

30-
import java.io.IOException;
31+
import android.os.Message;
3132

3233
/**
3334
* Used to intercept and handle the responses from requests made using
@@ -102,6 +103,7 @@ public void onSuccess(int statusCode, byte[] binaryData) {
102103
* @param binaryData the response body, if any
103104
* @deprecated
104105
*/
106+
@Deprecated
105107
public void onFailure(Throwable error, byte[] binaryData) {
106108
// By default, call the deprecated onFailure(Throwable) for compatibility
107109
onFailure(error);
@@ -116,6 +118,7 @@ protected void sendSuccessMessage(int statusCode, byte[] responseBody) {
116118
sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[]{statusCode, responseBody}));
117119
}
118120

121+
@Override
119122
protected void sendFailureMessage(Throwable e, byte[] responseBody) {
120123
sendMessage(obtainMessage(FAILURE_MESSAGE, new Object[]{e, responseBody}));
121124
}
@@ -133,6 +136,7 @@ protected void handleFailureMessage(Throwable e, byte[] responseBody) {
133136
}
134137

135138
// Methods which emulate android's Handler and Message methods
139+
@Override
136140
protected void handleMessage(Message msg) {
137141
Object[] response;
138142
switch(msg.what) {
@@ -142,7 +146,7 @@ protected void handleMessage(Message msg) {
142146
break;
143147
case FAILURE_MESSAGE:
144148
response = (Object[])msg.obj;
145-
handleFailureMessage((Throwable)response[0], (byte[])response[1]);
149+
handleFailureMessage((Throwable)response[0], response[1].toString());
146150
break;
147151
default:
148152
super.handleMessage(msg);
@@ -151,6 +155,7 @@ protected void handleMessage(Message msg) {
151155
}
152156

153157
// Interface to AsyncHttpRequest
158+
@Override
154159
void sendResponseMessage(HttpResponse response) {
155160
StatusLine status = response.getStatusLine();
156161
Header[] contentTypeHeaders = response.getHeaders("Content-Type");

src/com/loopj/android/http/PersistentCookieStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public PersistentCookieStore(Context context) {
8080

8181
@Override
8282
public void addCookie(Cookie cookie) {
83-
String name = cookie.getName();
83+
String name = cookie.getName() + cookie.getDomain();
8484

8585
// Save cookie into local store, or remove if expired
8686
if(!cookie.isExpired(new Date())) {

src/com/loopj/android/http/RequestParams.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ public HttpEntity getEntity() {
236236
multipartEntity.addPart(entry.getKey(), entry.getValue());
237237
}
238238

239+
// Add dupe params
240+
for(ConcurrentHashMap.Entry<String, ArrayList<String>> entry : urlParamsWithArray.entrySet()) {
241+
ArrayList<String> values = entry.getValue();
242+
for (String value : values) {
243+
multipartEntity.addPart(entry.getKey(), value);
244+
}
245+
}
246+
239247
// Add file params
240248
int currentIndex = 0;
241249
int lastIndex = fileParams.entrySet().size() - 1;
@@ -252,14 +260,6 @@ public HttpEntity getEntity() {
252260
currentIndex++;
253261
}
254262

255-
// Add dupe params
256-
for(ConcurrentHashMap.Entry<String, ArrayList<String>> entry : urlParamsWithArray.entrySet()) {
257-
ArrayList<String> values = entry.getValue();
258-
for (String value : values) {
259-
multipartEntity.addPart(entry.getKey(), value);
260-
}
261-
}
262-
263263
entity = multipartEntity;
264264
} else {
265265
try {
@@ -318,4 +318,4 @@ public String getFileName() {
318318
}
319319
}
320320
}
321-
}
321+
}

src/com/loopj/android/http/RetryHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public RetryHandler(int maxRetries) {
6565
this.maxRetries = maxRetries;
6666
}
6767

68+
@Override
6869
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
6970
boolean retry = true;
7071

src/com/loopj/android/http/SyncHttpClient.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ public abstract class SyncHttpClient extends AsyncHttpClient {
1414
* the result back to this method. Therefore the result object has to be a
1515
* field to be accessible
1616
*/
17-
private String result;
18-
AsyncHttpResponseHandler responseHandler = new AsyncHttpResponseHandler() {
17+
protected String result;
18+
protected AsyncHttpResponseHandler responseHandler = new AsyncHttpResponseHandler() {
1919

20-
void sendResponseMessage(org.apache.http.HttpResponse response) {
20+
@Override
21+
void sendResponseMessage(org.apache.http.HttpResponse response) {
2122
responseCode = response.getStatusLine().getStatusCode();
2223
super.sendResponseMessage(response);
2324
};
@@ -51,7 +52,8 @@ public int getResponseCode() {
5152
}
5253

5354
// Private stuff
54-
protected void sendRequest(DefaultHttpClient client,
55+
@Override
56+
protected void sendRequest(DefaultHttpClient client,
5557
HttpContext httpContext, HttpUriRequest uriRequest,
5658
String contentType, AsyncHttpResponseHandler responseHandler,
5759
Context context) {

0 commit comments

Comments
 (0)