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 2015/06/21 12:44:31 UTC

svn commit: r1686699 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/client/config/ main/java/org/apache/http/impl/client/ test/java/org/apache/http/client/config/ test/java/org/apache/http/impl/client/ test/java/org/apa...

Author: olegk
Date: Sun Jun 21 10:44:31 2015
New Revision: 1686699

URL: http://svn.apache.org/r1686699
Log:
RFC 7231: removed restriction on the use of relative URIs in Location header

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java?rev=1686699&r1=1686698&r2=1686699&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java Sun Jun 21 10:44:31 2015
@@ -48,7 +48,6 @@ public class RequestConfig implements Cl
     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 Cl
         this.localAddress = localAddress;
         this.cookieSpec = cookieSpec;
         this.redirectsEnabled = redirectsEnabled;
-        this.relativeRedirectsAllowed = relativeRedirectsAllowed;
         this.circularRedirectsAllowed = circularRedirectsAllowed;
         this.maxRedirects = maxRedirects;
         this.authenticationEnabled = authenticationEnabled;
@@ -174,17 +172,6 @@ public class RequestConfig implements Cl
     }
 
     /**
-     * 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
      * are permitted, therefore optionally they can be enabled
@@ -312,7 +299,6 @@ public class RequestConfig implements Cl
         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 Cl
             .setLocalAddress(config.getLocalAddress())
             .setCookieSpec(config.getCookieSpec())
             .setRedirectsEnabled(config.isRedirectsEnabled())
-            .setRelativeRedirectsAllowed(config.isRelativeRedirectsAllowed())
             .setCircularRedirectsAllowed(config.isCircularRedirectsAllowed())
             .setMaxRedirects(config.getMaxRedirects())
             .setAuthenticationEnabled(config.isAuthenticationEnabled())

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java?rev=1686699&r1=1686698&r2=1686699&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java Sun Jun 21 10:44:31 2015
@@ -123,16 +123,9 @@ public class DefaultRedirectStrategy imp
         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());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java?rev=1686699&r1=1686698&r2=1686699&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java Sun Jun 21 10:44:31 2015
@@ -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());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java?rev=1686699&r1=1686698&r2=1686699&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java Sun Jun 21 10:44:31 2015
@@ -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();

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java?rev=1686699&r1=1686698&r2=1686699&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java Sun Jun 21 10:44:31 2015
@@ -616,23 +616,6 @@ public class TestRedirects extends Local
     }
 
     @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"));