From d6216b4257ea1525580e5c5f20cfcb6dd3813bfb Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Wed, 28 Aug 2013 17:49:46 +0000 Subject: [PATCH] HTTPCLIENT-1393: original request headers do not get copied over in case of multiple redirects git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1518298 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/http/impl/execchain/RedirectExec.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 954eacf82..5740a616d 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 @@ -116,12 +116,16 @@ public class RedirectExec implements ClientExecChain { } redirectCount++; - final HttpRequest redirect = this.redirectStrategy.getRedirect(currentRequest, response, context); - final HttpRequest original = currentRequest.getOriginal(); + final HttpRequest redirect = this.redirectStrategy.getRedirect( + currentRequest, response, context); + if (!redirect.headerIterator().hasNext()) { + final HttpRequest original = request.getOriginal(); + redirect.setHeaders(original.getAllHeaders()); + } currentRequest = HttpRequestWrapper.wrap(redirect); - currentRequest.setHeaders(original.getAllHeaders()); - if (original instanceof HttpEntityEnclosingRequest) { - Proxies.enhanceEntity((HttpEntityEnclosingRequest) request); + + if (currentRequest instanceof HttpEntityEnclosingRequest) { + Proxies.enhanceEntity((HttpEntityEnclosingRequest) currentRequest); } final URI uri = currentRequest.getURI();