diff options
Diffstat (limited to 'AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java')
-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); |