Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2011-12-19 23:55:56 +0000
committerGreg Wilkins2011-12-19 23:55:56 +0000
commitb7d8bd4f28160120a8edb1316db5940837d52199 (patch)
tree4788fbeb207ff4b3fcd94ab9cf20785677247991
parentc5c6377e26dff5f99a91fadf1029cc5074cd4ad4 (diff)
downloadorg.eclipse.jetty.project-b7d8bd4f28160120a8edb1316db5940837d52199.tar.gz
org.eclipse.jetty.project-b7d8bd4f28160120a8edb1316db5940837d52199.tar.xz
org.eclipse.jetty.project-b7d8bd4f28160120a8edb1316db5940837d52199.zip
364638 HttpParser closes if data received while seeking EOF. Tests fixed to cope
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/TimeoutTest.java17
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java31
-rw-r--r--jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java30
-rw-r--r--test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java8
4 files changed, 69 insertions, 17 deletions
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/TimeoutTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/TimeoutTest.java
index abe37a7f66..4aefca5514 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/TimeoutTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/TimeoutTest.java
@@ -217,7 +217,6 @@ public class TimeoutTest
* The connection should be closed by the server
*/
@Test
- @Ignore
public void testServerCloseClientMoreDataSent() throws Exception
{
// Log.getLogger("").setDebugEnabled(true);
@@ -387,6 +386,22 @@ public class TimeoutTest
Assert.assertTrue("close not received",serverEndPoint.get().isInputShutdown());
Assert.assertEquals("one request handled",1,httpRequests.get());
+
+
+ // client will eventually get broken pipe if it keeps writing
+ try
+ {
+ for (int i=0;i<1000;i++)
+ {
+ clientOutput.write(req.toString().getBytes("UTF-8"));
+ clientOutput.flush();
+ }
+ Assert.fail("Client should have seen a broken pipe");
+ }
+ catch(IOException e)
+ {
+ // expected broken pipe
+ }
}
finally
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
index 046430a0b3..f732717740 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
@@ -968,24 +968,27 @@ public class HttpParser implements Parser
}
case STATE_SEEKING_EOF:
- {
- _buffer.clear();
- break;
-
- /*
- System.err.println("Seeking EOF read "+_buffer);
- if (_buffer!=null)
+ {
+ // Close if there is more data than CRLF
+ if (_buffer.length()>2)
{
- ch=_buffer.get();
- if (Character.isWhitespace(ch))
- break;
-
- // rubbish data sent, so let's close the connection
- _buffer.clear();
+ _state=STATE_END;
_endp.close();
}
+ else
+ {
+ // or if the data is not white space
+ while (_buffer.length()>0)
+ if (!Character.isWhitespace(_buffer.get()))
+ {
+ _state=STATE_END;
+ _endp.close();
+ _buffer.clear();
+ }
+ }
+
+ _buffer.clear();
break;
- */
}
}
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
index 85cf15c202..e861721de0 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
@@ -510,6 +510,36 @@ public class HttpParserTest
assertTrue(messageCompleted);
}
+ @Test
+ public void testSeekEOF() throws Exception
+ {
+ StringEndPoint io=new StringEndPoint();
+ io.setInput(
+ "HTTP/1.1 200 OK\015\012"
+ + "Content-Length: 0\015\012"
+ + "Connection: close\015\012"
+ + "\015\012"
+ + "\015\012" // extra CRLF ignored
+ + "HTTP/1.1 400 OK\015\012"); // extra data causes close
+
+
+ ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
+ SimpleBuffers buffers=new SimpleBuffers(buffer,null);
+
+ Handler handler = new Handler();
+ HttpParser parser= new HttpParser(buffers,io, handler);
+
+ parser.parse();
+ assertEquals("HTTP/1.1", f0);
+ assertEquals("200", f1);
+ assertEquals("OK", f2);
+ assertEquals(null,_content);
+ assertTrue(headerCompleted);
+ assertTrue(messageCompleted);
+
+
+ }
+
private String _content;
private String f0;
private String f1;
diff --git a/test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java b/test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java
index 2049dc1fc0..f7b516ef76 100644
--- a/test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java
+++ b/test-continuation/src/main/java/org/eclipse/jetty/continuation/test/ContinuationBase.java
@@ -233,9 +233,13 @@ public abstract class ContinuationBase extends TestCase
request+=" HTTP/1.1\r\n"+
"Host: localhost\r\n"+
"Connection: close\r\n";
- if (content!=null)
+ if (content==null)
+ request+="\r\n";
+ else
+ {
request+="Content-Length: "+content.length()+"\r\n";
- request+="\r\n" + content;
+ request+="\r\n" + content;
+ }
int port=_port;
String response=null;

Back to the top