Skip to content

Commit 3a02c63

Browse files
p-m-jjamur2
authored andcommitted
Added headers array to onSuccess
1 parent 65dc6f2 commit 3a02c63

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

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

Lines changed: 8 additions & 7 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;
@@ -113,7 +114,7 @@ public void onSuccess(String content) {}
113114
* @param statusCode the status code of the response
114115
* @param content the body of the HTTP response from the server
115116
*/
116-
public void onSuccess(int statusCode, String content) {
117+
public void onSuccess(int statusCode,Header[] headers,String content) {
117118
onSuccess(content);
118119
}
119120

@@ -139,8 +140,8 @@ public void onFailure(Throwable error, String content) {
139140
// Pre-processing of messages (executes in background threadpool thread)
140141
//
141142

142-
protected void sendSuccessMessage(int statusCode, String responseBody) {
143-
sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[]{new Integer(statusCode), responseBody}));
143+
protected void sendSuccessMessage(int statusCode, Header[] headers, String responseBody) {
144+
sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[]{new Integer(statusCode),headers, responseBody}));
144145
}
145146

146147
protected void sendFailureMessage(Throwable e, String responseBody) {
@@ -164,8 +165,8 @@ protected void sendFinishMessage() {
164165
// Pre-processing of messages (in original calling thread, typically the UI thread)
165166
//
166167

167-
protected void handleSuccessMessage(int statusCode, String responseBody) {
168-
onSuccess(statusCode, responseBody);
168+
protected void handleSuccessMessage(int statusCode, Header[] headers, String responseBody) {
169+
onSuccess(statusCode, headers, responseBody);
169170
}
170171

171172
protected void handleFailureMessage(Throwable e, String responseBody) {
@@ -181,7 +182,7 @@ protected void handleMessage(Message msg) {
181182
switch(msg.what) {
182183
case SUCCESS_MESSAGE:
183184
response = (Object[])msg.obj;
184-
handleSuccessMessage(((Integer) response[0]).intValue(), (String) response[1]);
185+
handleSuccessMessage(((Integer) response[0]).intValue(),(Header[]) response[1], (String) response[2]);
185186
break;
186187
case FAILURE_MESSAGE:
187188
response = (Object[])msg.obj;
@@ -234,7 +235,7 @@ void sendResponseMessage(HttpResponse response) {
234235
if(status.getStatusCode() >= 300) {
235236
sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
236237
} else {
237-
sendSuccessMessage(status.getStatusCode(), responseBody);
238+
sendSuccessMessage(status.getStatusCode(),response.getAllHeaders(), responseBody);
238239
}
239240
}
240241
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.json.JSONException;
2323
import org.json.JSONObject;
2424
import org.json.JSONTokener;
25-
25+
import org.apache.http.Header;
2626
import android.os.Message;
2727

2828
/**
@@ -68,7 +68,7 @@ public void onSuccess(JSONArray response) {}
6868
* @param statusCode the status code of the response
6969
* @param response the parsed json object found in the server response (if any)
7070
*/
71-
public void onSuccess(int statusCode, JSONObject response) {
71+
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
7272
onSuccess(response);
7373
}
7474

@@ -80,7 +80,7 @@ public void onSuccess(int statusCode, JSONObject response) {
8080
* @param statusCode the status code of the response
8181
* @param response the parsed json array found in the server response (if any)
8282
*/
83-
public void onSuccess(int statusCode, JSONArray response) {
83+
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
8484
onSuccess(response);
8585
}
8686

@@ -93,10 +93,10 @@ public void onFailure(Throwable e, JSONArray errorResponse) {}
9393
//
9494

9595
@Override
96-
protected void sendSuccessMessage(int statusCode, String responseBody) {
96+
protected void sendSuccessMessage(int statusCode, Header[] headers, String responseBody) {
9797
try {
9898
Object jsonResponse = parseResponse(responseBody);
99-
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, jsonResponse}));
99+
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, headers, jsonResponse}));
100100
} catch(JSONException e) {
101101
sendFailureMessage(e, responseBody);
102102
}
@@ -112,18 +112,18 @@ protected void handleMessage(Message msg) {
112112
switch(msg.what){
113113
case SUCCESS_JSON_MESSAGE:
114114
Object[] response = (Object[]) msg.obj;
115-
handleSuccessJsonMessage(((Integer) response[0]).intValue(), response[1]);
115+
handleSuccessJsonMessage(((Integer) response[0]).intValue(),(Header[]) response[1] ,response[2]);
116116
break;
117117
default:
118118
super.handleMessage(msg);
119119
}
120120
}
121121

122-
protected void handleSuccessJsonMessage(int statusCode, Object jsonResponse) {
122+
protected void handleSuccessJsonMessage(int statusCode,Header[] headers, Object jsonResponse) {
123123
if(jsonResponse instanceof JSONObject) {
124-
onSuccess(statusCode, (JSONObject)jsonResponse);
124+
onSuccess(statusCode, headers, (JSONObject)jsonResponse);
125125
} else if(jsonResponse instanceof JSONArray) {
126-
onSuccess(statusCode, (JSONArray)jsonResponse);
126+
onSuccess(statusCode, headers, (JSONArray)jsonResponse);
127127
} else {
128128
onFailure(new JSONException("Unexpected type " + jsonResponse.getClass().getName()), (JSONObject)null);
129129
}

0 commit comments

Comments
 (0)