Author: markt
Date: Wed Sep 30 23:33:27 2015
New Revision: 1706172

URL: http://svn.apache.org/viewvc?rev=1706172&view=rev
Log:
Refactor the expectation flag to move it to the request (since it is a property 
of the request)

Modified:
    tomcat/trunk/java/org/apache/coyote/Request.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java

Modified: tomcat/trunk/java/org/apache/coyote/Request.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Request.java?rev=1706172&r1=1706171&r2=1706172&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/Request.java (original)
+++ tomcat/trunk/java/org/apache/coyote/Request.java Wed Sep 30 23:33:27 2015
@@ -121,6 +121,10 @@ public final class Request {
     private long contentLength = -1;
     private MessageBytes contentTypeMB = null;
     private String charEncoding = null;
+    /**
+     * Is there an expectation ?
+     */
+    private boolean expectation = false;
 
     private final ServerCookies serverCookies = new 
ServerCookies(INITIAL_COOKIE_SIZE);
     private final Parameters parameters = new Parameters();
@@ -344,6 +348,17 @@ public final class Request {
         return headers.getHeader(name);
     }
 
+
+    public void setExpectation(boolean expectation) {
+        this.expectation = expectation;
+    }
+
+
+    public boolean hasExpectation() {
+        return expectation;
+    }
+
+
     // -------------------- Associated response --------------------
 
     public Response getResponse() {
@@ -524,6 +539,7 @@ public final class Request {
         contentLength = -1;
         contentTypeMB = null;
         charEncoding = null;
+        expectation = false;
         headers.recycle();
         serverNameMB.recycle();
         serverPort=-1;

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1706172&r1=1706171&r2=1706172&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Wed Sep 30 
23:33:27 2015
@@ -152,12 +152,6 @@ public class Http11Processor extends Abs
 
 
     /**
-     * Is there an expectation ?
-     */
-    protected boolean expectation = false;
-
-
-    /**
      * Regular expression that defines the restricted user agents.
      */
     protected Pattern restrictedUserAgents = null;
@@ -678,15 +672,13 @@ public class Http11Processor extends Abs
             // Acknowledge request
             // Send a 100 status back if it makes sense (response not committed
             // yet, and client specified an expectation for 100-continue)
-            if ((response.isCommitted()) || !expectation) {
-                return;
-            }
-
-            inputBuffer.setSwallowInput(true);
-            try {
-                outputBuffer.sendAck();
-            } catch (IOException e) {
-                setErrorState(ErrorState.CLOSE_NOW, e);
+            if (!response.isCommitted() && request.hasExpectation()) {
+                inputBuffer.setSwallowInput(true);
+                try {
+                    outputBuffer.sendAck();
+                } catch (IOException e) {
+                    setErrorState(ErrorState.CLOSE_NOW, e);
+                }
             }
             break;
         }
@@ -1227,7 +1219,8 @@ public class Http11Processor extends Abs
 
 
     private void checkExpectationAndResponseStatus() {
-        if (expectation && (response.getStatus() < 200 || response.getStatus() 
> 299)) {
+        if (request.hasExpectation() &&
+                (response.getStatus() < 200 || response.getStatus() > 299)) {
             // Client sent Expect: 100-continue but received a
             // non-2xx final response. Disable keep-alive (if enabled)
             // to ensure that the connection is closed. Some clients may
@@ -1248,7 +1241,6 @@ public class Http11Processor extends Abs
         http11 = true;
         http09 = false;
         contentDelimitation = false;
-        expectation = false;
         sendfileData = null;
 
         if (endpoint.isSSLEnabled()) {
@@ -1307,7 +1299,7 @@ public class Http11Processor extends Abs
         if (expectMB != null) {
             if (expectMB.indexOfIgnoreCase("100-continue", 0) != -1) {
                 inputBuffer.setSwallowInput(false);
-                expectation = true;
+                request.setExpectation(true);
             } else {
                 response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
                 setErrorState(ErrorState.CLOSE_CLEAN, null);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to