Index: java/org/apache/commons/httpclient/HttpMethodDirector.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v retrieving revision 1.19 diff -u -r1.19 HttpMethodDirector.java --- java/org/apache/commons/httpclient/HttpMethodDirector.java 25 Mar 2004 20:37:19 -0000 1.19 +++ java/org/apache/commons/httpclient/HttpMethodDirector.java 10 Apr 2004 17:14:53 -0000 @@ -534,16 +534,13 @@ redirectUri = new URI(currentUri, redirectUri); } } + //update the current location with the redirect location. + hostConfiguration.setHost(redirectUri); + method.setURI(redirectUri); } catch (URIException e) { LOG.warn("Redirected location '" + location + "' is malformed"); return false; } - //update the current location with the redirect location. - //avoiding use of URL.getPath() and URL.getQuery() to keep - //jdk1.2 comliance. - method.setPath(redirectUri.getEscapedPath()); - method.setQueryString(redirectUri.getEscapedQuery()); - hostConfiguration.setHost(redirectUri); if (LOG.isDebugEnabled()) { LOG.debug("Redirecting from '" + currentUri.getEscapedURI() Index: test/org/apache/commons/httpclient/TestNoHost.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v retrieving revision 1.33 diff -u -r1.33 TestNoHost.java --- test/org/apache/commons/httpclient/TestNoHost.java 25 Mar 2004 20:37:20 -0000 1.33 +++ test/org/apache/commons/httpclient/TestNoHost.java 10 Apr 2004 17:14:55 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v 1.33 2004/03/25 20:37:20 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v 1.33 2004/03/25 20:37:20 olegk Exp $ * $Revision: 1.33 $ * $Date: 2004/03/25 20:37:20 $ * ==================================================================== @@ -66,6 +66,7 @@ suite.addTest(TestChallengeProcessor.suite()); suite.addTest(TestAuthenticator.suite()); suite.addTest(TestBasicAuth.suite()); + suite.addTest(TestRedirects.suite()); suite.addTest(TestHttpUrlMethod.suite()); suite.addTest(TestURI.suite()); suite.addTest(TestURIUtil.suite()); Index: test/org/apache/commons/httpclient/TestRedirects.java =================================================================== RCS file: test/org/apache/commons/httpclient/TestRedirects.java diff -N test/org/apache/commons/httpclient/TestRedirects.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ test/org/apache/commons/httpclient/TestRedirects.java 10 Apr 2004 17:14:55 -0000 @@ -0,0 +1,115 @@ +/* + * $Header$ + * $Revision$ + * $Date$ + * ==================================================================== + * + * Copyright 1999-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * [Additional notices, if required by prior licensing conditions] + * + */ + +package org.apache.commons.httpclient; + +import java.io.IOException; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.params.HttpClientParams; +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; + +import sun.security.action.GetPropertyAction; + +/** + * Basic authentication test cases. + * + * @author Oleg Kalnichevski + * + * @version $Id: TestBasicAuth.java,v 1.2 2004/03/25 20:37:20 olegk Exp $ + */ +public class TestRedirects extends HttpClientTestBase { + + // ------------------------------------------------------------ Constructor + public TestRedirects(String testName) { + super(testName); + } + + // ------------------------------------------------------------------- Main + public static void main(String args[]) { + String[] testCaseName = { TestRedirects.class.getName() }; + junit.textui.TestRunner.main(testCaseName); + } + + // ------------------------------------------------------- TestCase Methods + + public static Test suite() { + return new TestSuite(TestRedirects.class); + } + + private class RedirectService implements HttpService { + + private String host = null; + private int port; + + public RedirectService(final String host, int port) { + super(); + this.host = host; + this.port = port; + } + + public boolean process(final SimpleRequest request, final SimpleResponse response) + throws IOException + { + RequestLine reqline = request.getRequestLine(); + if (reqline.getUri().equals("/location1/")) { + response.setStatusLine("HTTP/1.1 302 Object moved"); + response.addHeader(new Header("Location", "http://" + this.host + ":" + this.port + "/location2/")); + } else if (reqline.getUri().equals("/location2/")) { + response.setStatusLine("HTTP/1.1 200 OK"); + response.setBodyString("Successful redirect"); + } else { + response.setStatusLine("HTTP/1.1 404 Not Found"); + } + return true; + } + } + + public void testRedirectLocation() throws IOException { + String host = this.server.getLocalAddress(); + int port = this.server.getLocalPort(); + this.server.setHttpService(new RedirectService(host, port)); + GetMethod httpget = new GetMethod("/location1/"); + try { + this.client.executeMethod(httpget); + assertEquals(host, httpget.getURI().getHost()); + assertEquals(port, httpget.getURI().getPort()); + assertEquals(new URI("http://" + host + ":" + port + "/location2/", false), httpget.getURI()); + } finally { + httpget.releaseConnection(); + } + } +} Index: test/org/apache/commons/httpclient/TestWebappHeaders.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappHeaders.java,v retrieving revision 1.11 diff -u -r1.11 TestWebappHeaders.java --- test/org/apache/commons/httpclient/TestWebappHeaders.java 22 Feb 2004 18:08:50 -0000 1.11 +++ test/org/apache/commons/httpclient/TestWebappHeaders.java 10 Apr 2004 17:14:56 -0000 @@ -158,13 +158,13 @@ String hostname = addr.getHostName(); HttpClient client = new HttpClient(); - GetMethod get = new GetMethod("/" + getWebappContext()); + GetMethod get = new GetMethod("/" + getWebappContext() + "/"); // Open connection using IP. Host header should be sent // Note: RFC 2616 is somewhat unclear on whether a host should // be sent in this context - however, both Mozilla and IE send // the header for an IP address, instead of sending blank. - client.getHostConfiguration().setHost(ip, getPort(), getProtocol()); + client.getHostConfiguration().setHost(ip, getPort(), getProtocol()); try { client.executeMethod(get); } catch (Throwable t) { @@ -173,17 +173,23 @@ } Header hostHeader = get.getRequestHeader("Host"); assertTrue(hostHeader != null); + if (getPort() == 80) { + // no port information should be in the value + assertTrue(hostHeader.getValue().equals(ip)); + } else { + assertTrue(hostHeader.getValue().equals(ip + ":" + getPort())); + } // reset get.recycle(); - get.setPath("/" + getWebappContext()); + get.setPath("/" + getWebappContext() + "/"); // Open connection using Host. Host header should // contain this value (this test will fail if DNS // is not available. Additionally, if the port is // something other that 80, then the port value // should also be present in the header. - client.getHostConfiguration().setHost(hostname, getPort(), getProtocol()); + client.getHostConfiguration().setHost(hostname, getPort(), getProtocol()); try { client.executeMethod(get); } catch (Throwable t) { @@ -199,6 +205,5 @@ assertTrue(hostHeader.getValue().equals(hostname + ":" + getPort())); } } - }