HTTPCLIENT-2051: corrected handling of 303 redirects
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java
index 03a770d..92081e9 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java
@@ -142,11 +142,16 @@
switch (statusCode) {
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_MOVED_TEMPORARILY:
- case HttpStatus.SC_SEE_OTHER:
if (Method.POST.isSame(request.getMethod())) {
state.currentRequest = new BasicHttpRequest(Method.GET, redirectUri);
state.currentEntityProducer = null;
}
+ break;
+ case HttpStatus.SC_SEE_OTHER:
+ if (!Method.GET.isSame(request.getMethod()) && !Method.HEAD.isSame(request.getMethod())) {
+ state.currentRequest = new BasicHttpRequest(Method.GET, redirectUri);
+ state.currentEntityProducer = null;
+ }
}
if (state.currentRequest == null) {
state.currentRequest = new BasicHttpRequest(request.getMethod(), redirectUri);
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java
index d6ec2f5..bf55aec 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java
@@ -145,10 +145,14 @@
switch (statusCode) {
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_MOVED_TEMPORARILY:
- case HttpStatus.SC_SEE_OTHER:
if (Method.POST.isSame(request.getMethod())) {
redirect = new HttpGet(redirectUri);
}
+ break;
+ case HttpStatus.SC_SEE_OTHER:
+ if (!Method.GET.isSame(request.getMethod()) && !Method.HEAD.isSame(request.getMethod())) {
+ redirect = new HttpGet(redirectUri);
+ }
}
if (redirect == null) {
redirect = new BasicClassicHttpRequest(originalRequest.getMethod(), redirectUri);