Author: olegk
Date: Tue Feb 22 02:00:23 2005
New Revision: 154822

URL: http://svn.apache.org/viewcvs?view=rev&rev=154822
Log:
PR #33541 (Problem getting the HTTPClient to use HTTP 1.0 with a proxy server)

Changelog:
* Fixed the problem with host level parameters having no effect on HTTP CONNECT 
methods

Contributed by Oleg Kalnichevski

Added:
    
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestParamsAll.java
    
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestSSLTunnelParams.java
Modified:
    
jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/ConnectMethod.java
    
jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
    
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java

Modified: 
jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/ConnectMethod.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/ConnectMethod.java?view=diff&r1=154821&r2=154822
==============================================================================
--- 
jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/ConnectMethod.java
 (original)
+++ 
jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/ConnectMethod.java
 Tue Feb 22 02:00:23 2005
@@ -1,7 +1,7 @@
 /*
  * $Header: 
/home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java,v
 1.29 2004/06/24 21:39:52 mbecke Exp $
  * $Revision: 1.29 $
- * $Date: 2004/06/24 21:39:52 $
+ * $Date$
  *
  * ====================================================================
  *
@@ -42,7 +42,7 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Mike Bowler</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Oleg Kalnichevski</a>
  * @since 2.0
- * @version $Revision: 1.29 $ $Date: 2004/06/24 21:39:52 $
+ * @version $Revision: 1.29 $ $Date$
  */
 public class ConnectMethod extends HttpMethodBase {
     
@@ -170,7 +170,8 @@
             buffer.append(':'); 
             buffer.append(port); 
         }
