Index: main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java =================================================================== --- main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java (revision 1177034) +++ main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java (working copy) @@ -44,6 +44,7 @@ import org.apache.http.client.RedirectStrategy; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpHead; +import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.params.ClientPNames; import org.apache.http.client.utils.URIUtils; @@ -72,6 +73,15 @@ public static final String REDIRECT_LOCATIONS = "http.protocol.redirect-locations"; + /** + * Redirectable methods. + */ + private static final String[] REDIRECT_METHODS = new String[] { + HttpGet.METHOD_NAME, + HttpHead.METHOD_NAME + }; + + public DefaultRedirectStrategy() { super(); } @@ -92,12 +102,10 @@ Header locationHeader = response.getFirstHeader("location"); switch (statusCode) { case HttpStatus.SC_MOVED_TEMPORARILY: - return (method.equalsIgnoreCase(HttpGet.METHOD_NAME) - || method.equalsIgnoreCase(HttpHead.METHOD_NAME)) && locationHeader != null; + return isRedirectable(method) && locationHeader != null; case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_TEMPORARY_REDIRECT: - return method.equalsIgnoreCase(HttpGet.METHOD_NAME) - || method.equalsIgnoreCase(HttpHead.METHOD_NAME); + return isRedirectable(method); case HttpStatus.SC_SEE_OTHER: return true; default: @@ -197,6 +205,15 @@ throw new ProtocolException("Invalid redirect URI: " + location, ex); } } + + protected boolean isRedirectable(String method) { + for (String m: REDIRECT_METHODS) { + if (m.equalsIgnoreCase(method)) { + return true; + } + } + return false; + } public HttpUriRequest getRedirect( final HttpRequest request, Index: main/java/org/apache/http/impl/client/LaxRedirectStrategy.java =================================================================== --- main/java/org/apache/http/impl/client/LaxRedirectStrategy.java (revision 1177034) +++ main/java/org/apache/http/impl/client/LaxRedirectStrategy.java (working copy) @@ -27,17 +27,11 @@ package org.apache.http.impl.client; -import org.apache.http.Header; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.ProtocolException; import org.apache.http.annotation.Immutable; import org.apache.http.client.RedirectStrategy; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpHead; import org.apache.http.client.methods.HttpPost; -import org.apache.http.protocol.HttpContext; /** * Lax {@link RedirectStrategy} implementation that automatically redirects all HEAD, GET and POST @@ -58,36 +52,7 @@ HttpHead.METHOD_NAME }; - @Override - public boolean isRedirected( - final HttpRequest request, - final HttpResponse response, - final HttpContext context) throws ProtocolException { - if (request == null) { - throw new IllegalArgumentException("HTTP request may not be null"); - } - if (response == null) { - throw new IllegalArgumentException("HTTP response may not be null"); - } - - String method = request.getRequestLine().getMethod(); - - int status = response.getStatusLine().getStatusCode(); - switch (status) { - case HttpStatus.SC_MOVED_TEMPORARILY: - Header location = response.getFirstHeader("location"); - return isRedirectable(method) && location != null; - case HttpStatus.SC_MOVED_PERMANENTLY: - case HttpStatus.SC_TEMPORARY_REDIRECT: - return isRedirectable(method); - case HttpStatus.SC_SEE_OTHER: - return true; - default: - return false; - } - } - - private boolean isRedirectable(String method) { + protected boolean isRedirectable(String method) { for (String m: REDIRECT_METHODS) { if (m.equalsIgnoreCase(method)) { return true;