You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/06/13 13:26:36 UTC

svn commit: r1602381 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/coyote/http11/AbstractHttp11Processor.java test/org/apache/catalina/startup/SimpleHttpClient.java test/org/apache/coyote/http11/TestAbstractHttp11Processor.java

Author: markt
Date: Fri Jun 13 11:26:36 2014
New Revision: 1602381

URL: http://svn.apache.org/r1602381
Log:
As per RFC2616, an unknown expect header should result in a 417 response.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java
    tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1599500

Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1602381&r1=1602380&r2=1602381&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java Fri Jun 13 11:26:36 2014
@@ -1242,10 +1242,14 @@ public abstract class AbstractHttp11Proc
         if (http11) {
             expectMB = headers.getValue("expect");
         }
-        if ((expectMB != null)
-            && (expectMB.indexOfIgnoreCase("100-continue", 0) != -1)) {
-            getInputBuffer().setSwallowInput(false);
-            expectation = true;
+        if (expectMB != null) {
+            if (expectMB.indexOfIgnoreCase("100-continue", 0) != -1) {
+                getInputBuffer().setSwallowInput(false);
+                expectation = true;
+            } else {
+                error = true;
+                response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
+            }
         }
 
         // Check user-agent header

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java?rev=1602381&r1=1602380&r2=1602381&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java Fri Jun 13 11:26:36 2014
@@ -53,6 +53,7 @@ public abstract class SimpleHttpClient {
     public static final String FAIL_404 = "HTTP/1.1 404";
     public static final String TIMEOUT_408 = "HTTP/1.1 408";
     public static final String FAIL_413 = "HTTP/1.1 413";
+    public static final String FAIL_417 = "HTTP/1.1 417";
     public static final String FAIL_50X = "HTTP/1.1 50";
     public static final String FAIL_500 = "HTTP/1.1 500";
     public static final String FAIL_501 = "HTTP/1.1 501";
@@ -416,6 +417,10 @@ public abstract class SimpleHttpClient {
         return getResponseLine().startsWith(FAIL_413);
     }
 
+    public boolean isResponse417() {
+        return getResponseLine().startsWith(FAIL_417);
+    }
+
     public boolean isResponse50x() {
         return getResponseLine().startsWith(FAIL_50X);
     }

Modified: tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java?rev=1602381&r1=1602380&r2=1602381&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java Fri Jun 13 11:26:36 2014
@@ -53,6 +53,31 @@ import org.apache.tomcat.util.buf.ByteCh
 public class TestAbstractHttp11Processor extends TomcatBaseTest {
 
     @Test
+    public void testWithUnknownExpectation() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        // Use the normal Tomcat ROOT context
+        File root = new File("test/webapp");
+        tomcat.addWebapp("", root.getAbsolutePath());
+
+        tomcat.start();
+
+        String request =
+            "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
+            "Host: any" + SimpleHttpClient.CRLF +
+            "Expect: unknoen" + SimpleHttpClient.CRLF +
+            SimpleHttpClient.CRLF;
+
+        Client client = new Client(tomcat.getConnector().getLocalPort());
+        client.setRequest(new String[] {request});
+
+        client.connect();
+        client.processRequest();
+        assertTrue(client.isResponse417());
+    }
+
+
+    @Test
     public void testWithTEVoid() throws Exception {
         Tomcat tomcat = getTomcatInstance();
 



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


Re: svn commit: r1602381 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/coyote/http11/AbstractHttp11Processor.java test/org/apache/catalina/startup/SimpleHttpClient.java test/org/apache/coyote/http11/TestAbstractHttp11Processor.java

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-06-13 19:16 GMT+04:00 Konstantin Preißer <kp...@apache.org>:
> Hi,
>
>> -----Original Message-----
>> From: markt@apache.org [mailto:markt@apache.org]
>> Sent: Friday, June 13, 2014 1:27 PM
>
>
>> Author: markt
>> Date: Fri Jun 13 11:26:36 2014
>> New Revision: 1602381
>>
>> URL: http://svn.apache.org/r1602381
>> Log:
>> As per RFC2616, an unknown expect header should result in a 417 response.
>
>
> JFYI, according to Mark Notthingham from IETF [1], RFC2616 should not be used any more:
> "Don’t use RFC2616. Delete it from your hard drives, bookmarks, and burn (or responsibly recycle) any copies that are printed out."
>
> New RFCs have been released that clarify HTTP/1.1:
>
> RFC7230 - HTTP/1.1: Message Syntax and Routing
> RFC7231 - HTTP/1.1: Semantics and Content
> RFC7232 - HTTP/1.1: Conditional Requests
> RFC7233 - HTTP/1.1: Range Requests
> RFC7234 - HTTP/1.1: Caching
> RFC7235 - HTTP/1.1: Authentication
>
>
> Regards,
> Konstantin Preißer
>
>
> [1] https://www.mnot.net/blog/2014/06/07/rfc2616_is_dead
>


Thank you for head-ups.

In this particular case the new reference is RFC7231 Section.

The differences that I note are that
a) Only "100-continue" is allowed as the value. The syntax is no more
extensible.
b) "MUST respond with a 417" was replaced with "MAY respond with a 417".

So the code is OK.

[2] http://tools.ietf.org/html/rfc7231#section-5.1.1

Best regards,
Konstantin Kolinko

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


RE: svn commit: r1602381 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/coyote/http11/AbstractHttp11Processor.java test/org/apache/catalina/startup/SimpleHttpClient.java test/org/apache/coyote/http11/TestAbstractHttp11Processor.java

Posted by Konstantin Preißer <kp...@apache.org>.
Hi,

> -----Original Message-----
> From: markt@apache.org [mailto:markt@apache.org]
> Sent: Friday, June 13, 2014 1:27 PM


> Author: markt
> Date: Fri Jun 13 11:26:36 2014
> New Revision: 1602381
> 
> URL: http://svn.apache.org/r1602381
> Log:
> As per RFC2616, an unknown expect header should result in a 417 response.


JFYI, according to Mark Notthingham from IETF [1], RFC2616 should not be used any more:
"Don’t use RFC2616. Delete it from your hard drives, bookmarks, and burn (or responsibly recycle) any copies that are printed out."

New RFCs have been released that clarify HTTP/1.1:

RFC7230 - HTTP/1.1: Message Syntax and Routing
RFC7231 - HTTP/1.1: Semantics and Content
RFC7232 - HTTP/1.1: Conditional Requests
RFC7233 - HTTP/1.1: Range Requests
RFC7234 - HTTP/1.1: Caching
RFC7235 - HTTP/1.1: Authentication


Regards,
Konstantin Preißer


[1] https://www.mnot.net/blog/2014/06/07/rfc2616_is_dead


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