commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestLocalHostBase.java
Date Wed, 12 Mar 2003 22:13:16 GMT
olegk       2003/03/12 14:13:16

  Modified:    httpclient/src/java/org/apache/commons/httpclient/methods
                        EntityEnclosingMethod.java MultipartPostMethod.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestLocalHostBase.java
  Log:
  Changelog:
  - 'Expect: 100-continue' functions refactored into an abstract ExpectContinueMethod class.
  - 'Expect: 100-continue' handshake is not used when sending requests via a proxy
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.13      +17 -58    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java
  
  Index: EntityEnclosingMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- EntityEnclosingMethod.java	6 Mar 2003 07:49:03 -0000	1.12
  +++ EntityEnclosingMethod.java	12 Mar 2003 22:13:15 -0000	1.13
  @@ -92,7 +92,7 @@
    * @since 2.0beta1
    * @version $Revision$
    */
  -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 <tt>true</tt> 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 <tt>Expect</tt> 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}
  
  
  
  1.14      +15 -35    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java
  
  Index: MultipartPostMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MultipartPostMethod.java	6 Mar 2003 07:49:03 -0000	1.13
  +++ MultipartPostMethod.java	12 Mar 2003 22:13:15 -0000	1.14
  @@ -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 <tt>"POST"</tt>.
  -     * @return <tt>"POST"</tt>
  -     */
  -    public String getName() {
  -        return "POST";
  -    }
  -
  -    /**
  -     * Returns the useExpectHeader.
  -     * @return boolean
  +     * Returns <tt>true</tt> 
  +     * 
  +     * @return <tt>true</tt>
  +     * 
  +     * @since 2.0beta1
        */
  -    public boolean getUseExpectHeader() {
  -        return this.useExpectHeader;
  +    protected boolean hasRequestContent() {
  +        return true;
       }
   
       /**
  -     * Sets the useExpectHeader.
  -     * @param value The useExpectHeader to set
  +     * Returns <tt>"POST"</tt>.
  +     * @return <tt>"POST"</tt>
        */
  -    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();
       }
  -
   }
  
  
  
  1.4       +16 -3     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestLocalHostBase.java
  
  Index: TestLocalHostBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestLocalHostBase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestLocalHostBase.java	5 Mar 2003 04:02:56 -0000	1.3
  +++ TestLocalHostBase.java	12 Mar 2003 22:13:15 -0000	1.4
  @@ -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.proxy.host");
  +    private final int proxyPort;
       
       /**
        * Constructor for TestLocalHostBase.
  @@ -92,6 +94,14 @@
               tempPort = 8080;
           }
           port = tempPort;
  +        String proxyPortString = System.getProperty("httpclient.test.proxy.port","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;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message