diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 525668188..ac294a08c 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,5 +1,9 @@ Changes since 4.2 ------------------- + +* [HTTPCLIENT-1209] Redirect URIs are now normalized. + Contributed by Oleg Kalnichevski + * [HTTPCLIENT-1202] ResponseCachingPolicy should honor explicit cache-control directives for other status codes Contributed by Jon Moore 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 f837d1d32..bdec33fc8 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 @@ -184,7 +184,7 @@ public class DefaultRedirectStrategy implements RedirectStrategy { */ 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); } 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 79ce60473..63da9be55 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 @@ -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();