Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 82690 invoked from network); 12 Apr 2004 11:16:30 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 12 Apr 2004 11:16:30 -0000 Received: (qmail 88086 invoked by uid 500); 12 Apr 2004 11:16:26 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 88030 invoked by uid 500); 12 Apr 2004 11:16:25 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 88017 invoked by uid 500); 12 Apr 2004 11:16:25 -0000 Received: (qmail 88014 invoked from network); 12 Apr 2004 11:16:25 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 12 Apr 2004 11:16:25 -0000 Received: (qmail 82681 invoked by uid 1624); 12 Apr 2004 11:16:26 -0000 Date: 12 Apr 2004 11:16:26 -0000 Message-ID: <20040412111626.82680.qmail@minotaur.apache.org> From: olegk@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestRedirects.java TestWebappHeaders.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N olegk 2004/04/12 04:16:26 Modified: httpclient/src/java/org/apache/commons/httpclient HttpMethodDirector.java httpclient/src/test/org/apache/commons/httpclient TestRedirects.java TestWebappHeaders.java Log: PR #27194 (Host configuration properties not updated when the method is redirected) Contributed by Oleg Kalnichevski Reviewed by Michael Becke Revision Changes Path 1.21 +5 -6 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java Index: HttpMethodDirector.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- HttpMethodDirector.java 12 Apr 2004 10:30:46 -0000 1.20 +++ HttpMethodDirector.java 12 Apr 2004 11:16:25 -0000 1.21 @@ -532,6 +532,8 @@ redirectUri = new URI(currentUri, redirectUri); } } + method.setURI(redirectUri); + hostConfiguration.setHost(redirectUri); } catch (URIException e) { LOG.warn("Redirected location '" + location + "' is malformed"); return false; @@ -547,9 +549,6 @@ redirectUri + "'"); } } - method.setPath(redirectUri.getEscapedPath()); - method.setQueryString(redirectUri.getEscapedQuery()); - hostConfiguration.setHost(redirectUri); if (LOG.isDebugEnabled()) { LOG.debug("Redirecting from '" + currentUri.getEscapedURI() 1.2 +39 -14 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRedirects.java Index: TestRedirects.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRedirects.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TestRedirects.java 12 Apr 2004 10:30:46 -0000 1.1 +++ TestRedirects.java 12 Apr 2004 11:16:25 -0000 1.2 @@ -84,12 +84,6 @@ } else if (reqline.getUri().equals("/circular-location2/")) { response.setStatusLine("HTTP/1.1 302 Object moved"); response.addHeader(new Header("Location", "/circular-location1/")); - } else if (reqline.getUri().equals("/location1/")) { - response.setStatusLine("HTTP/1.1 302 Object moved"); - response.addHeader(new Header("Location", "/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"); } @@ -128,16 +122,47 @@ } } + private class RedirectService2 implements HttpService { + + private String host = null; + private int port; + + public RedirectService2(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 { - this.server.setHttpService(new RedirectService()); + String host = this.server.getLocalAddress(); + int port = this.server.getLocalPort(); + this.server.setHttpService(new RedirectService2(host, port)); GetMethod httpget = new GetMethod("/location1/"); try { this.client.executeMethod(httpget); - assertEquals("/location2/", httpget.getPath()); - assertEquals(new URI("/location2/", false), httpget.getURI()); - System.out.println(); + assertEquals(host, httpget.getURI().getHost()); + assertEquals(port, httpget.getURI().getPort()); + assertEquals(new URI("http://" + host + ":" + port + "/location2/", false), httpget.getURI()); } finally { httpget.releaseConnection(); } } + } 1.12 +14 -9 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappHeaders.java Index: TestWebappHeaders.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappHeaders.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- TestWebappHeaders.java 22 Feb 2004 18:08:50 -0000 1.11 +++ TestWebappHeaders.java 12 Apr 2004 11:16:25 -0000 1.12 @@ -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())); } } - } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org