364638 HttpParser closes if data received while seeking EOF. Tests fixed to cope
This commit is contained in:
parent
c5c6377e26
commit
b7d8bd4f28
|
@ -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);
|
||||
|
@ -388,6 +387,22 @@ public class TimeoutTest
|
|||
|
||||
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
|
||||
{
|
||||
|
|
|
@ -969,23 +969,26 @@ 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;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
int port=_port;
|
||||
String response=null;
|
||||
|
|
Loading…
Reference in New Issue