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/java/org/apache/commons/httpclient/methods EntityEnclosingMethod.java
Date Thu, 06 Feb 2003 15:51:57 GMT
olegk       2003/02/06 07:51:57

  Modified:    httpclient/src/java/org/apache/commons/httpclient/methods
                        EntityEnclosingMethod.java
  Log:
  - fixes "Expect: 100-continue" related bug triggered when authenticating against HTTP/1.0
server
  
  1. -> PUT /file HTTP/1.1
     contains Expect: 100-continue header but disregarded as the server
     needs authentication information
  2. <- HTTP/1.0 401 Unauthorized
     switches isHttp11 flag
  3. Now it tries on loop 2
     -> PUT /file HTTP/1.0 with authorization header
     still contains Expect header, although a warning message about
     HTTP/1.0 not supporting Expect is written out
  4. 3 second timeout occurs, Expect header is removed and body is supposed
     to be sent
  5. The body is not sent through writeRemainingRequestBody() as
     statusLine exists and statusCode is currently 401, and continue
     has not been received.
  6. isRetryNeeded is checked, which causes processAuthenticationResponse
     to find it has already authenticated to this realm (although it
     never got a chance to check it out), and so the request is not
     retried. [A retry with the request now (without Expect header and
     correct authorization) would work.]
  7. 401 Unauthorized is returned as the status.
  
  Bug reported by Rob Owen
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.6       +20 -12    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EntityEnclosingMethod.java	2 Feb 2003 04:30:13 -0000	1.5
  +++ EntityEnclosingMethod.java	6 Feb 2003 15:51:57 -0000	1.6
  @@ -77,6 +77,7 @@
   import org.apache.commons.httpclient.HttpException;
   import org.apache.commons.httpclient.HttpState;
   import org.apache.commons.httpclient.HttpStatus;
  +import org.apache.commons.httpclient.Header;
   import org.apache.commons.httpclient.ChunkedOutputStream;
   import org.apache.commons.httpclient.ContentLengthInputStream;
   import org.apache.commons.logging.Log;
  @@ -356,16 +357,23 @@
       throws IOException, HttpException {
           LOG.trace("enter EntityEnclosingMethod.addRequestHeaders(HttpState, HttpConnection)");
           
  -        if (!isHttp11() && getUseExpectHeader()) {
  -            LOG.warn("100-continue not allowed for HTTP/1.0");
  -        }
  -
           super.addRequestHeaders(state, conn);
  -        // Send expectation header, provided there's something to be sent
  -        if (isHttp11() && getUseExpectHeader() && ((this.requestBodyStream
!= null) 
  -                    || this.buffer != null)) {
  -            if (getRequestHeader("Expect") == null) {
  +        // 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");
  +            } else {
  +                LOG.warn("100-continue not allowed for HTTP/1.0");
               }
           }
       }
  
  
  

---------------------------------------------------------------------
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