diff options
author | glennporter-examtime <glenn.porter@examtime.com> | 2015-03-05 12:14:44 +0000 |
---|---|---|
committer | glennporter-examtime <glenn.porter@examtime.com> | 2015-03-05 12:14:44 +0000 |
commit | 6ae6e0c38b025fe87c3ace8599d92b055231b738 (patch) | |
tree | 86f62048747270c60aa0a3ea2f8148a4da41aec5 | |
parent | 17ddc21484f7461d901bc90a8f40a508243c9fe9 (diff) | |
download | AndroidAsync-6ae6e0c38b025fe87c3ace8599d92b055231b738.tar.gz AndroidAsync-6ae6e0c38b025fe87c3ace8599d92b055231b738.tar.bz2 AndroidAsync-6ae6e0c38b025fe87c3ace8599d92b055231b738.zip |
Redirected requests now keep the same request method, body and headers as the original one.
-rw-r--r-- | AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java b/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java index 6382494..f08d99a 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java @@ -27,6 +27,7 @@ import com.koushikdutta.async.parser.JSONObjectParser; import com.koushikdutta.async.parser.StringParser; import com.koushikdutta.async.stream.OutputStreamDataCallback; +import org.apache.http.NameValuePair; import org.json.JSONArray; import org.json.JSONObject; @@ -356,7 +357,7 @@ public class AsyncHttpClient { Headers headers = mHeaders; int responseCode = code(); if ((responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP || responseCode == 307) && request.getFollowRedirect()) { - String location = headers.get("Location"); + String location = headers.get("Location"); Uri redirect; try { redirect = Uri.parse(location); @@ -368,7 +369,7 @@ public class AsyncHttpClient { reportConnectedCompleted(cancel, e, this, request, callback); return; } - final String method = request.getMethod().equals(AsyncHttpHead.METHOD) ? AsyncHttpHead.METHOD : AsyncHttpGet.METHOD; + final String method = request.getMethod(); AsyncHttpRequest newReq = new AsyncHttpRequest(redirect, method); newReq.executionTime = request.executionTime; newReq.logLevel = request.logLevel; @@ -376,8 +377,16 @@ public class AsyncHttpClient { newReq.proxyHost = request.proxyHost; newReq.proxyPort = request.proxyPort; setupAndroidProxy(newReq); - copyHeader(request, newReq, "User-Agent"); - copyHeader(request, newReq, "Range"); + + // Copy all headers from the old request to the new one (except for "host" - + // keeping this in will make the redirect happen again! + for (NameValuePair entry : request.getHeaders().getMultiMap()) { + if (!entry.getName().toLowerCase().equals("host")) { + copyHeader(request, newReq, entry.getName()); + } + } + + newReq.setBody(request.getBody()); request.logi("Redirecting"); newReq.logi("Redirected"); execute(newReq, redirectCount + 1, cancel, callback); |