HTTPCLIENT-2040: Copy headers from the original request to the redirect request
This commit is contained in:
parent
b34007dffd
commit
a2ebb62881
|
@ -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:
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue