mbecke 2003/09/03 19:12:13 Modified: httpclient/src/java/org/apache/commons/httpclient HttpMethodBase.java httpclient/src/test/org/apache/commons/httpclient TestMethodsRedirectNoHost.java NoHostHttpConnectionManager.java Log: Fixes host header redirect bug. PR: 22667 Submitted by: Michael Becke Revision Changes Path 1.179 +4 -10 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java Index: HttpMethodBase.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.178 retrieving revision 1.179 diff -u -r1.178 -r1.179 --- HttpMethodBase.java 3 Sep 2003 02:17:49 -0000 1.178 +++ HttpMethodBase.java 4 Sep 2003 02:12:13 -0000 1.179 @@ -1223,12 +1223,6 @@ } int port = conn.getPort(); - if (getRequestHeader("host") != null) { - LOG.debug( - "Request to add Host header ignored: header already added"); - return; - } - // Note: RFC 2616 uses the term "internet host name" for what goes on the // host line. It would seem to imply that host should be blank if the // host is a number instead of an name. Based on the behavior of web 1.8 +9 -10 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java Index: TestMethodsRedirectNoHost.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- TestMethodsRedirectNoHost.java 12 Aug 2003 02:35:17 -0000 1.7 +++ TestMethodsRedirectNoHost.java 4 Sep 2003 02:12:13 -0000 1.8 @@ -209,17 +209,16 @@ } public void testRedirectDifferentHost() throws Exception { - conn = new SimpleHttpConnection("oldhost", 80); + addRedirectResponse("http://newhost/newfile"); addOkResponse(); - conn.open(); HttpMethod method = new SimpleHttpMethod("/oldfile"); method.setFollowRedirects(true); - method.execute(new HttpState(), conn); - Header locationHeader = method.getResponseHeader("Location"); - assertEquals(302, method.getStatusCode()); - assertEquals("/oldfile", method.getPath()); + client.executeMethod(method); + assertEquals(200, method.getStatusCode()); + assertEquals("/newfile", method.getPath()); + assertEquals("newhost", method.getRequestHeader("host").getValue()); } public void testRedirectDifferentPort() throws Exception { 1.2 +26 -3 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java Index: NoHostHttpConnectionManager.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/NoHostHttpConnectionManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NoHostHttpConnectionManager.java 12 Aug 2003 02:35:17 -0000 1.1 +++ NoHostHttpConnectionManager.java 4 Sep 2003 02:12:13 -0000 1.2 @@ -20,7 +20,7 @@ private HttpConnection connection; public NoHostHttpConnectionManager() { - this.connection = new SimpleHttpConnection(); + setConnection(new SimpleHttpConnection()); } /** @@ -28,22 +28,45 @@ */ public void setConnection(HttpConnection connection) { this.connection = connection; + connection.setHttpConnectionManager(this); } public HttpConnection getConnection(HostConfiguration hostConfiguration) { + + // make sure the host and proxy are correct for this connection + // close it and set the values if they are not + if (!hostConfiguration.hostEquals(connection) + || !hostConfiguration.proxyEquals(connection)) { + + if (connection.isOpen()) { + connection.close(); + } + + connection.setHost(hostConfiguration.getHost()); + connection.setVirtualHost(hostConfiguration.getVirtualHost()); + connection.setPort(hostConfiguration.getPort()); + connection.setProtocol(hostConfiguration.getProtocol()); + connection.setLocalAddress(hostConfiguration.getLocalAddress()); + + connection.setProxyHost(hostConfiguration.getProxyHost()); + connection.setProxyPort(hostConfiguration.getProxyPort()); + } else { + finishLastResponse(connection); + } + return connection; } public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { - return connection; + return getConnection(hostConfiguration); } public HttpConnection getConnectionWithTimeout( HostConfiguration hostConfiguration, long timeout) throws ConnectTimeoutException { - return connection; + return getConnection(hostConfiguration); } public void releaseConnection(HttpConnection conn) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]