diff --git a/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java b/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java index 2b3fe8ac7c..893b558e6f 100644 --- a/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java +++ b/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java @@ -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 @@ protected RequestConfig() { 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 boolean isRedirectsEnabled() { return redirectsEnabled; } - /** - * Determines whether relative redirects should be rejected. HTTP specification - * requires the location value be an absolute URI. - *

- * Default: {@code true} - *

- */ - 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 String toString() { 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 static RequestConfig.Builder copy(final RequestConfig config) { .setLocalAddress(config.getLocalAddress()) .setCookieSpec(config.getCookieSpec()) .setRedirectsEnabled(config.isRedirectsEnabled()) - .setRelativeRedirectsAllowed(config.isRelativeRedirectsAllowed()) .setCircularRedirectsAllowed(config.isCircularRedirectsAllowed()) .setMaxRedirects(config.getMaxRedirects()) .setAuthenticationEnabled(config.isAuthenticationEnabled()) diff --git a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java index fffa12f101..67c6af9096 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java @@ -123,16 +123,9 @@ public URI getLocationURI( 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()); diff --git a/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java b/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java index 68c70fc8b3..c0b0745dbe 100644 --- a/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java +++ b/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java @@ -51,7 +51,6 @@ public void testDefaults() { 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 void testBuildAndCopy() throws Exception { 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()); diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java b/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java index 1ef467a170..eeb27bcc72 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java @@ -240,21 +240,6 @@ public void testGetLocationUriNormalized() throws Exception { 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(); diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java index 43dbabec56..4bed0528a2 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java @@ -615,23 +615,6 @@ public void testRelativeRedirect2() throws Exception { 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"));