remm        2004/06/01 07:34:22

  Modified:    http11/src/java/org/apache/coyote/http11
                        Http11Processor.java InternalInputBuffer.java
  Log:
  - Bug 29166: Tweak expectation handling so that if the expectation isn't satisfied,
    we don't attempt to swallow the request's body (with a good client, it shouldn't
    have been sent). Hopefully I'm not breaking anything.
  - Test requests (use telnet and a tomcat/tomcat user):
  GET /manager/list HTTP/1.1
  Host: localhost:8080
  Expect: 100-continue
  Content-Length: 10
  
  GET /manager/list HTTP/1.1
  Host: localhost:8080
  Authorization: Basic dG9tY2F0OnRvbWNhdA==
  Expect: 100-continue
  Content-Length: 10
  
  1234567890
  
  Revision  Changes    Path
  1.100     +23 -11    
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java
  
  Index: Http11Processor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v
  retrieving revision 1.99
  retrieving revision 1.100
  diff -u -r1.99 -r1.100
  --- Http11Processor.java      30 Mar 2004 21:50:11 -0000      1.99
  +++ Http11Processor.java      1 Jun 2004 14:34:22 -0000       1.100
  @@ -171,6 +171,12 @@
   
   
       /**
  +     * Is there an expectation ?
  +     */
  +    protected boolean expectation = false;
  +
  +
  +    /**
        * List of restricted user agents.
        */
       protected RE[] restrictedUserAgents = null;
  @@ -898,19 +904,15 @@
               // Send a 100 status back if it makes sense (response not committed
               // yet, and client specified an expectation for 100-continue)
   
  -            if ((response.isCommitted()) || (!http11))
  +            if ((response.isCommitted()) || !expectation)
                   return;
   
  -            MessageBytes expectMB = 
  -                request.getMimeHeaders().getValue("expect");
  -            if ((expectMB != null)
  -                && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) {
  -                try {
  -                    outputBuffer.sendAck();
  -                } catch (IOException e) {
  -                    // Set error flag
  -                    error = true;
  -                }
  +            inputBuffer.setSwallowInput(true);
  +            try {
  +                outputBuffer.sendAck();
  +            } catch (IOException e) {
  +                // Set error flag
  +                error = true;
               }
   
           } else if (actionCode == ActionCode.ACTION_CLIENT_FLUSH) {
  @@ -1092,6 +1094,7 @@
           http11 = true;
           http09 = false;
           contentDelimitation = false;
  +        expectation = false;
           if (sslSupport != null) {
               request.scheme().setString("https");
           }
  @@ -1134,6 +1137,15 @@
                                    Constants.KEEPALIVE_BYTES) != -1) {
                   keepAlive = true;
               }
  +        }
  +
  +        MessageBytes expectMB = null;
  +        if (http11)
  +            expectMB = request.getMimeHeaders().getValue("expect");
  +        if ((expectMB != null)
  +            && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) {
  +            inputBuffer.setSwallowInput(false);
  +            expectation = true;
           }
   
           // Check user-agent header
  
  
  
  1.18      +18 -1     
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java
  
  Index: InternalInputBuffer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalInputBuffer.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- InternalInputBuffer.java  24 Feb 2004 08:50:56 -0000      1.17
  +++ InternalInputBuffer.java  1 Jun 2004 14:34:22 -0000       1.18
  @@ -75,6 +75,7 @@
           lastActiveFilter = -1;
   
           parsingHeader = true;
  +        swallowInput = true;
   
       }
   
  @@ -111,6 +112,12 @@
   
   
       /**
  +     * Swallow input ? (in the case of an expectation)
  +     */
  +    protected boolean swallowInput;
  +
  +
  +    /**
        * Pointer to the current read buffer.
        */
       protected byte[] buf;
  @@ -277,6 +284,14 @@
       }
   
   
  +    /**
  +     * Set the swallow input flag.
  +     */
  +    public void setSwallowInput(boolean swallowInput) {
  +        this.swallowInput = swallowInput;
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -295,6 +310,7 @@
           pos = 0;
           lastActiveFilter = -1;
           parsingHeader = true;
  +        swallowInput = true;
   
       }
   
  @@ -335,6 +351,7 @@
           pos = 0;
           lastActiveFilter = -1;
           parsingHeader = true;
  +        swallowInput = true;
   
       }
   
  @@ -347,7 +364,7 @@
       public void endRequest()
           throws IOException {
   
  -        if (lastActiveFilter != -1) {
  +        if (swallowInput && (lastActiveFilter != -1)) {
               int extraBytes = (int) activeFilters[lastActiveFilter].end();
               pos = pos - extraBytes;
           }
  
  
  

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

Reply via email to