olegk       2003/07/08 14:24:38

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
  Log:
  Force-close connection feature added. Follow-up to bug #21378
  
  Contributed by Michael Becke & Oleg Kalnichevski
  
  Revision  Changes    Path
  1.162     +38 -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.161
  retrieving revision 1.162
  diff -u -r1.161 -r1.162
  --- HttpMethodBase.java       8 Jul 2003 11:51:45 -0000       1.161
  +++ HttpMethodBase.java       8 Jul 2003 21:24:37 -0000       1.162
  @@ -258,6 +258,9 @@
       /** true if we are finished with the connection */
       private boolean doneWithConnection = false;
   
  +    /** true if the connection must be dropped */
  +    private boolean forceCloseConnection = false;
  +
       /** Number of milliseconds to wait for 100-contunue response. */
       private static final int RESPONSE_WAIT_TIME_MS = 3000;
   
  @@ -843,6 +846,30 @@
       }
   
       /**
  +     * Return <tt>true</tt> if the connection must be dropped due to some 
  +     * abnormal circumstances, <tt>false</tt> if normal decision
  +     * process should take place.
  +     * 
  +     * @return <tt>true</tt> if the connection must be dropped.
  +     */
  +    protected boolean getForceCloseConnection() {
  +        return this.forceCloseConnection;
  +    }
  +
  +    /**
  +     * Set to <tt>true</tt> if the connection must be dropped due to some 
  +     * abnormal circumstances. Set to <tt>false</tt> if normal decision
  +     * process should take place.
  +     * 
  +     * @param b <tt>true</tt> if the connection must be dropped, <tt>false</tt>
  +     * otherwise.
  +     */
  +    protected void setForceCloseConnection(boolean b) {
  +        this.forceCloseConnection = 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 +880,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 (getForceCloseConnection()) {
  +            LOG.debug("Should forcefully close connection.");
               return true;
           }
   
  @@ -1268,6 +1293,7 @@
           recoverableExceptionCount = 0;
           inExecute = false;
           doneWithConnection = false;
  +        forceCloseConnection = false;
       }
   
       /**
  @@ -2053,14 +2079,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
  +                setForceCloseConnection(true);
                   result = is;  
               }
           } else {
               int expectedLength = getResponseContentLength();
               if (expectedLength == -1) {
                   if (canResponseHaveBody(statusLine.getStatusCode())) {
  +                    setForceCloseConnection(true);
                       result = is;            
                   }
               } else {
  
  
  

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

Reply via email to