From e26d5376587a6c9873bd8d45a18b3d4d4ac10052 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 23 Apr 2020 17:14:56 +0200 Subject: [PATCH] HTTPCLIENT-2051: corrected handling of 303 redirects --- .../hc/client5/http/impl/async/AsyncRedirectExec.java | 7 ++++++- .../apache/hc/client5/http/impl/classic/RedirectExec.java | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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 03a770d28..92081e919 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 @@ public final class AsyncRedirectExec implements AsyncExecChainHandler { 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 d6ec2f5fa..bf55aec75 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 @@ public final class RedirectExec implements ExecChainHandler { 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);