Issue #1116 Allow empty HTTP header value

This commit is contained in:
Greg Wilkins 2017-08-30 16:42:47 +10:00
parent bd111264f5
commit eb1320f56c
2 changed files with 41 additions and 4 deletions

View File

@ -560,10 +560,6 @@ public class HttpGenerator
for (int f=0;f<n;f++) for (int f=0;f<n;f++)
{ {
HttpField field = trailer.getField(f); HttpField field = trailer.getField(f);
String v = field.getValue();
if (v==null || v.length()==0)
continue; // rfc7230 does not allow no value
putTo(field,buffer); putTo(field,buffer);
} }

View File

@ -79,6 +79,47 @@ public class HttpGeneratorClientTest
Assert.assertThat(out, Matchers.not(Matchers.containsString("Content-Length"))); Assert.assertThat(out, Matchers.not(Matchers.containsString("Content-Length")));
} }
@Test
public void testEmptyHeaders() throws Exception
{
ByteBuffer header=BufferUtil.allocate(2048);
HttpGenerator gen = new HttpGenerator();
HttpGenerator.Result
result=gen.generateRequest(null,null,null,null, true);
Assert.assertEquals(HttpGenerator.Result.NEED_INFO, result);
Assert.assertEquals(HttpGenerator.State.START, gen.getState());
Info info = new Info("GET","/index.html");
info.getFields().add("Host","something");
info.getFields().add("Null",null);
info.getFields().add("Empty","");
Assert.assertTrue(!gen.isChunking());
result=gen.generateRequest(info,null,null,null, true);
Assert.assertEquals(HttpGenerator.Result.NEED_HEADER, result);
Assert.assertEquals(HttpGenerator.State.START, gen.getState());
result=gen.generateRequest(info,header,null,null, true);
Assert.assertEquals(HttpGenerator.Result.FLUSH, result);
Assert.assertEquals(HttpGenerator.State.COMPLETING, gen.getState());
Assert.assertTrue(!gen.isChunking());
String out = BufferUtil.toString(header);
BufferUtil.clear(header);
result=gen.generateResponse(null,false,null,null, null, false);
Assert.assertEquals(HttpGenerator.Result.DONE, result);
Assert.assertEquals(HttpGenerator.State.END, gen.getState());
Assert.assertTrue(!gen.isChunking());
Assert.assertEquals(0, gen.getContentPrepared());
Assert.assertThat(out, Matchers.containsString("GET /index.html HTTP/1.1"));
Assert.assertThat(out, Matchers.not(Matchers.containsString("Content-Length")));
Assert.assertThat(out, Matchers.containsString("Empty:"));
Assert.assertThat(out, Matchers.not(Matchers.containsString("Null:")));
}
@Test @Test
public void testPOSTRequestNoContent() throws Exception public void testPOSTRequestNoContent() throws Exception
{ {