olegk       2003/07/08 15:05:25

  Modified:    httpclient/src/java/org/apache/commons/httpclient Tag:
                        HTTPCLIENT_2_0_BRANCH HttpMethodBase.java
  Log:
  Adds a feature to force-close connection in abnormal circumstances. Follow up to bug 
fix #21378
  
  Contributed by Michael Becke & Oleg Kalnichevski
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.159.2.2 +35 -10    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.159.2.1
  retrieving revision 1.159.2.2
  diff -u -r1.159.2.1 -r1.159.2.2
  --- HttpMethodBase.java       8 Jul 2003 11:47:15 -0000       1.159.2.1
  +++ HttpMethodBase.java       8 Jul 2003 22:05:25 -0000       1.159.2.2
  @@ -258,6 +258,9 @@
       /** true if we are finished with the connection */
       private boolean doneWithConnection = false;
   
  +    /** true if the connection must be closed when no longer needed */
  +    private boolean connectionCloseForced = false;
  +
       /** Number of milliseconds to wait for 100-contunue response. */
       private static final int RESPONSE_WAIT_TIME_MS = 3000;
   
  @@ -843,6 +846,27 @@
       }
   
       /**
  +     * Tests if the connection should be force-closed when no longer needed.
  +     * 
  +     * @return <code>true</code> if the connection must be closed
  +     */
  +    protected boolean isConnectionCloseForced() {
  +        return this.connectionCloseForced;
  +    }
  +
  +    /**
  +     * Sets whether or not the connection should be force-closed when no longer 
  +     * needed. This value should only be set to <code>true</code> in abnormal 
  +     * circumstances. 
  +     * 
  +     * @param b <code>true</code> if the connection must be closed, 
<code>false</code>
  +     * otherwise.
  +     */
  +    protected void setConnectionCloseForced(boolean b) {
  +        this.connectionCloseForced = b;
  +    }
  +
  +    /**
        * Return true if we should close the connection now.  The connection will
        * only be left open if we are using HTTP1.1 or if "Connection: keep-alive" 
        * was sent.
  @@ -853,11 +877,9 @@
        */
       protected boolean shouldCloseConnection(HttpConnection conn) {
   
  -        // if we are not chunked and there is no content length the connection
  -        // cannot be reused
  -        if (responseHeaders.getFirstHeader("Transfer-Encoding") == null 
  -            && getResponseContentLength() < 0) {
  -            LOG.debug("Should close connection as content-length is missing.");
  +        // Connection must be closed due to an abnormal circumstance 
  +        if (isConnectionCloseForced()) {
  +            LOG.debug("Should forcefully close connection.");
               return true;
           }
   
  @@ -1268,6 +1290,7 @@
           recoverableExceptionCount = 0;
           inExecute = false;
           doneWithConnection = false;
  +        connectionCloseForced = false;
       }
   
       /**
  @@ -2053,14 +2076,16 @@
                       LOG.warn("Transfer-Encoding is set but does not contain 
\"chunked\": "
                           + getResponseHeader("Transfer-Encoding"));
                   }
  -                // we assume that the response connection will be terminated by 
closing 
  +                // The connection must be terminated by closing 
                   // the socket as per RFC 2616, 3.6
  +                setConnectionCloseForced(true);
                   result = is;  
               }
           } else {
               int expectedLength = getResponseContentLength();
               if (expectedLength == -1) {
                   if (canResponseHaveBody(statusLine.getStatusCode())) {
  +                    setConnectionCloseForced(true);
                       result = is;            
                   }
               } else {
  
  
  

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

Reply via email to