442942 Content sent with status 204 (No Content)
This commit is contained in:
parent
060a26ecfe
commit
f07387c703
|
@ -158,6 +158,12 @@ public class HttpGenerator
|
|||
return _endOfContent==EndOfContent.CHUNKED_CONTENT;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isNoContent()
|
||||
{
|
||||
return _noContent;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setPersistent(boolean persistent)
|
||||
{
|
||||
|
|
|
@ -72,7 +72,40 @@ public class HttpGeneratorServerTest
|
|||
assertThat(response, containsString("Content-Length: 10"));
|
||||
assertThat(response, containsString("\r\n0123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test204() throws Exception
|
||||
{
|
||||
ByteBuffer header = BufferUtil.allocate(8096);
|
||||
ByteBuffer content = BufferUtil.toBuffer("0123456789");
|
||||
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
ResponseInfo info = new ResponseInfo(HttpVersion.HTTP_1_1, new HttpFields(), 10, 204, "Foo", false);
|
||||
info.getHttpFields().add("Content-Type", "test/data");
|
||||
info.getHttpFields().add("Last-Modified", DateGenerator.__01Jan1970);
|
||||
|
||||
HttpGenerator.Result result = gen.generateResponse(info, header, null, content, true);
|
||||
|
||||
assertEquals(gen.isNoContent(), true);
|
||||
assertEquals(HttpGenerator.Result.FLUSH, result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING, gen.getState());
|
||||
String responseheaders = BufferUtil.toString(header);
|
||||
BufferUtil.clear(header);
|
||||
|
||||
result = gen.generateResponse(null, null, null, content, false);
|
||||
assertEquals(HttpGenerator.Result.DONE, result);
|
||||
assertEquals(HttpGenerator.State.END, gen.getState());
|
||||
|
||||
assertThat(responseheaders, containsString("HTTP/1.1 204 Foo"));
|
||||
assertThat(responseheaders, containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
|
||||
assertThat(responseheaders, not(containsString("Content-Length: 10")));
|
||||
|
||||
//Note: the HttpConnection.process() method is responsible for actually
|
||||
//excluding the content from the response based on generator.isNoContent()==true
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testComplexChars() throws Exception
|
||||
{
|
||||
|
|
|
@ -620,8 +620,8 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
|||
}
|
||||
case FLUSH:
|
||||
{
|
||||
// Don't write the chunk or the content if this is a HEAD response
|
||||
if (_channel.getRequest().isHead())
|
||||
// Don't write the chunk or the content if this is a HEAD response, or any other type of response that should have no content
|
||||
if (_channel.getRequest().isHead() || _generator.isNoContent())
|
||||
{
|
||||
BufferUtil.clear(chunk);
|
||||
BufferUtil.clear(_content);
|
||||
|
|
Loading…
Reference in New Issue