RFC 7231: removed restriction on the use of relative URIs in Location header
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1686699 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
93525ebb36
commit
777f6ead46
|
@ -48,7 +48,6 @@ public class RequestConfig implements Cloneable {
|
|||
private final InetAddress localAddress;
|
||||
private final String cookieSpec;
|
||||
private final boolean redirectsEnabled;
|
||||
private final boolean relativeRedirectsAllowed;
|
||||
private final boolean circularRedirectsAllowed;
|
||||
private final int maxRedirects;
|
||||
private final boolean authenticationEnabled;
|
||||
|
@ -89,7 +88,6 @@ public class RequestConfig implements Cloneable {
|
|||
this.localAddress = localAddress;
|
||||
this.cookieSpec = cookieSpec;
|
||||
this.redirectsEnabled = redirectsEnabled;
|
||||
this.relativeRedirectsAllowed = relativeRedirectsAllowed;
|
||||
this.circularRedirectsAllowed = circularRedirectsAllowed;
|
||||
this.maxRedirects = maxRedirects;
|
||||
this.authenticationEnabled = authenticationEnabled;
|
||||
|
@ -173,17 +171,6 @@ public class RequestConfig implements Cloneable {
|
|||
return redirectsEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether relative redirects should be rejected. HTTP specification
|
||||
* requires the location value be an absolute URI.
|
||||
* <p>
|
||||
* Default: {@code true}
|
||||
* </p>
|
||||
*/
|
||||
public boolean isRelativeRedirectsAllowed() {
|
||||
return relativeRedirectsAllowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether circular redirects (redirects to the same location) should
|
||||
* be allowed. The HTTP spec is not sufficiently clear whether circular redirects
|
||||
|
@ -312,7 +299,6 @@ public class RequestConfig implements Cloneable {
|
|||
builder.append(", localAddress=").append(localAddress);
|
||||
builder.append(", cookieSpec=").append(cookieSpec);
|
||||
builder.append(", redirectsEnabled=").append(redirectsEnabled);
|
||||
builder.append(", relativeRedirectsAllowed=").append(relativeRedirectsAllowed);
|
||||
builder.append(", maxRedirects=").append(maxRedirects);
|
||||
builder.append(", circularRedirectsAllowed=").append(circularRedirectsAllowed);
|
||||
builder.append(", authenticationEnabled=").append(authenticationEnabled);
|
||||
|
@ -337,7 +323,6 @@ public class RequestConfig implements Cloneable {
|
|||
.setLocalAddress(config.getLocalAddress())
|
||||
.setCookieSpec(config.getCookieSpec())
|
||||
.setRedirectsEnabled(config.isRedirectsEnabled())
|
||||
.setRelativeRedirectsAllowed(config.isRelativeRedirectsAllowed())
|
||||
.setCircularRedirectsAllowed(config.isCircularRedirectsAllowed())
|
||||
.setMaxRedirects(config.getMaxRedirects())
|
||||
.setAuthenticationEnabled(config.isAuthenticationEnabled())
|
||||
|
|
|
@ -123,16 +123,9 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
|
|||
final RequestConfig config = clientContext.getRequestConfig();
|
||||
|
||||
URI uri = createLocationURI(location);
|
||||
|
||||
// rfc2616 demands the location value be a complete URI
|
||||
// Location = "Location" ":" absoluteURI
|
||||
try {
|
||||
if (!uri.isAbsolute()) {
|
||||
if (!config.isRelativeRedirectsAllowed()) {
|
||||
throw new ProtocolException("Relative redirect location '"
|
||||
+ uri + "' not allowed");
|
||||
}
|
||||
// Adjust location URI
|
||||
// Resolve location URI
|
||||
final HttpHost target = clientContext.getTargetHost();
|
||||
Asserts.notNull(target, "Target host");
|
||||
final URI requestURI = new URI(request.getRequestLine().getUri());
|
||||
|
|
|
@ -51,7 +51,6 @@ public class TestRequestConfig {
|
|||
Assert.assertEquals(false, config.isExpectContinueEnabled());
|
||||
Assert.assertEquals(true, config.isAuthenticationEnabled());
|
||||
Assert.assertEquals(true, config.isRedirectsEnabled());
|
||||
Assert.assertEquals(true, config.isRelativeRedirectsAllowed());
|
||||
Assert.assertEquals(false, config.isCircularRedirectsAllowed());
|
||||
Assert.assertEquals(50, config.getMaxRedirects());
|
||||
Assert.assertEquals(null, config.getCookieSpec());
|
||||
|
@ -88,7 +87,6 @@ public class TestRequestConfig {
|
|||
Assert.assertEquals(true, config.isExpectContinueEnabled());
|
||||
Assert.assertEquals(false, config.isAuthenticationEnabled());
|
||||
Assert.assertEquals(false, config.isRedirectsEnabled());
|
||||
Assert.assertEquals(false, config.isRelativeRedirectsAllowed());
|
||||
Assert.assertEquals(true, config.isCircularRedirectsAllowed());
|
||||
Assert.assertEquals(100, config.getMaxRedirects());
|
||||
Assert.assertEquals(CookieSpecs.STANDARD, config.getCookieSpec());
|
||||
|
|
|
@ -240,21 +240,6 @@ public class TestDefaultRedirectStrategy {
|
|||
Assert.assertEquals(URI.create("http://localhost/morestuff"), uri);
|
||||
}
|
||||
|
||||
@Test(expected=ProtocolException.class)
|
||||
public void testGetLocationUriRelativeLocationNotAllowed() throws Exception {
|
||||
final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, new HttpHost("localhost"));
|
||||
final RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(false).build();
|
||||
context.setRequestConfig(config);
|
||||
|
||||
final HttpGet httpget = new HttpGet("http://localhost/");
|
||||
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
|
||||
response.addHeader("Location", "/stuff");
|
||||
redirectStrategy.getLocationURI(httpget, response, context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLocationUriAllowCircularRedirects() throws Exception {
|
||||
final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
|
||||
|
|
|
@ -615,23 +615,6 @@ public class TestRedirects extends LocalServerTestBase {
|
|||
Assert.assertEquals(host, target);
|
||||
}
|
||||
|
||||
@Test(expected=ClientProtocolException.class)
|
||||
public void testRejectRelativeRedirect() throws Exception {
|
||||
this.serverBootstrap.registerHandler("*", new RelativeRedirectService());
|
||||
|
||||
final HttpHost target = start();
|
||||
|
||||
final RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(false).build();
|
||||
final HttpGet httpget = new HttpGet("/oldlocation/");
|
||||
httpget.setConfig(config);
|
||||
try {
|
||||
this.httpclient.execute(target, httpget);
|
||||
} catch (final ClientProtocolException e) {
|
||||
Assert.assertTrue(e.getCause() instanceof ProtocolException);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=ClientProtocolException.class)
|
||||
public void testRejectBogusRedirectLocation() throws Exception {
|
||||
this.serverBootstrap.registerHandler("*", new BogusRedirectService("xxx://bogus"));
|
||||
|
|
Loading…
Reference in New Issue