remm        01/05/19 15:37:05

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpClient.java
  Log:
  - The output will only be closed when necessary (instead of just whenever the
    client wasn't in HTTP/1.1 mode). This fixes problems with some HTTP servers.
  - Also, openConnection will no longer retry after getting an IOException when
    trying to open the connection; it will now rethow the IOException after resetting
    the socket. This also fixes a bug where the SSL socket would be reopened in
    non-SSL mode.
  
  Revision  Changes    Path
  1.14      +39 -20    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
  
  Index: HttpClient.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- HttpClient.java   2001/05/17 23:58:51     1.13
  +++ HttpClient.java   2001/05/19 22:37:04     1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
 1.13 2001/05/17 23:58:51 rwaldhoff Exp $
  - * $Revision: 1.13 $
  - * $Date: 2001/05/17 23:58:51 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
 1.14 2001/05/19 22:37:04 remm Exp $
  + * $Revision: 1.14 $
  + * $Date: 2001/05/19 22:37:04 $
    *
    * ====================================================================
    *
  @@ -91,7 +91,8 @@
    * in your JRE's <tt>java.security</tt> file) and with the
    * VM that is running the HttpClient (e.g., set the
    * system property <tt>java.protocol.handler.pkgs</tt>
  - * to include your provider, such as <tt>com.sun.net.ssl.internal.www.protocol</tt>
  + * to include your provider, such as 
  + * <tt>com.sun.net.ssl.internal.www.protocol</tt>
    * for the reference implementation of JSSE).
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  @@ -140,6 +141,7 @@
           //startSession();
       }
   
  +
       /**
        *
        * <b>Note:</b> The HttpClient constructors used to
  @@ -154,6 +156,7 @@
           setCredentials(new Credentials(user, password));
       }
   
  +
       /**
        * <b>Note:</b> The HttpClient constructor used to
        * implicitly start a session.  That behavior has been
  @@ -427,7 +430,7 @@
                       connectionInterceptor.sentRequest();
                   }
   
  -                boolean closeOutput = needToCloseOutput();
  +                boolean closeOutput = needToCloseOutput(method);
                   if (closeOutput) {
                       try {
                           Class[] paramsClasses = new Class[0];
  @@ -644,6 +647,10 @@
           startSession(host,port,false);
       }
   
  +
  +    /**
  +     * Start a session.
  +     */
       public void startSession(String host, int port, boolean https) {
           if (debug > 0)
               System.out.println("Start session : Host:" + host
  @@ -657,6 +664,7 @@
   
       }
   
  +
       /**
        * Start a session.
        */
  @@ -664,10 +672,12 @@
           startSession(host,port,creds,false);
       }
   
  +
       /**
        * Start a session.
        */
  -    public void startSession(String host, int port, Credentials creds, boolean 
https) {
  +    public void startSession(String host, int port, Credentials creds, 
  +                             boolean https) {
           if (debug > 0)
               System.out.println("Start session : Host:" + host
                                   + " Port:" + port
  @@ -681,6 +691,7 @@
   
       }
   
  +
       /**
        * Start a session.  When starting a session, only the
        * protocol, hostname and port are considered.  The path must still
  @@ -691,14 +702,18 @@
        */
       public void startSession(URL url) {
         if("https".equalsIgnoreCase(url.getProtocol())) {
  -        startSession(url.getHost(), url.getPort() == -1 ? 443 : url.getPort(),true);
  +        startSession(url.getHost(), url.getPort() == -1 ? 443 
  +                     : url.getPort(),true);
         } else if("http".equalsIgnoreCase(url.getProtocol())) {
  -        startSession(url.getHost(), url.getPort() == -1 ? 80 : url.getPort(),false);
  +        startSession(url.getHost(), url.getPort() == -1 ? 80 
  +                     : url.getPort(),false);
         } else {
  -          throw new IllegalArgumentException("Protocol " + url.getProtocol() + " 
not supported in URL " + url);
  +          throw new IllegalArgumentException("Protocol " + url.getProtocol() 
  +                                             + " not supported in URL " + url);
         }
       }
   
  +
       /**
        * Start a session.  When starting a session, only the
        * hostname and port are considered.  The path must still
  @@ -712,6 +727,7 @@
         startSession(url.getHost(), url.getPort() == -1 ? 80 : url.getPort());
       }
   
  +
       /**
        * End a session.
        */
  @@ -742,7 +758,8 @@
                       System.out.println("Reopen connection : Host:"
                                          + sessionHost + " Port:" + sessionPort);
                   if(https) {
  -                    socket = 
SSLSocketFactory.getDefault().createSocket(this.sessionHost, this.sessionPort);
  +                    socket = SSLSocketFactory.getDefault().createSocket
  +                        (this.sessionHost, this.sessionPort);
                   } else {
                       socket = new Socket(this.sessionHost, this.sessionPort);
                   }
  @@ -761,12 +778,7 @@
                   socket = null;
               }
   
  -            if (debug > 0)
  -                System.out.println("Reopen connection after IOException: Host:"
  -                    + sessionHost + " Port:" + sessionPort);
  -            socket = new Socket(this.sessionHost, this.sessionPort);
  -            input = socket.getInputStream();
  -            output = socket.getOutputStream();
  +            throw e;
           }
   
           if (connectionInterceptor != null) {
  @@ -1137,11 +1149,18 @@
        * Return true if the connection should be closed after sending the
        * request.
        */
  -    protected boolean needToCloseOutput() {
  -        if (!http11)
  -            return true;
  -        else
  +    protected boolean needToCloseOutput(HttpMethod method) {
  +        if (!http11) {
  +            if ((method.isStreamedQuery()) 
  +                && (method.getHeader("Content-Length") == null)
  +                && (method.needContentLength())) {
  +                return true;
  +            } else {
  +                return false;
  +            }
  +        } else {
               return false;
  +        }
       }
   
   
  
  
  

Reply via email to