Index: java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v retrieving revision 1.12 diff -u -r1.12 EntityEnclosingMethod.java --- java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 6 Mar 2003 07:49:03 -0000 1.12 +++ java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 12 Mar 2003 10:08:32 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v 1.12 2003/03/06 07:49:03 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v 1.12 2003/03/06 07:49:03 olegk Exp $ * $Revision: 1.12 $ * $Date: 2003/03/06 07:49:03 $ * @@ -92,7 +92,7 @@ * @since 2.0beta1 * @version $Revision: 1.12 $ */ -public abstract class EntityEnclosingMethod extends GetMethod { +public abstract class EntityEnclosingMethod extends ExpectContinueMethod { // ----------------------------------------- Static variables/initializers @@ -125,10 +125,6 @@ */ private int requestContentLength = CONTENT_LENGTH_AUTO; - /** This flag specifies whether "expect: 100-continue" handshake is - * to be used prior to sending the requesst body */ - private boolean useExpectHeader = true; - // ----------------------------------------------------------- Constructors /** @@ -182,6 +178,18 @@ setFollowRedirects(false); } + /** + * Returns true if there is a request body to be sent. + * 'Expect: 100-continue' handshake may not be used if request + * body is not present + * + * @return boolean + * + * @since 2.0beta1 + */ + protected boolean hasRequestContent() { + return (this.requestBodyStream != null) || (this.buffer != null); + } /** * Entity enclosing requests cannot be redirected without user intervention @@ -212,23 +220,6 @@ super.setFollowRedirects(false); } - - /** - * Returns the useExpectHeader. - * @return boolean - */ - public boolean getUseExpectHeader() { - return this.useExpectHeader; - } - - /** - * Sets the useExpectHeader. - * @param value The useExpectHeader to set - */ - public void setUseExpectHeader(boolean value) { - this.useExpectHeader = value; - } - /** * Sets length information about the request body. * @@ -342,38 +333,6 @@ return buffer.toString(); } - - /** - * Set the Expect header if it has not already been set, - * in addition to the "standard" set of headers. - * - * @param state the client state - * @param conn the connection to write to - * - * @throws HttpException when a protocol error occurs or state is invalid - * @throws IOException when i/o errors occur reading the response - */ - protected void addRequestHeaders(HttpState state, HttpConnection conn) - throws IOException, HttpException { - LOG.trace("enter EntityEnclosingMethod.addRequestHeaders(HttpState, HttpConnection)"); - - super.addRequestHeaders(state, conn); - // If the request is being retried, the header may already be present - boolean headerPresent = (getRequestHeader("Expect") != null); - // See if the expect header should be sent - // = HTTP/1.1 or higher - // = request body present - if (getUseExpectHeader() && isHttp11() - && ((this.requestBodyStream != null) || this.buffer != null)) { - if (!headerPresent) { - setRequestHeader("Expect", "100-continue"); - } - } else { - if (headerPresent) { - removeRequestHeader("Expect"); - } - } - } /** * Override method of {@link org.apache.commons.httpclient.HttpMethodBase} Index: java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java =================================================================== RCS file: java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java diff -N java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java 12 Mar 2003 10:08:32 -0000 @@ -0,0 +1,200 @@ +/* + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 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", "Commons", 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.methods; + +import java.io.IOException; +import org.apache.commons.httpclient.HttpConnection; +import org.apache.commons.httpclient.HttpConstants; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpState; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * This abstract class serves as a foundation for all HTTP methods + * that support 'Expect: 100-continue' handshake + * + * @author Oleg Kalnichevski + * + * @since 2.0beta1 + */ + +public abstract class ExpectContinueMethod extends GetMethod +{ + /** This flag specifies whether "expect: 100-continue" handshake is + * to be used prior to sending the request body */ + private boolean useExpectHeader = true; + + /** LOG object for this class. */ + private static final Log LOG = LogFactory.getLog(ExpectContinueMethod.class); + + /** + * No-arg constructor. + * + * @since 2.0 + */ + public ExpectContinueMethod() { + super(); + } + + /** + * Constructor specifying a URI. + * + * @param uri either an absolute or relative URI + * + * @since 2.0 + */ + public ExpectContinueMethod(String uri) { + super(uri); + } + + /** + * Constructor specifying a URI and a tempDir. + * + * @param uri either an absolute or relative URI + * @param tempDir directory to store temp files in + * + * @deprecated the client is responsible for disk I/O + * @since 2.0 + */ + public ExpectContinueMethod(String uri, String tempDir) { + super(uri, tempDir); + } + + /** + * Constructor specifying a URI, tempDir and tempFile. + * + * @param uri either an absolute or relative URI + * @param tempDir directory to store temp files in + * @param tempFile file to store temporary data in + * + * @deprecated the client is responsible for disk I/O + * @since 2.0 + */ + public ExpectContinueMethod(String uri, String tempDir, String tempFile) { + super(uri, tempDir, tempFile); + } + + /** + * Returns the useExpectHeader. + * @return boolean + * + * @since 2.0beta1 + */ + public boolean getUseExpectHeader() { + return this.useExpectHeader; + } + + /** + * Sets the useExpectHeader. + * @param value The useExpectHeader to set + * + * @since 2.0beta1 + */ + public void setUseExpectHeader(boolean value) { + this.useExpectHeader = value; + } + + /** + * Returns true if there is a request body to be sent. + * 'Expect: 100-continue' handshake may not be used if request + * body is not present + * + * @return boolean + * + * @since 2.0beta1 + */ + protected abstract boolean hasRequestContent(); + + /** + * Set the Expect header if it has not already been set, + * in addition to the "standard" set of headers. + * + * @param state the client state + * @param conn the connection to write to + * + * @throws HttpException when a protocol error occurs or state is invalid + * @throws IOException when i/o errors occur reading the response + */ + protected void addRequestHeaders(HttpState state, HttpConnection conn) + throws IOException, HttpException { + LOG.trace("enter ExpectContinueMethod.addRequestHeaders(HttpState, HttpConnection)"); + + super.addRequestHeaders(state, conn); + // If the request is being retried, the header may already be present + boolean headerPresent = (getRequestHeader("Expect") != null); + // See if the expect header should be sent + // = HTTP/1.1 or higher + // = request body present + // = connection is not proxied + + if (getUseExpectHeader() && isHttp11() && hasRequestContent() && + !conn.isProxied()) { + if (!headerPresent) { + setRequestHeader("Expect", "100-continue"); + } + } else { + if (headerPresent) { + removeRequestHeader("Expect"); + } + } + } +} Index: java/org/apache/commons/httpclient/methods/MultipartPostMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v retrieving revision 1.13 diff -u -r1.13 MultipartPostMethod.java --- java/org/apache/commons/httpclient/methods/MultipartPostMethod.java 6 Mar 2003 07:49:03 -0000 1.13 +++ java/org/apache/commons/httpclient/methods/MultipartPostMethod.java 12 Mar 2003 10:08:32 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v 1.13 2003/03/06 07:49:03 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v 1.13 2003/03/06 07:49:03 olegk Exp $ * $Revision: 1.13 $ * $Date: 2003/03/06 07:49:03 $ * @@ -93,7 +93,7 @@ * * @since 2.0 */ -public class MultipartPostMethod extends GetMethod { +public class MultipartPostMethod extends ExpectContinueMethod { /** The Content-Type for multipart/form-data. */ public static final String MULTIPART_FORM_CONTENT_TYPE = @@ -105,10 +105,6 @@ /** The parameters for this method */ private final List parameters = new ArrayList(); - /** This flag specifies whether "expect: 100-continue" handshake is - * to be used prior to sending the request body */ - private boolean useExpectHeader = true; - /** * No-arg constructor. */ @@ -147,27 +143,22 @@ } /** - * Returns "POST". - * @return "POST" - */ - public String getName() { - return "POST"; - } - - /** - * Returns the useExpectHeader. - * @return boolean + * Returns true + * + * @return true + * + * @since 2.0beta1 */ - public boolean getUseExpectHeader() { - return this.useExpectHeader; + protected boolean hasRequestContent() { + return true; } /** - * Sets the useExpectHeader. - * @param value The useExpectHeader to set + * Returns "POST". + * @return "POST" */ - public void setUseExpectHeader(boolean value) { - this.useExpectHeader = value; + public String getName() { + return "POST"; } /** @@ -251,16 +242,6 @@ } setRequestHeader("Content-Type", buffer.toString()); } - boolean headerPresent = (getRequestHeader("Expect") != null); - if (getUseExpectHeader() && isHttp11()) { - if (!headerPresent) { - setRequestHeader("Expect", "100-continue"); - } - } else { - if (headerPresent) { - removeRequestHeader("Expect"); - } - } } /** @@ -314,5 +295,4 @@ super.recycle(); parameters.clear(); } - } Index: test/org/apache/commons/httpclient/TestLocalHostBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestLocalHostBase.java,v retrieving revision 1.3 diff -u -r1.3 TestLocalHostBase.java --- test/org/apache/commons/httpclient/TestLocalHostBase.java 5 Mar 2003 04:02:56 -0000 1.3 +++ test/org/apache/commons/httpclient/TestLocalHostBase.java 12 Mar 2003 10:08:32 -0000 @@ -77,6 +77,8 @@ ); private final String host = System.getProperty("httpclient.test.localHost","localhost"); private final int port; + private final String proxyHost = System.getProperty("httpclient.test.localProxyHost"); + private final int proxyPort; /** * Constructor for TestLocalHostBase. @@ -92,6 +94,14 @@ tempPort = 8080; } port = tempPort; + String proxyPortString = System.getProperty("httpclient.test.localProxyPort","3128"); + int tempProxyPort = 3128; + try { + tempProxyPort = Integer.parseInt(proxyPortString); + } catch(Exception e) { + tempProxyPort = 3128; + } + proxyPort = tempProxyPort; } /** @@ -123,6 +133,9 @@ } client.getHostConfiguration().setHost(host, port, protocol); + if (proxyHost != null) { + client.getHostConfiguration().setProxy(proxyHost, proxyPort); + } return client; }