Issue #1116 Allow empty HTTP header value
This commit is contained in:
parent
bd111264f5
commit
eb1320f56c
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue