Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BAA5A9F19 for ; Thu, 16 May 2013 09:13:33 +0000 (UTC) Received: (qmail 52338 invoked by uid 500); 16 May 2013 09:13:33 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 52302 invoked by uid 500); 16 May 2013 09:13:33 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 52293 invoked by uid 99); 16 May 2013 09:13:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 May 2013 09:13:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 May 2013 09:13:31 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E3BB623889ED for ; Thu, 16 May 2013 09:13:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130516091311.E3BB623889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 + * [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(":::::::"); + } + }