Return-Path: X-Original-To: apmail-hc-dev-archive@www.apache.org Delivered-To: apmail-hc-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2C1D8D87B for ; Tue, 8 Jan 2013 14:26:13 +0000 (UTC) Received: (qmail 56877 invoked by uid 500); 8 Jan 2013 14:26:13 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 56849 invoked by uid 500); 8 Jan 2013 14:26:13 -0000 Mailing-List: contact dev-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 dev@hc.apache.org Received: (qmail 56700 invoked by uid 99); 8 Jan 2013 14:26:12 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jan 2013 14:26:12 +0000 Date: Tue, 8 Jan 2013 14:26:12 +0000 (UTC) From: "Michiel Proce (JIRA)" To: dev@hc.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (HTTPCLIENT-1294) CircularRedirectException is falsely thrown on URI case mismatch MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13546914#comment-13546914 ] Michiel Proce edited comment on HTTPCLIENT-1294 at 1/8/13 2:25 PM: ------------------------------------------------------------------- Workaround, in own implementation of org.apache.http.impl.client.DefaultRedirectStrategy: @Override protected URI createLocationURI(String location) throws ProtocolException { // Let HttpClient build an URI URI locationURI = super.createLocationURI(location); // Workaround HttpClient bug: https://issues.apache.org/jira/browse/HTTPCLIENT-1294 // Lower case the host (case insenistive according to RFC-3986 http://tools.ietf.org/html/rfc3986#section-3.1) // This way we prevent an extra redirect from IIS6: EXAMPLE.com -> example.com. These hosts are considered equal, and throw a CircularRedirectException if (locationURI != null) { String host = locationURI.getHost(); if (host != null) { String hostLowerCase = host.toLowerCase(); // if the host contains uppercase characters if (!host.equals(hostLowerCase)) { // rebuild the URI with lower case host try { locationURI = new URIBuilder(locationURI) .setHost(host.toLowerCase()) .build(); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } } } } return locationURI; } was (Author: michielproce): Workaround, in own implementation of org.apache.http.impl.client.DefaultRedirectStrategy: {code:java} @Override protected URI createLocationURI(String location) throws ProtocolException { // Let HttpClient build an URI URI locationURI = super.createLocationURI(location); // Workaround HttpClient bug: https://issues.apache.org/jira/browse/HTTPCLIENT-1294 // Lower case the host (case insenistive according to RFC-3986 http://tools.ietf.org/html/rfc3986#section-3.1) // This way we prevent an extra redirect from IIS6: EXAMPLE.com -> example.com. These hosts are considered equal, and throw a CircularRedirectException if (locationURI != null) { String host = locationURI.getHost(); if (host != null) { String hostLowerCase = host.toLowerCase(); // if the host contains uppercase characters if (!host.equals(hostLowerCase)) { // rebuild the URI with lower case host try { locationURI = new URIBuilder(locationURI) .setHost(host.toLowerCase()) .build(); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } } } } return locationURI; } {code} > CircularRedirectException is falsely thrown on URI case mismatch > ---------------------------------------------------------------- > > Key: HTTPCLIENT-1294 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1294 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient > Affects Versions: 4.1.3, 4.2.2 > Reporter: Michiel Proce > > Some servers (including IIS6) redirect wrong-cased request URIs to lower case: > http://EXAMPLE.com/ -> http://example.com/ > Now when I'm redirected from another URI to an uppercase URI, the following redirects happen: > http://referrer.com/ -> http://EXAMPLE.com/ -> http://example.com/ > When running this request with HttpClient (with default ALLOW_CIRCULAR_REDIRECTS: false), I get a org.apache.http.client.CircularRedirectException, even though a circular redirect won't occur. > The problem lies in java.net.URI, the following URIs are considered equal: > URI a = new URI("http://example.com"); > URI b = new URI("http://EXAMPLE.com"); > // a.equals(b): true > // a.hashCode() == b.hashCode(): true > The redirect locations are stored in a HashSet in org.apache.http.impl.client.RedirectLocations. A CircularRedirectException is thrown when an URI is already in this hashset. > I have no real suggestions on how to fix this, because I am not known with the coding style for HttpClient.. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org