From 6fd73b5fb52b44ef7670765a35d88cbf939b36a5 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sun, 30 Aug 2015 16:34:38 +0000 Subject: [PATCH] HTTPCLIENT-1680: redirect of a POST request causes ClientProtocolException git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.5.x@1700136 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/execchain/RedirectExec.java | 4 ++-- .../http/impl/execchain/TestRedirectExec.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java b/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java index f9c1d795f..dcafdb55c 100644 --- a/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java +++ b/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java @@ -111,7 +111,7 @@ public class RedirectExec implements ClientExecChain { currentRoute, currentRequest, context, execAware); try { if (config.isRedirectsEnabled() && - this.redirectStrategy.isRedirected(currentRequest, response, context)) { + this.redirectStrategy.isRedirected(currentRequest.getOriginal(), response, context)) { if (redirectCount >= maxRedirects) { throw new RedirectException("Maximum redirects ("+ maxRedirects + ") exceeded"); @@ -119,7 +119,7 @@ public class RedirectExec implements ClientExecChain { redirectCount++; final HttpRequest redirect = this.redirectStrategy.getRedirect( - currentRequest, response, context); + currentRequest.getOriginal(), response, context); if (!redirect.headerIterator().hasNext()) { final HttpRequest original = request.getOriginal(); redirect.setHeaders(original.getAllHeaders()); diff --git a/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java b/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java index ed1546cb7..5621a3f2c 100644 --- a/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java +++ b/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java @@ -120,11 +120,11 @@ public class TestRedirectExec { Mockito.any(), Mockito.any())).thenReturn(response2); Mockito.when(redirectStrategy.isRedirected( - Mockito.same(request), + Mockito.same(get), Mockito.same(response1), Mockito.any())).thenReturn(Boolean.TRUE); Mockito.when(redirectStrategy.getRedirect( - Mockito.same(request), + Mockito.same(get), Mockito.same(response1), Mockito.any())).thenReturn(redirect); Mockito.when(httpRoutePlanner.determineRoute( @@ -216,11 +216,11 @@ public class TestRedirectExec { Mockito.any(), Mockito.any())).thenReturn(response2); Mockito.when(redirectStrategy.isRedirected( - Mockito.same(request), + Mockito.same(get), Mockito.same(response1), Mockito.any())).thenReturn(Boolean.TRUE); Mockito.when(redirectStrategy.getRedirect( - Mockito.same(request), + Mockito.same(get), Mockito.same(response1), Mockito.any())).thenReturn(redirect); Mockito.when(httpRoutePlanner.determineRoute( @@ -240,10 +240,10 @@ public class TestRedirectExec { final AuthState targetAuthState = new AuthState(); targetAuthState.setState(AuthProtocolState.SUCCESS); - targetAuthState.update(new BasicScheme(), new UsernamePasswordCredentials("user:pass")); + targetAuthState.update(new BasicScheme(), new UsernamePasswordCredentials("user", "pass")); final AuthState proxyAuthState = new AuthState(); proxyAuthState.setState(AuthProtocolState.SUCCESS); - proxyAuthState.update(new NTLMScheme(), new NTCredentials("user:pass")); + proxyAuthState.update(new NTLMScheme(), new NTCredentials("user", "pass", null, null)); context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, targetAuthState); context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState); @@ -261,11 +261,11 @@ public class TestRedirectExec { Mockito.any(), Mockito.any())).thenReturn(response2); Mockito.when(redirectStrategy.isRedirected( - Mockito.same(request), + Mockito.same(get), Mockito.same(response1), Mockito.any())).thenReturn(Boolean.TRUE); Mockito.when(redirectStrategy.getRedirect( - Mockito.same(request), + Mockito.same(get), Mockito.same(response1), Mockito.any())).thenReturn(redirect); Mockito.when(httpRoutePlanner.determineRoute( @@ -332,11 +332,11 @@ public class TestRedirectExec { Mockito.any(), Mockito.any())).thenReturn(response1); Mockito.when(redirectStrategy.isRedirected( - Mockito.same(request), + Mockito.same(get), Mockito.same(response1), Mockito.any())).thenReturn(Boolean.TRUE); Mockito.doThrow(new ProtocolException("Oppsie")).when(redirectStrategy).getRedirect( - Mockito.same(request), + Mockito.same(get), Mockito.same(response1), Mockito.any());