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 2012/06/22 13:05:11 UTC

svn commit: r1352845 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java

Author: olegk
Date: Fri Jun 22 11:05:10 2012
New Revision: 1352845

URL: http://svn.apache.org/viewvc?rev=1352845&view=rev
Log:
HTTPCLIENT-1209: Redirect URIs are now normalized

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.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=1352845&r1=1352844&r2=1352845&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Fri Jun 22 11:05:10 2012
@@ -1,5 +1,9 @@
 Changes since 4.2 
 -------------------
+
+* [HTTPCLIENT-1209] Redirect URIs are now normalized.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1202] ResponseCachingPolicy should honor explicit cache-control
   directives for other status codes
   Contributed by Jon Moore <jonm at apache.org>

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=1352845&r1=1352844&r2=1352845&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 Fri Jun 22 11:05:10 2012
@@ -184,7 +184,7 @@ public class DefaultRedirectStrategy imp
      */
     protected URI createLocationURI(final String location) throws ProtocolException {
         try {
-            return new URI(location);
+            return new URI(location).normalize();
         } catch (URISyntaxException ex) {
             throw new ProtocolException("Invalid redirect URI: " + location, ex);
         }

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=1352845&r1=1352844&r2=1352845&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 Fri Jun 22 11:05:10 2012
@@ -232,6 +232,19 @@ public class TestDefaultRedirectStrategy
         Assert.assertEquals(URI.create("http://localhost/stuff"), uri);
     }
 
+    @Test
+    public void testGetLocationUriNormalized() throws Exception {
+        DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); 
+        HttpContext context = new BasicHttpContext();
+        context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, new HttpHost("localhost"));
+        HttpGet httpget = new HttpGet("http://localhost/");
+        HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 
+                HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
+        response.addHeader("Location", "http://localhost/././stuff/../morestuff");
+        URI uri = redirectStrategy.getLocationURI(httpget, response, context);
+        Assert.assertEquals(URI.create("http://localhost/morestuff"), uri);
+    }
+
     @Test(expected=ProtocolException.class)
     public void testGetLocationUriRelativeLocationNotAllowed() throws Exception {
         DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();