444222 replace CRLF in header values with whitespace rather than ?
This commit is contained in:
parent
d60a61288a
commit
40a7d5984e
|
@ -1049,7 +1049,7 @@ public class HttpGenerator
|
|||
char c=s.charAt(i);
|
||||
|
||||
if (c<0 || c>0xff || c=='\r' || c=='\n')
|
||||
buffer.put((byte)'?');
|
||||
buffer.put((byte)' ');
|
||||
else
|
||||
buffer.put((byte)(0xff&c));
|
||||
}
|
||||
|
|
|
@ -156,9 +156,9 @@ public class HttpFieldsTest
|
|||
HttpGenerator.putTo(header,buffer);
|
||||
BufferUtil.flipToFlush(buffer,0);
|
||||
String out = BufferUtil.toString(buffer);
|
||||
assertThat(out,containsString("name0: value??0"));
|
||||
assertThat(out,containsString("name0: value 0"));
|
||||
assertThat(out,containsString("name??1: value1"));
|
||||
assertThat(out,containsString("name?2: value:??2"));
|
||||
assertThat(out,containsString("name?2: value: 2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -32,7 +32,87 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
public class HttpGeneratorServerTest
|
||||
{
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testSimple() throws Exception
|
||||
{
|
||||
ByteBuffer header = BufferUtil.allocate(8096);
|
||||
ByteBuffer content = BufferUtil.toBuffer("0123456789");
|
||||
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
HttpGenerator.Result result = gen.generateResponse(null, null, null, content, true);
|
||||
assertEquals(HttpGenerator.Result.NEED_INFO, result);
|
||||
assertEquals(HttpGenerator.State.START, gen.getState());
|
||||
|
||||
ResponseInfo info = new ResponseInfo(HttpVersion.HTTP_1_1, new HttpFields(), 10, 200, null, false);
|
||||
info.getHttpFields().add("Content-Type", "test/data");
|
||||
info.getHttpFields().add("Last-Modified", DateGenerator.__01Jan1970);
|
||||
|
||||
result = gen.generateResponse(info, null, null, content, true);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER, result);
|
||||
|
||||
result = gen.generateResponse(info, header, null, content, true);
|
||||
assertEquals(HttpGenerator.Result.FLUSH, result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING, gen.getState());
|
||||
String response = BufferUtil.toString(header);
|
||||
BufferUtil.clear(header);
|
||||
response += BufferUtil.toString(content);
|
||||
BufferUtil.clear(content);
|
||||
|
||||
result = gen.generateResponse(null, null, null, content, false);
|
||||
assertEquals(HttpGenerator.Result.DONE, result);
|
||||
assertEquals(HttpGenerator.State.END, gen.getState());
|
||||
|
||||
assertEquals(10, gen.getContentPrepared());
|
||||
|
||||
assertThat(response, containsString("HTTP/1.1 200 OK"));
|
||||
assertThat(response, containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
|
||||
assertThat(response, containsString("Content-Length: 10"));
|
||||
assertThat(response, containsString("\r\n0123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplexChars() throws Exception
|
||||
{
|
||||
ByteBuffer header = BufferUtil.allocate(8096);
|
||||
ByteBuffer content = BufferUtil.toBuffer("0123456789");
|
||||
|
||||
HttpGenerator gen = new HttpGenerator();
|
||||
|
||||
HttpGenerator.Result result = gen.generateResponse(null, null, null, content, true);
|
||||
assertEquals(HttpGenerator.Result.NEED_INFO, result);
|
||||
assertEquals(HttpGenerator.State.START, gen.getState());
|
||||
|
||||
ResponseInfo info = new ResponseInfo(HttpVersion.HTTP_1_1, new HttpFields(), 10, 200, null, false);
|
||||
info.getHttpFields().add("Content-Type", "test/data;\r\nextra=value");
|
||||
info.getHttpFields().add("Last-Modified", DateGenerator.__01Jan1970);
|
||||
|
||||
result = gen.generateResponse(info, null, null, content, true);
|
||||
assertEquals(HttpGenerator.Result.NEED_HEADER, result);
|
||||
|
||||
result = gen.generateResponse(info, header, null, content, true);
|
||||
assertEquals(HttpGenerator.Result.FLUSH, result);
|
||||
assertEquals(HttpGenerator.State.COMPLETING, gen.getState());
|
||||
String response = BufferUtil.toString(header);
|
||||
BufferUtil.clear(header);
|
||||
response += BufferUtil.toString(content);
|
||||
BufferUtil.clear(content);
|
||||
|
||||
result = gen.generateResponse(null, null, null, content, false);
|
||||
assertEquals(HttpGenerator.Result.DONE, result);
|
||||
assertEquals(HttpGenerator.State.END, gen.getState());
|
||||
|
||||
assertEquals(10, gen.getContentPrepared());
|
||||
|
||||
assertThat(response, containsString("HTTP/1.1 200 OK"));
|
||||
assertThat(response, containsString("Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT"));
|
||||
assertThat(response, containsString("Content-Type: test/data; extra=value"));
|
||||
assertThat(response, containsString("Content-Length: 10"));
|
||||
assertThat(response, containsString("\r\n0123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendServerXPoweredBy() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue