You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/12/20 09:49:13 UTC
[httpcomponents-client] branch HTTPCLIENT-2040 created (now fa1a8d2)
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a change to branch HTTPCLIENT-2040
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git.
at fa1a8d2 HTTPCLIENT-2040: Copy headers from the original request to the redirect request
This branch includes the following new commits:
new fa1a8d2 HTTPCLIENT-2040: Copy headers from the original request to the redirect request
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[httpcomponents-client] 01/01: HTTPCLIENT-2040: Copy headers from
the original request to the redirect request
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch HTTPCLIENT-2040
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit fa1a8d240bb3283cbbd1d7b12c0c868a67d3fa3a
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Dec 20 10:40:54 2019 +0100
HTTPCLIENT-2040: Copy headers from the original request to the redirect request
---
.../apache/hc/client5/http/impl/async/AsyncRedirectExec.java | 12 ++++++------
.../apache/hc/client5/http/impl/classic/RedirectExec.java | 7 ++-----
2 files changed, 8 insertions(+), 11 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 c8ad47d..53d5b7e 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
@@ -138,20 +138,20 @@ public final class AsyncRedirectExec implements AsyncExecChainHandler {
final int statusCode = response.getCode();
+ state.currentRequest = null;
switch (statusCode) {
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_SEE_OTHER:
if (!Methods.isSafe(request.getMethod())) {
- final HttpRequest httpGet = new BasicHttpRequest(Methods.GET, redirectUri);
- httpGet.setHeaders(scope.originalRequest.getHeaders());
- state.currentRequest = httpGet;
+ state.currentRequest = new BasicHttpRequest(Methods.GET, redirectUri);
state.currentEntityProducer = null;
- break;
}
- default:
- state.currentRequest = new BasicHttpRequest(request.getMethod(), redirectUri);
}
+ if (state.currentRequest == null) {
+ state.currentRequest = new BasicHttpRequest(request.getMethod(), redirectUri);
+ }
+ state.currentRequest.setHeaders(scope.originalRequest.getHeaders());
final HttpHost newTarget = URIUtils.extractHost(redirectUri);
if (newTarget == null) {
throw new ProtocolException("Redirect URI does not specify a valid host name: " + 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 025d9f2..d2503e6 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
@@ -147,17 +147,14 @@ public final class RedirectExec implements ExecChainHandler {
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_SEE_OTHER:
if (!Methods.isSafe(request.getMethod())) {
- final HttpGet httpGet = new HttpGet(redirectUri);
- httpGet.setHeaders(originalRequest.getHeaders());
- redirect = httpGet;
- } else {
- redirect = null;
+ redirect = new HttpGet(redirectUri);
}
}
if (redirect == null) {
redirect = new BasicClassicHttpRequest(originalRequest.getMethod(), redirectUri);
redirect.setEntity(originalRequest.getEntity());
}
+ redirect.setHeaders(originalRequest.getHeaders());
final HttpHost newTarget = URIUtils.extractHost(redirectUri);
if (newTarget == null) {