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();
|
final int statusCode = response.getCode();
|
||||||
|
|
||||||
|
state.currentRequest = null;
|
||||||
switch (statusCode) {
|
switch (statusCode) {
|
||||||
case HttpStatus.SC_MOVED_PERMANENTLY:
|
case HttpStatus.SC_MOVED_PERMANENTLY:
|
||||||
case HttpStatus.SC_MOVED_TEMPORARILY:
|
case HttpStatus.SC_MOVED_TEMPORARILY:
|
||||||
case HttpStatus.SC_SEE_OTHER:
|
case HttpStatus.SC_SEE_OTHER:
|
||||||
if (!Methods.isSafe(request.getMethod())) {
|
if (!Methods.isSafe(request.getMethod())) {
|
||||||
final HttpRequest httpGet = new BasicHttpRequest(Methods.GET, redirectUri);
|
state.currentRequest = new BasicHttpRequest(Methods.GET, redirectUri);
|
||||||
httpGet.setHeaders(scope.originalRequest.getHeaders());
|
|
||||||
state.currentRequest = httpGet;
|
|
||||||
state.currentEntityProducer = null;
|
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);
|
final HttpHost newTarget = URIUtils.extractHost(redirectUri);
|
||||||
if (newTarget == null) {
|
if (newTarget == null) {
|
||||||
throw new ProtocolException("Redirect URI does not specify a valid host name: " + redirectUri);
|
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_MOVED_TEMPORARILY:
|
||||||
case HttpStatus.SC_SEE_OTHER:
|
case HttpStatus.SC_SEE_OTHER:
|
||||||
if (!Methods.isSafe(request.getMethod())) {
|
if (!Methods.isSafe(request.getMethod())) {
|
||||||
final HttpGet httpGet = new HttpGet(redirectUri);
|
redirect = new HttpGet(redirectUri);
|
||||||
httpGet.setHeaders(originalRequest.getHeaders());
|
|
||||||
redirect = httpGet;
|
|
||||||
} else {
|
|
||||||
redirect = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (redirect == null) {
|
if (redirect == null) {
|
||||||
redirect = new BasicClassicHttpRequest(originalRequest.getMethod(), redirectUri);
|
redirect = new BasicClassicHttpRequest(originalRequest.getMethod(), redirectUri);
|
||||||
redirect.setEntity(originalRequest.getEntity());
|
redirect.setEntity(originalRequest.getEntity());
|
||||||
}
|
}
|
||||||
|
redirect.setHeaders(originalRequest.getHeaders());
|
||||||
|
|
||||||
final HttpHost newTarget = URIUtils.extractHost(redirectUri);
|
final HttpHost newTarget = URIUtils.extractHost(redirectUri);
|
||||||
if (newTarget == null) {
|
if (newTarget == null) {
|
||||||
|
|
Loading…
Reference in New Issue