Index: java/org/apache/commons/httpclient/HttpMethodBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.120
diff -u -r1.120 HttpMethodBase.java
--- java/org/apache/commons/httpclient/HttpMethodBase.java 6 Mar 2003 07:49:03 -0000 1.120
+++ java/org/apache/commons/httpclient/HttpMethodBase.java 7 Mar 2003 17:44:11 -0000
@@ -77,6 +77,7 @@
import org.apache.commons.httpclient.cookie.MalformedCookieException;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
+import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -1502,50 +1503,59 @@
* @param name the method name generate a request for
* @param requestPath the path string for the request
* @param query the query string for the request
- * @param protocol the protocol to use (e.g. HTTP/1.0)
+ * @param version the protocol version to use (e.g. HTTP/1.0)
*
* @return a line to send to the server that will fulfil the request
*/
protected static String generateRequestLine(HttpConnection connection,
- String name, String requestPath, String query, String protocol) {
+ String name, String requestPath, String query, String version) {
LOG.trace("enter HttpMethodBase.generateRequestLine(HttpConnection, "
+ "String, String, String, String)");
StringBuffer buf = new StringBuffer();
- String path = null;
- try {
- path = (requestPath == null) ? "/" : URIUtil.encodePath(requestPath);
- } catch (URIException urie) {
- LOG.error("URI path encoding error");
- path = requestPath;
+ // Append method name
+ buf.append(name);
+ buf.append(" ");
+ // Absolute or relative URL?
+ if (!connection.isTransparent()) {
+ Protocol protocol = connection.getProtocol();
+ buf.append(protocol.getScheme().toLowerCase());
+ buf.append("://");
+ buf.append(connection.getHost());
+ if ((connection.getPort() != -1) && (connection.getPort() != protocol.getDefaultPort())) {
+ buf.append(":");
+ buf.append(connection.getPort());
+ }
+ }
+ // Append path, if any
+ if (requestPath == null) {
+ buf.append("/");
+ } else {
+ if (!connection.isTransparent() && !requestPath.startsWith("/")) {
+ buf.append("/");
+ }
+ try {
+ buf.append(URIUtil.encodePath(requestPath));
+ } catch (URIException e) {
+ if (LOG.isErrorEnabled()) {
+ LOG.error("URI path encoding error: " + e.getMessage());
+ }
+ buf.append(requestPath);
+ }
}
- buf.append(path);
+ // Append query, if any
if (query != null) {
if (query.indexOf("?") != 0) {
buf.append("?");
}
- String queryString = null;
- queryString = (query == null) ? "/" : query;
- buf.append(queryString);
- }
-
- if (!connection.isProxied() || connection.isTransparent()) {
- return (name + " " + buf.toString() + " " + protocol + "\r\n");
- } else {
- if (connection.isSecure()) {
- return (name + " https://" + connection.getHost()
- + ((443 == connection.getPort()
- || -1 == connection.getPort())
- ? "" : (":" + connection.getPort())) + buf.toString()
- + " " + protocol + "\r\n");
- } else {
- return (name + " http://" + connection.getHost()
- + ((80 == connection.getPort()
- || -1 == connection.getPort())
- ? "" : (":" + connection.getPort())) + buf.toString()
- + " " + protocol + "\r\n");
- }
+ buf.append(query);
}
+ // Append protocol
+ buf.append(" ");
+ buf.append(version);
+ buf.append("\r\n");
+
+ return buf.toString();
}
/**
Index: test/org/apache/commons/httpclient/SimpleHttpConnection.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v
retrieving revision 1.10
diff -u -r1.10 SimpleHttpConnection.java
--- test/org/apache/commons/httpclient/SimpleHttpConnection.java 16 Feb 2003 13:08:34 -0000 1.10
+++ test/org/apache/commons/httpclient/SimpleHttpConnection.java 7 Mar 2003 17:44:10 -0000
@@ -114,6 +114,15 @@
super(null, -1, "localhost", 80, Protocol.getProtocol("http"));
}
+ public SimpleHttpConnection(
+ String proxyHost,
+ int proxyPort,
+ String host,
+ int port,
+ Protocol protocol) {
+ super(proxyHost, proxyPort, host, port, protocol);
+ }
+
public SimpleHttpConnection(String host, int port){
super(host, port, Protocol.getProtocol("http"));
}
@@ -191,12 +200,6 @@
return str;
}
- public boolean waitForResponse(long timeout_ms)
- throws IOException, IllegalStateException {
- return true;
- }
-
-
public InputStream getResponseInputStream() {
return inputStream;
}
Index: test/org/apache/commons/httpclient/SimpleHttpMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpMethod.java,v
retrieving revision 1.5
diff -u -r1.5 SimpleHttpMethod.java
--- test/org/apache/commons/httpclient/SimpleHttpMethod.java 11 Feb 2003 03:23:05 -0000 1.5
+++ test/org/apache/commons/httpclient/SimpleHttpMethod.java 7 Mar 2003 17:44:10 -0000
@@ -139,5 +139,10 @@
ensureResponseHeaderIsSet();
return super.getResponseHeaders();
}
-
+
+
+ public String getTestRequestLine(HttpConnection connection) {
+ return HttpMethodBase.generateRequestLine(connection,
+ this.getName(), this.getPath(), this.getQueryString(), "HTTP/1.1");
+ }
}
Index: test/org/apache/commons/httpclient/TestRequestLine.java
===================================================================
RCS file: test/org/apache/commons/httpclient/TestRequestLine.java
diff -N test/org/apache/commons/httpclient/TestRequestLine.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/org/apache/commons/httpclient/TestRequestLine.java 7 Mar 2003 17:44:10 -0000
@@ -0,0 +1,135 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * 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 org.apache.commons.httpclient.protocol.Protocol;
+import junit.framework.*;
+
+/**
+ * Simple tests for {@link StatusLine}.
+ *
+ * @author oleg Kalnichevski
+ * @version $Id: TestStatusLine.java,v 1.6 2003/02/07 04:50:03 jsdever Exp $
+ */
+public class TestRequestLine extends TestCase {
+
+ private StatusLine statusLine = null;
+
+ // ------------------------------------------------------------ Constructor
+ public TestRequestLine(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestRequestLine.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+
+ public static Test suite() {
+ return new TestSuite(TestRequestLine.class);
+ }
+
+ // ------------------------------------------------------ Protected Methods
+
+
+ // ----------------------------------------------------------- Test Methods
+
+ public void testDirectAccess() throws Exception {
+ SimpleHttpConnection conn = null;
+ SimpleHttpMethod method = null;
+
+ conn = new SimpleHttpConnection(null, -1, "localhost", 80, Protocol.getProtocol("http"));
+
+ method = new SimpleHttpMethod();
+ assertEquals("Simple / HTTP/1.1\r\n", method.getTestRequestLine(conn));
+
+ method = new SimpleHttpMethod("stuff");
+ assertEquals("Simple stuff HTTP/1.1\r\n", method.getTestRequestLine(conn));
+
+ conn = new SimpleHttpConnection("proxy", 8080, "localhost", 80, Protocol.getProtocol("http"));
+
+ method = new SimpleHttpMethod();
+ assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.getTestRequestLine(conn));
+
+ method = new SimpleHttpMethod("stuff");
+ assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.getTestRequestLine(conn));
+
+ conn = new SimpleHttpConnection("proxy", 8080, "localhost", -1, Protocol.getProtocol("http"));
+
+ method = new SimpleHttpMethod();
+ assertEquals("Simple http://localhost/ HTTP/1.1\r\n", method.getTestRequestLine(conn));
+
+ method = new SimpleHttpMethod("stuff");
+ assertEquals("Simple http://localhost/stuff HTTP/1.1\r\n", method.getTestRequestLine(conn));
+
+ conn = new SimpleHttpConnection("proxy", 8080, "localhost", 666, Protocol.getProtocol("http"));
+
+ method = new SimpleHttpMethod();
+ assertEquals("Simple http://localhost:666/ HTTP/1.1\r\n", method.getTestRequestLine(conn));
+
+ method = new SimpleHttpMethod("stuff");
+ assertEquals("Simple http://localhost:666/stuff HTTP/1.1\r\n", method.getTestRequestLine(conn));
+ }
+
+}