Issue #786 Buffering Response Handler

Fixed commit of empty buffers
This commit is contained in:
Greg Wilkins 2016-08-10 16:01:56 +10:00
parent a9653e2f49
commit cc8c3590c0
2 changed files with 19 additions and 1 deletions

View File

@ -282,7 +282,9 @@ public class BufferedResponseHandler extends HandlerWrapper
protected void commit(Queue<ByteBuffer> buffers, Callback callback)
{
// If only 1 buffer
if (_buffers.size()==1)
if (_buffers.size()==0)
getNextInterceptor().write(BufferUtil.EMPTY_BUFFER,true,callback);
else if (_buffers.size()==1)
// just flush it with the last callback
getNextInterceptor().write(_buffers.remove(),true,callback);
else

View File

@ -204,6 +204,22 @@ public class BufferedResponseHandlerTest
assertThat(response,containsString("Written: true"));
}
@Test
public void testFlushEmpty() throws Exception
{
_test._writes=1;
_test._flush=true;
_test._close=false;
_test._content = new byte[0];
String response = _local.getResponse("GET /ctx/include/path HTTP/1.1\r\nHost: localhost\r\n\r\n");
System.err.println(response);
assertThat(response,containsString(" 200 OK"));
assertThat(response,containsString("Content-Length: "));
assertThat(response,containsString("Write: 0"));
assertThat(response,not(containsString("Write: 1")));
assertThat(response,containsString("Written: true"));
}
public static class TestHandler extends AbstractHandler
{
int _bufferSize;