-        buffer.append(" HTTP/1.1"); 
+        buffer.append(" "); 
+        buffer.append(getEffectiveVersion()); 
         String line = buffer.toString();
         conn.printLine(line, getParams().getHttpElementCharset());
         if (Wire.HEADER_WIRE.enabled()) {

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?view=diff&r1=154821&r2=154822
==============================================================================
--- 
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
 Tue Feb 22 02:00:23 2005
@@ -1,7 +1,7 @@
 /*
  * $Header: 
/home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v
 1.34 2005/01/14 19:40:39 olegk Exp $
  * $Revision: 1.34 $
- * $Date: 2005/01/14 19:40:39 $
+ * $Date$
  *
  * ====================================================================
  *
@@ -458,7 +458,7 @@
         throws IOException, HttpException {
 
         this.connectMethod = new ConnectMethod();
-        this.connectMethod.getParams().setDefaults(this.params);
+        
this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams());
         
         int code;
         for (;;) {

Modified: 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java?view=diff&r1=154821&r2=154822
==============================================================================
--- 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java
 (original)
+++ 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestNoHost.java
 Tue Feb 22 02:00:23 2005
@@ -1,7 +1,7 @@
 /*
  * $Header: 
/home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v
 1.48 2004/11/20 17:56:39 olegk Exp $
  * $Revision: 1.48 $
- * $Date: 2004/11/20 17:56:39 $
+ * $Date$
  * ====================================================================
  *
  *  Copyright 1999-2004 The Apache Software Foundation
@@ -33,7 +33,7 @@
 
 import org.apache.commons.httpclient.auth.TestAuthAll;
 import org.apache.commons.httpclient.cookie.TestCookieAll;
-import org.apache.commons.httpclient.params.TestHttpParams;
+import org.apache.commons.httpclient.params.TestParamsAll;
 
 /**
  * Tests that don't require any external host.
@@ -43,7 +43,7 @@
  *
  * @author Rodney Waldhoff
  * @author <a href="mailto:[EMAIL PROTECTED]">Jeff Dever</a>
- * @version $Revision: 1.48 $ $Date: 2004/11/20 17:56:39 $
+ * @version $Revision: 1.48 $ $Date$
  */
 public class TestNoHost extends TestCase {
 
@@ -87,7 +87,7 @@
         suite.addTest(TestIdleConnectionTimeout.suite());
         suite.addTest(TestMethodAbort.suite());
         // Preferences
-        suite.addTest(TestHttpParams.suite());
+        suite.addTest(TestParamsAll.suite());
         suite.addTest(TestVirtualHost.suite());        
         // URIs
         suite.addTest(TestURI.suite());

Added: 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestParamsAll.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestParamsAll.java?view=auto&rev=154822
==============================================================================
--- 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestParamsAll.java
 (added)
+++ 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestParamsAll.java
 Tue Feb 22 02:00:23 2005
@@ -0,0 +1,55 @@
+/*
+ * $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
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.commons.httpclient.params;
+
+import junit.framework.*;
+
+/**
+ * @author Oleg Kalnichevski 
+ * 
+ * @version $Id$
+ */
+public class TestParamsAll extends TestCase {
+
+    public TestParamsAll(String testName) {
+        super(testName);
+    }
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite();
+        suite.addTest(TestHttpParams.suite());
+        suite.addTest(TestSSLTunnelParams.suite());
+        return suite;
+    }
+
+    public static void main(String args[]) {
+        String[] testCaseName = { TestParamsAll.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+}

Added: 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestSSLTunnelParams.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestSSLTunnelParams.java?view=auto&rev=154822
==============================================================================
--- 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestSSLTunnelParams.java
 (added)
+++ 
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/params/TestSSLTunnelParams.java
 Tue Feb 22 02:00:23 2005
@@ -0,0 +1,191 @@
+/*
+ * $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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.commons.httpclient.params;
+
+import java.io.IOException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.httpclient.FeedbackService;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClientTestBase;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.server.HttpRequestHandler;
+import org.apache.commons.httpclient.server.SimpleHttpServerConnection;
+import org.apache.commons.httpclient.server.SimpleRequest;
+import org.apache.commons.httpclient.server.SimpleResponse;
+
+/**
+ * Tunnelling proxy configuration.
+ *
+ * @author Oleg Kalnichevski
+ * 
+ * @version $Id$
+ */
+public class TestSSLTunnelParams extends HttpClientTestBase {
+
+    // ------------------------------------------------------------ Constructor
+    public TestSSLTunnelParams(final String testName) throws IOException {
+        super(testName);
+        setUseProxy(true);
+        setUseSSL(true);
+    }
+
+    // ------------------------------------------------------------------- Main
+    public static void main(String args[]) {
+        String[] testCaseName = { TestSSLTunnelParams.class.getName() };
+        junit.textui.TestRunner.main(testCaseName);
+    }
+
+    // ------------------------------------------------------- TestCase Methods
+
+    public static Test suite() {
+        TestSuite suite = new TestSuite(TestSSLTunnelParams.class);
+        return suite;
+    }
+
+    
+    static class HttpVersionHandler implements HttpRequestHandler {
+        
+        public HttpVersionHandler() {
+            super();
+        }
+
+        public boolean processRequest(
+                final SimpleHttpServerConnection conn,
+                final SimpleRequest request) throws IOException
+            {
+                HttpVersion ver = request.getRequestLine().getHttpVersion();
+                if (ver.equals(HttpVersion.HTTP_1_0)) {
+                    return false;
+                } else {
+                    SimpleResponse response = new SimpleResponse();
+                    response.setStatusLine(ver, 
HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
+                    response.addHeader(new Header("Proxy-Connection", 
"close"));
+                    conn.setKeepAlive(false);
+                    // Make sure the request body is fully consumed
+                    request.getBodyBytes();
+                    conn.writeResponse(response);
+                    return true;
+                }
+            }
+        
+    }
+   
+    /**
+     * Tests correct proparation of HTTP params from the client to
+     * CONNECT method.
+     */
+    public void testTunnellingParamsAgentLevel() throws IOException {
+        this.proxy.addHandler(new HttpVersionHandler());
+        this.server.setHttpService(new FeedbackService());
+
+        this.client.getParams().setVersion(HttpVersion.HTTP_1_1);
+        GetMethod httpget = new GetMethod("/test/");
+        try {
+            this.client.executeMethod(httpget);
+            assertNotNull(httpget.getStatusLine());
+            assertEquals(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED, 
+                    httpget.getStatusLine().getStatusCode());
+        } finally {
+            httpget.releaseConnection();
+        }
+
+        this.client.getParams().setVersion(HttpVersion.HTTP_1_0);
+        httpget = new GetMethod("/test/");
+        try {
+            this.client.executeMethod(httpget);
+            assertNotNull(httpget.getStatusLine());
+            assertEquals(HttpStatus.SC_OK, 
+                    httpget.getStatusLine().getStatusCode());
+        } finally {
+            httpget.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests correct proparation of HTTP params from the host config to
+     * CONNECT method.
+     */
+    public void testTunnellingParamsHostLevel() throws IOException {
+        this.proxy.addHandler(new HttpVersionHandler());
+        this.server.setHttpService(new FeedbackService());
+
+        this.client.getHostConfiguration().getParams().setParameter(
+                HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
+        GetMethod httpget = new GetMethod("/test/");
+        try {
+            this.client.executeMethod(httpget);
+            assertNotNull(httpget.getStatusLine());
+            assertEquals(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED, 
+                    httpget.getStatusLine().getStatusCode());
+        } finally {
+            httpget.releaseConnection();
+        }
+
+        this.client.getHostConfiguration().getParams().setParameter(
+                HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
+        httpget = new GetMethod("/test/");
+        try {
+            this.client.executeMethod(httpget);
+            assertNotNull(httpget.getStatusLine());
+            assertEquals(HttpStatus.SC_OK, 
+                    httpget.getStatusLine().getStatusCode());
+        } finally {
+            httpget.releaseConnection();
+        }
+    }
+
+    /**
+     * Tests ability to use HTTP/1.0 to execute CONNECT method and HTTP/1.1 to
+     * execute methods once the tunnel is established.
+     */
+    public void testTunnellingParamsHostHTTP10AndMethodHTTP11() throws 
IOException {
+        this.proxy.addHandler(new HttpVersionHandler());
+        this.server.setHttpService(new FeedbackService());
+
+        this.client.getHostConfiguration().getParams().setParameter(
+                HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
+        GetMethod httpget = new GetMethod("/test/");
+        httpget.getParams().setVersion(HttpVersion.HTTP_1_1);
+        try {
+            this.client.executeMethod(httpget);
+            assertNotNull(httpget.getStatusLine());
+            assertEquals(HttpStatus.SC_OK, 
+                    httpget.getStatusLine().getStatusCode());
+            assertEquals(HttpVersion.HTTP_1_1, 
+                    httpget.getEffectiveVersion());
+        } finally {
+            httpget.releaseConnection();
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to