commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r366870 - in /jakarta/commons/proper/httpclient/trunk: release_notes.txt src/java/org/apache/commons/httpclient/HttpMethodDirector.java src/test/org/apache/commons/httpclient/TestVirtualHost.java
Date Sat, 07 Jan 2006 18:13:21 GMT
Author: olegk
Date: Sat Jan  7 10:12:55 2006
New Revision: 366870

URL: http://svn.apache.org/viewcvs?rev=366870&view=rev
Log:
PR #38004 (Explicit VirtualHosts Can Cause Issues On Redirects)

Contributed by Oleg Kalnichevski
Reviewed by Ortwin Gl├╝ck and Michael Becke


Modified:
    jakarta/commons/proper/httpclient/trunk/release_notes.txt
    jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
    jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestVirtualHost.java

Modified: jakarta/commons/proper/httpclient/trunk/release_notes.txt
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/release_notes.txt?rev=366870&r1=366869&r2=366870&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/release_notes.txt (original)
+++ jakarta/commons/proper/httpclient/trunk/release_notes.txt Sat Jan  7 10:12:55 2006
@@ -1,9 +1,15 @@
 Changes since Release 3.0:
 
- * 38139 - Calling MultiThreadedHttpConnectionManager.setMaxTotalConnections(int) had no
effect
+ * 38004 - Fixed bug causing cyclic redirects when virtual host is set
+           Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+ * 38139 - Calling deprecated MultiThreadedHttpConnectionManager.setMaxTotalConnections(int)

+           had no effect
+           Contributed by Ortwin Glueck <oglueck at apache.org>
 
  * 37988 - Fixed bug in URI#toString() causing user name / password to 
            stripped from the resultant String
+           Contributed by Oleg Kalnichevski <olegk at apache.org>
 
 Release 3.0 
 -------------------

Modified: jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodDirector.java?rev=366870&r1=366869&r2=366870&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
(original)
+++ jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
Sat Jan  7 10:12:55 2006
@@ -604,7 +604,10 @@
 					LOG.debug("Redirect URI is not absolute - parsing as relative");
 					redirectUri = new URI(currentUri, redirectUri);
 				}
-			}
+			} else {
+                // Reset the default params
+                method.getParams().setDefaults(this.params);
+            }
             method.setURI(redirectUri);
             hostConfiguration.setHost(redirectUri);
 		} catch (URIException e) {

Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestVirtualHost.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestVirtualHost.java?rev=366870&r1=366869&r2=366870&view=diff
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestVirtualHost.java
(original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestVirtualHost.java
Sat Jan  7 10:12:55 2006
@@ -31,12 +31,19 @@
 package org.apache.commons.httpclient;
 
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
 import org.apache.commons.httpclient.server.HttpService;
+import org.apache.commons.httpclient.server.RequestLine;
 import org.apache.commons.httpclient.server.SimpleRequest;
 import org.apache.commons.httpclient.server.SimpleResponse;
 
@@ -121,4 +128,94 @@
             httpget.releaseConnection();
         }
     }
+    
+    private class VirtualHostService implements HttpService {
+
+        public VirtualHostService() {
+            super();
+        }
+
+        public boolean process(final SimpleRequest request, final SimpleResponse response)
+            throws IOException {
+            RequestLine reqline = request.getRequestLine();
+            HttpVersion ver = reqline.getHttpVersion();
+            Header header =  request.getFirstHeader("Host");
+            if (header == null) {
+                response.setStatusLine(ver, HttpStatus.SC_BAD_REQUEST);
+                return true;
+            }
+            String host = header.getValue();
+            if (host.equalsIgnoreCase("whatever.com")) {
+                response.setStatusLine(ver, HttpStatus.SC_MOVED_TEMPORARILY);
+                response.setHeader(new Header("Location", "testhttp://www.whatever.com/"));
+                return true;
+            } else if (host.equalsIgnoreCase("www.whatever.com")) {
+                response.setStatusLine(ver, HttpStatus.SC_MOVED_TEMPORARILY);
+                response.setHeader(new Header("Location", "testhttp://www.whatever.co.nz/"));
+                return true;
+            } else if (host.equalsIgnoreCase("www.whatever.co.nz")) {
+                response.setStatusLine(ver, HttpStatus.SC_OK);
+                return true;
+            } else {
+                response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
+                return true;
+            }
+        }
+    }
+    
+    private class VirtualSocketFactory implements ProtocolSocketFactory {
+        
+        private final String hostname;
+        private final int port;
+        
+        public VirtualSocketFactory(final String hostname, int port) {
+            super();
+            this.hostname = hostname;
+            this.port = port;
+        }
+
+        public Socket createSocket(
+                final String host, 
+                int port, 
+                final InetAddress localAddress, 
+                int localPort, 
+                final HttpConnectionParams params) throws IOException, UnknownHostException,
ConnectTimeoutException {
+            return new Socket(this.hostname, this.port);
+        }
+
+        public Socket createSocket(String host, int port, InetAddress localAddress, int localPort)
throws IOException, UnknownHostException {
+            return new Socket(this.hostname, this.port);
+        }
+
+        public Socket createSocket(String host, int port) throws IOException, UnknownHostException
{
+            return new Socket(this.hostname, this.port);
+        }
+        
+    }
+
+    public void testRedirectWithVirtualHost() throws IOException {
+        String host = this.server.getLocalAddress();
+        int port = this.server.getLocalPort();
+
+        Protocol testhttp = new Protocol("http", new VirtualSocketFactory(host, port), port);
+        Protocol.registerProtocol("testhttp", testhttp);
+        try {
+            this.server.setHttpService(new VirtualHostService());
+            this.client.getHostConfiguration().setHost(host, port, "testhttp");
+            this.client.getHostConfiguration().getParams().setVirtualHost("whatever.com");
+            GetMethod httpget = new GetMethod("/");
+            httpget.setFollowRedirects(true);
+            try {
+                this.client.executeMethod(httpget);
+                assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
+                assertEquals("http://www.whatever.co.nz/", httpget.getURI().toString());
+            } finally {
+                httpget.releaseConnection();
+            }
+        } finally {
+            Protocol.unregisterProtocol("testhttp");
+        }
+        
+    }
+    
 }



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


Mime
View raw message