Avoid duplicating existing headers when copying requests.

This commit is contained in:
Simone Bordet 2014-04-15 08:49:58 +02:00
parent e252b52eb3
commit d6e538a9d2
1 changed files with 14 additions and 11 deletions

View File

@ -391,26 +391,29 @@ public class HttpClient extends ContainerLifeCycle
.idleTimeout(oldRequest.getIdleTimeout(), TimeUnit.MILLISECONDS) .idleTimeout(oldRequest.getIdleTimeout(), TimeUnit.MILLISECONDS)
.timeout(oldRequest.getTimeout(), TimeUnit.MILLISECONDS) .timeout(oldRequest.getTimeout(), TimeUnit.MILLISECONDS)
.followRedirects(oldRequest.isFollowRedirects()); .followRedirects(oldRequest.isFollowRedirects());
for (HttpField header : oldRequest.getHeaders()) for (HttpField field : oldRequest.getHeaders())
{ {
// We have a new URI, so skip the host header if present HttpHeader header = field.getHeader();
if (HttpHeader.HOST == header.getHeader()) // We have a new URI, so skip the host header if present.
if (HttpHeader.HOST == header)
continue; continue;
// Remove expectation headers // Remove expectation headers.
if (HttpHeader.EXPECT == header.getHeader()) if (HttpHeader.EXPECT == header)
continue; continue;
// Remove cookies // Remove cookies.
if (HttpHeader.COOKIE == header.getHeader()) if (HttpHeader.COOKIE == header)
continue; continue;
// Remove authorization headers // Remove authorization headers.
if (HttpHeader.AUTHORIZATION == header.getHeader() || if (HttpHeader.AUTHORIZATION == header ||
HttpHeader.PROXY_AUTHORIZATION == header.getHeader()) HttpHeader.PROXY_AUTHORIZATION == header)
continue; continue;
newRequest.header(header.getName(), header.getValue()); String value = field.getValue();
if (!newRequest.getHeaders().contains(header, value))
newRequest.header(field.getName(), value);
} }
return newRequest; return newRequest;
} }