Skip to content

Commit ded7e80

Browse files
committed
update pull request android-async-http#170 add response headers from rustybox/response-headers to fix merge conflicts
1 parent 874c175 commit ded7e80

File tree

2 files changed

+59
-24
lines changed

2 files changed

+59
-24
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.os.Handler;
2222
import android.os.Looper;
2323
import android.os.Message;
24+
import org.apache.http.Header;
2425
import org.apache.http.HttpEntity;
2526
import org.apache.http.HttpResponse;
2627
import org.apache.http.StatusLine;
@@ -111,9 +112,20 @@ public void onSuccess(String content) {}
111112
/**
112113
* Fired when a request returns successfully, override to handle in your own code
113114
* @param statusCode the status code of the response
115+
* @param headers the headers of the HTTP response
114116
* @param content the body of the HTTP response from the server
115117
*/
116-
public void onSuccess(int statusCode, String content) {
118+
public void onSuccess(int statusCode, Header[] headers, String content) {
119+
onSuccess(statusCode, content);
120+
}
121+
122+
/**
123+
* Fired when a request returns successfully, override to handle in your own code
124+
* @param statusCode the status code of the response
125+
* @param content the body of the HTTP response from the server
126+
*/
127+
public void onSuccess(int statusCode, String content)
128+
{
117129
onSuccess(content);
118130
}
119131

@@ -139,8 +151,8 @@ public void onFailure(Throwable error, String content) {
139151
// Pre-processing of messages (executes in background threadpool thread)
140152
//
141153

142-
protected void sendSuccessMessage(int statusCode, String responseBody) {
143-
sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[]{new Integer(statusCode), responseBody}));
154+
protected void sendSuccessMessage(int statusCode, Header[] headers, String responseBody) {
155+
sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[]{new Integer(statusCode), headers, responseBody}));
144156
}
145157

146158
protected void sendFailureMessage(Throwable e, String responseBody) {
@@ -164,8 +176,8 @@ protected void sendFinishMessage() {
164176
// Pre-processing of messages (in original calling thread, typically the UI thread)
165177
//
166178

167-
protected void handleSuccessMessage(int statusCode, String responseBody) {
168-
onSuccess(statusCode, responseBody);
179+
protected void handleSuccessMessage(int statusCode, Header[] headers, String responseBody) {
180+
onSuccess(statusCode, headers, responseBody);
169181
}
170182

171183
protected void handleFailureMessage(Throwable e, String responseBody) {
@@ -181,7 +193,7 @@ protected void handleMessage(Message msg) {
181193
switch(msg.what) {
182194
case SUCCESS_MESSAGE:
183195
response = (Object[])msg.obj;
184-
handleSuccessMessage(((Integer) response[0]).intValue(), (String) response[1]);
196+
handleSuccessMessage(((Integer) response[0]).intValue(), (Header[]) response[1], (String) response[2]);
185197
break;
186198
case FAILURE_MESSAGE:
187199
response = (Object[])msg.obj;
@@ -234,7 +246,7 @@ void sendResponseMessage(HttpResponse response) {
234246
if(status.getStatusCode() >= 300) {
235247
sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
236248
} else {
237-
sendSuccessMessage(status.getStatusCode(), responseBody);
249+
sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
238250
}
239251
}
240-
}
252+
}

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

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.json.JSONException;
2424
import org.json.JSONObject;
2525
import org.json.JSONTokener;
26-
26+
import org.apache.http.Header;
2727
import android.os.Message;
2828

2929
/**
@@ -62,6 +62,18 @@ public void onSuccess(JSONObject response) {}
6262
*/
6363
public void onSuccess(JSONArray response) {}
6464

65+
/**
66+
* Fired when a request returns successfully and contains a json object
67+
* at the base of the response string. Override to handle in your
68+
* own code.
69+
* @param statusCode the status code of the response
70+
* @param headers the headers of the HTTP response
71+
* @param response the parsed json object found in the server response (if any)
72+
*/
73+
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
74+
onSuccess(statusCode, response);
75+
}
76+
6577
/**
6678
* Fired when a request returns successfully and contains a json object
6779
* at the base of the response string. Override to handle in your
@@ -73,6 +85,17 @@ public void onSuccess(int statusCode, JSONObject response) {
7385
onSuccess(response);
7486
}
7587

88+
/**
89+
* Fired when a request returns successfully and contains a json array
90+
* at the base of the response string. Override to handle in your
91+
* own code.
92+
* @param statusCode the status code of the response
93+
* @param headers the headers of the HTTP response
94+
* @param response the parsed json array found in the server response (if any)
95+
*/
96+
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
97+
onSuccess(statusCode, response);
98+
}
7699

77100
/**
78101
* Fired when a request returns successfully and contains a json array
@@ -81,7 +104,7 @@ public void onSuccess(int statusCode, JSONObject response) {
81104
* @param statusCode the status code of the response
82105
* @param response the parsed json array found in the server response (if any)
83106
*/
84-
public void onSuccess(int statusCode, JSONArray response) {
107+
public void onSuccess(int statusCode, JSONArray response) {
85108
onSuccess(response);
86109
}
87110

@@ -94,16 +117,16 @@ public void onFailure(Throwable e, JSONArray errorResponse) {}
94117
//
95118

96119
@Override
97-
protected void sendSuccessMessage(int statusCode, String responseBody) {
98-
if (statusCode != HttpStatus.SC_NO_CONTENT){
99-
try {
100-
Object jsonResponse = parseResponse(responseBody);
101-
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, jsonResponse}));
102-
} catch(JSONException e) {
103-
sendFailureMessage(e, responseBody);
104-
}
105-
}else{
106-
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, new JSONObject()}));
120+
protected void sendSuccessMessage(int statusCode, Header[] headers, String responseBody) {
121+
if (statusCode != HttpStatus.SC_NO_CONTENT){
122+
try {
123+
Object jsonResponse = parseResponse(responseBody);
124+
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, headers, jsonResponse}));
125+
} catch(JSONException e) {
126+
sendFailureMessage(e, responseBody);
127+
}
128+
} else {
129+
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, new JSONObject()}));
107130
}
108131
}
109132

@@ -117,18 +140,18 @@ protected void handleMessage(Message msg) {
117140
switch(msg.what){
118141
case SUCCESS_JSON_MESSAGE:
119142
Object[] response = (Object[]) msg.obj;
120-
handleSuccessJsonMessage(((Integer) response[0]).intValue(), response[1]);
143+
handleSuccessJsonMessage(((Integer) response[0]).intValue(),(Header[]) response[1] ,response[2]);
121144
break;
122145
default:
123146
super.handleMessage(msg);
124147
}
125148
}
126149

127-
protected void handleSuccessJsonMessage(int statusCode, Object jsonResponse) {
150+
protected void handleSuccessJsonMessage(int statusCode,Header[] headers, Object jsonResponse) {
128151
if(jsonResponse instanceof JSONObject) {
129-
onSuccess(statusCode, (JSONObject)jsonResponse);
152+
onSuccess(statusCode, headers, (JSONObject)jsonResponse);
130153
} else if(jsonResponse instanceof JSONArray) {
131-
onSuccess(statusCode, (JSONArray)jsonResponse);
154+
onSuccess(statusCode, headers, (JSONArray)jsonResponse);
132155
} else {
133156
onFailure(new JSONException("Unexpected type " + jsonResponse.getClass().getName()), (JSONObject)null);
134157
}

0 commit comments

Comments
 (0)