hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1483267 - in /httpcomponents/httpclient/trunk: ./ httpclient/src/main/java/org/apache/http/client/utils/ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/test/java/org/apache/http/client/utils/ httpclient/src/test/java/...
Date Thu, 16 May 2013 09:13:11 GMT
Author: olegk
Date: Thu May 16 09:13:11 2013
New Revision: 1483267

URL: http://svn.apache.org/r1483267
Log:
HTTPCLIENT-1294: HttpClient to rewrite host name of the redirect location URI in order to
avoid circular redirect exception due to host name case mismatch.

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.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/utils/TestURIUtils.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1483267&r1=1483266&r2=1483267&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Thu May 16 09:13:11 2013
@@ -1,6 +1,10 @@
 Changes since release 4.3 BETA1
 -------------------
 
+* [HTTPCLIENT-1294] HttpClient to rewrite host name of the redirect location URI in order

+  to avoid circular redirect exception due to host name case mismatch. 
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1264] Add support for multiple levels of browser compatibility
   to BrowserCompatSpec and BrowserCompatSpecFactory.  Include constructor
   argument for IE medium-security compatibility.

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java?rev=1483267&r1=1483266&r2=1483267&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
Thu May 16 09:13:11 2013
@@ -28,6 +28,7 @@ package org.apache.http.client.utils;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.Locale;
 import java.util.Stack;
 
 import org.apache.http.HttpHost;
@@ -173,17 +174,15 @@ public class URIUtils {
      */
     public static URI rewriteURI(final URI uri) throws URISyntaxException {
         Args.notNull(uri, "URI");
-        if (uri.getFragment() != null || uri.getUserInfo() != null
-                || TextUtils.isEmpty(uri.getPath())) {
-            final URIBuilder uribuilder = new URIBuilder(uri);
-            uribuilder.setFragment(null).setUserInfo(null);
-            if (TextUtils.isEmpty(uribuilder.getPath())) {
-                uribuilder.setPath("/");
-            }
-            return uribuilder.build();
-        } else {
-            return uri;
+        final URIBuilder uribuilder = new URIBuilder(uri);
+        uribuilder.setFragment(null).setUserInfo(null);
+        if (TextUtils.isEmpty(uribuilder.getPath())) {
+            uribuilder.setPath("/");
         }
+        if (uribuilder.getHost() != null) {
+            uribuilder.setHost(uribuilder.getHost().toLowerCase(Locale.ENGLISH));
+        }
+        return uribuilder.build();
     }
 
     /**

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=1483267&r1=1483266&r2=1483267&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
Thu May 16 09:13:11 2013
@@ -29,6 +29,7 @@ package org.apache.http.impl.client;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.Locale;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -47,11 +48,13 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.methods.RequestBuilder;
 import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.client.utils.URIUtils;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpCoreContext;
 import org.apache.http.util.Args;
 import org.apache.http.util.Asserts;
+import org.apache.http.util.TextUtils;
 
 /**
  * Default implementation of {@link RedirectStrategy}. This strategy honors the restrictions
@@ -179,7 +182,16 @@ public class DefaultRedirectStrategy imp
      */
     protected URI createLocationURI(final String location) throws ProtocolException {
         try {
-            return new URI(location).normalize();
+            final URIBuilder b = new URIBuilder(new URI(location).normalize());
+            final String host = b.getHost();
+            if (host != null) {
+                b.setHost(host.toLowerCase(Locale.US));
+            }
+            final String path = b.getPath();
+            if (TextUtils.isEmpty(path)) {
+                b.setPath("/");
+            }
+            return b.build();
         } catch (final URISyntaxException ex) {
             throw new ProtocolException("Invalid redirect URI: " + location, ex);
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java?rev=1483267&r1=1483266&r2=1483267&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
Thu May 16 09:13:11 2013
@@ -69,6 +69,8 @@ public class TestURIUtils {
                 URI.create("http://userinfo@thathost/stuff#fragment")).toString());
         Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
                 URI.create("http://thathost")).toString());
+        Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
+                URI.create("http://ThatHost")).toString());
     }
 
     @Test

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=1483267&r1=1483266&r2=1483267&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
Thu May 16 09:13:11 2013
@@ -376,4 +376,17 @@ public class TestDefaultRedirectStrategy
         Assert.assertSame(entity, ((HttpEntityEnclosingRequest) redirect2).getEntity());
     }
 
+    @Test
+    public void testCreateLocationURI() throws Exception {
+        final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
+        Assert.assertEquals("http://blahblah/",
+                redirectStrategy.createLocationURI("http://BlahBlah").toASCIIString());
+    }
+
+    @Test(expected=ProtocolException.class)
+    public void testCreateLocationURIInvalid() throws Exception {
+        final DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
+        redirectStrategy.createLocationURI(":::::::");
+    }
+
 }



Mime
View raw message