Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/com/loopj/android/http/AsyncHttpResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void onSuccess(String content) {}
* @param statusCode the status code of the response
* @param content the body of the HTTP response from the server
*/
public void onSuccess(int statusCode, String content) {
public void onSuccess(int statusCode,Header[] headers,String content) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustybox, I'm not a maintainer but I have some comments on this commit that I think might make it more likely to be merged in. If you like, I can make the changes and submit a separate pull request, as I'll probably make them anyway for my own use.

  1. To avoid breaking existing client code, it might be better to add this as another overload rather than changing the signature. e.g.

    public void onSuccess(int statusCode, String content) {
        onSuccess(content);
    }
    public void onSuccess(int statusCode, Header[] headers, String content) {
        onSuccess(statusCode, content);
    }
    
  2. The docstring should also be updated with the new parameter.

  3. The changed formatting in the parameter list is inconsistent with the rest of the library.

Same things with the JsonHttpResponseHandler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, Thanks for the response, I came to the same conclusions a while back and did those changes in https://github.com/rustybox/android-async-http/commit/78eee0d369f76ca9480c258292c1a959a4da648c.

Is there a way to update the pull request or do I need to do a new one (kind of new to the whole contributing thing)?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. It looks like this pull request is for a specific commit, not a branch, so you might have to create a new one and then close this one (leaving a comment pointing to the new one, e.g. "Reopened as #xx").

I suggest creating a new branch in your repository for this specific pull request (e.g. "response-headers") and then creating the new pull request from that. That way, if you need to make more changes they'll be automatically included. The pull request should look like "into loopj:master from rustybox:response-headers" instead of rustybox:d8f606c.

I've made the same mistake in the past; maybe someday github will let you rebase pull requests…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant, cheers for the help dude I'll get that sorted tomorrow morning (it's pretty late here).

Edit: Closed. reopened as #170

onSuccess(content);
}

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

protected void sendSuccessMessage(int statusCode, String responseBody) {
sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[]{new Integer(statusCode), responseBody}));
protected void sendSuccessMessage(int statusCode, Header[] headers, String responseBody) {
sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[]{new Integer(statusCode),headers, responseBody}));
}

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

protected void handleSuccessMessage(int statusCode, String responseBody) {
onSuccess(statusCode, responseBody);
protected void handleSuccessMessage(int statusCode, Header[] headers, String responseBody) {
onSuccess(statusCode, headers, responseBody);
}

protected void handleFailureMessage(Throwable e, String responseBody) {
Expand All @@ -181,7 +182,7 @@ protected void handleMessage(Message msg) {
switch(msg.what) {
case SUCCESS_MESSAGE:
response = (Object[])msg.obj;
handleSuccessMessage(((Integer) response[0]).intValue(), (String) response[1]);
handleSuccessMessage(((Integer) response[0]).intValue(),(Header[]) response[1], (String) response[2]);
break;
case FAILURE_MESSAGE:
response = (Object[])msg.obj;
Expand Down Expand Up @@ -234,7 +235,7 @@ void sendResponseMessage(HttpResponse response) {
if(status.getStatusCode() >= 300) {
sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
} else {
sendSuccessMessage(status.getStatusCode(), responseBody);
sendSuccessMessage(status.getStatusCode(),response.getAllHeaders(), responseBody);
}
}
}
18 changes: 9 additions & 9 deletions src/com/loopj/android/http/JsonHttpResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import org.apache.http.Header;
import android.os.Message;

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ public void onSuccess(JSONArray response) {}
* @param statusCode the status code of the response
* @param response the parsed json object found in the server response (if any)
*/
public void onSuccess(int statusCode, JSONObject response) {
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
onSuccess(response);
}

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

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

@Override
protected void sendSuccessMessage(int statusCode, String responseBody) {
protected void sendSuccessMessage(int statusCode, Header[] headers, String responseBody) {
try {
Object jsonResponse = parseResponse(responseBody);
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, jsonResponse}));
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, headers, jsonResponse}));
} catch(JSONException e) {
sendFailureMessage(e, responseBody);
}
Expand All @@ -112,18 +112,18 @@ protected void handleMessage(Message msg) {
switch(msg.what){
case SUCCESS_JSON_MESSAGE:
Object[] response = (Object[]) msg.obj;
handleSuccessJsonMessage(((Integer) response[0]).intValue(), response[1]);
handleSuccessJsonMessage(((Integer) response[0]).intValue(),(Header[]) response[1] ,response[2]);
break;
default:
super.handleMessage(msg);
}
}

protected void handleSuccessJsonMessage(int statusCode, Object jsonResponse) {
protected void handleSuccessJsonMessage(int statusCode,Header[] headers, Object jsonResponse) {
if(jsonResponse instanceof JSONObject) {
onSuccess(statusCode, (JSONObject)jsonResponse);
onSuccess(statusCode, headers, (JSONObject)jsonResponse);
} else if(jsonResponse instanceof JSONArray) {
onSuccess(statusCode, (JSONArray)jsonResponse);
onSuccess(statusCode, headers, (JSONArray)jsonResponse);
} else {
onFailure(new JSONException("Unexpected type " + jsonResponse.getClass().getName()), (JSONObject)null);
}
Expand Down