hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 38004] New: - Explicit VirtualHosts Can Cause Issues On Redirects
Date Thu, 22 Dec 2005 06:29:35 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38004>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38004

           Summary: Explicit VirtualHosts Can Cause Issues On Redirects
           Product: HttpClient
           Version: Nightly Builds
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Commons HttpClient
        AssignedTo: httpclient-dev@jakarta.apache.org
        ReportedBy: p.issues.apache.org@rimuhosting.com


If you set an explicit virtual host then a getmethod may get stuck in a redirect
loop (up to maxRedirects).

e.g. execute a get on www.google.com (with a www.google.com virtualhost).  That
redirects to www.google.co.nz (at least if you come from an NZ IP).  The current
httpclient behavior is to then connect to www.google.co.nz but pass through,
with the request, "Host: www.google.com".  Google will then reply with another
www.google.co.nz redirect and the loop continues.

There are probably a few ways to work around this.  It seems reasonable to drop
an explicity set virtual host in the event a redirect redirects to a different
uri authority.  The following patch works for me:


diff -Naur
../../t2/commons-httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
src/java/org/apache/commons/httpclient/HttpMethodDirector.java
---
../../t2/commons-httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
2005-12-22 01:06:55.000000000 +1300
+++ src/java/org/apache/commons/httpclient/HttpMethodDirector.java	2005-12-22
19:09:51.000000000 +1300
@@ -605,6 +605,27 @@
 					redirectUri = new URI(currentUri, redirectUri);
 				}
 			}
+            do {
+                // scenario we're trying to avoid:
+                // virtual host is set (e.g. google.com); a request to that
server responds
+                // with a redirect to google.co.nz; we issue a request to
google.co.nz with 
+                // a virtual host request of google.com
+                // 
+                // This code will remove any set virtual host if the redirect
is to a different 
+                // domain
+
+                if(redirectUri.isRelativeURI()) {
+                    break;
+                }
+
+                String vhost = hostConfiguration.getParams().getVirtualHost();
+                if(vhost==null)
+                    break;
+                if(redirectUri.getAuthority()!=currentUri.getAuthority()) {
+                    hostConfiguration.getParams().setVirtualHost(null);
+                }
+            } while(false);
+

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message