From b12bdbc06e2d5de6141b9ae2215914c742ecef18 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Sat, 27 Mar 2010 19:56:53 +0000 Subject: [PATCH] 306782 Do not skip content if 100 not sent, but content available git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1416 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../eclipse/jetty/server/HttpConnection.java | 16 +++++++-- .../jetty/test/rfcs/RFC2616BaseTest.java | 35 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 431d1f0b3bb..3df40d1eb09 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -4,6 +4,7 @@ jetty-7.0.2.SNAPSHOT + 306840 Suppress content-length in requests with no content + 306880 Support for UPGRADE in HttpClient + 306884 Suspend with timeout <=0 never expires + + 306782 Don't skip content if 100 not sent, but content available jetty-7.0.2.RC0 + JSON parses NaN as null diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 420eb3d9d9b..8ee4a6bb26a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -638,10 +638,22 @@ public class HttpConnection implements Connection if (_expect100Continue) { - // Continue not sent so don't parse any content + // We didn't send a 100 continues, but if there is + // content, then the client obviously ignored us and + // we need to read it. If there is no content, then + // we should not expect any to arrive and should skip + // it _expect100Continue = false; if (_parser instanceof HttpParser) - ((HttpParser)_parser).setState(HttpParser.STATE_END); + { + HttpParser parser=(HttpParser)_parser; + + // is there already content? + if ((parser.getHeaderBuffer()==null || parser.getHeaderBuffer().length()<2) && + (parser.getBodyBuffer()==null || parser.getBodyBuffer().length()<1)) + // No - so let's not expect it. + ((HttpParser)_parser).setState(HttpParser.STATE_END); + } } if(_endp.isOpen()) diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java index 3d912b03cbb..984191c1755 100644 --- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java +++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/rfcs/RFC2616BaseTest.java @@ -693,6 +693,41 @@ public abstract class RFC2616BaseTest extends AbstractJettyTestCase response.assertStatusOK("8.2.3 expect 100"); } + /** + * Test Message Transmission Requirements -- Acceptable bad client behavior, Expect 100 with body content. + * + * @see RFC 2616 (section 8.2) + */ + @Test + public void test8_2_UnexpectWithBody() throws Exception + { + // Expect with body + + StringBuffer req3 = new StringBuffer(); + req3.append("GET /redirect/R1 HTTP/1.1\n"); + req3.append("Host: localhost\n"); + req3.append("Expect: 100-continue\n"); // Valid Expect header. + req3.append("Content-Type: text/plain\n"); + req3.append("Content-Length: 8\n"); + req3.append("\n"); + req3.append("123456\r\n"); + req3.append("GET /echo/R1 HTTP/1.1\n"); + req3.append("Host: localhost\n"); + req3.append("Content-Type: text/plain\n"); + req3.append("Content-Length: 8\n"); + req3.append("Connection: close\n"); + req3.append("\n"); + req3.append("87654321"); // Body + + List responses = http.requests(req3); + + response=responses.get(0); + response.assertStatus("8.2.3 ignored no 100",302); + + response=responses.get(1); + response.assertStatus("8.2.3 ignored no 100",200); + response.assertBody("87654321\n"); + } /** * Test Message Transmission Requirements