use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testNoHost.
@Test
public void testNoHost() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.1\r\n" + "Connection: close\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals("No Host", _bad);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testCachedField.
@Test
public void testCachedField() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.1\r\n" + "Host: www.smh.com.au\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
Assert.assertEquals("www.smh.com.au", parser.getFieldCache().get("Host: www.smh.com.au").getValue());
HttpField field = _fields.get(0);
buffer.position(0);
parseAll(parser, buffer);
Assert.assertTrue(field == _fields.get(0));
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testEmptyHostPort.
@Test
public void testEmptyHostPort() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.1\r\n" + "Host:\r\n" + "Connection: close\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals(null, _host);
Assert.assertEquals(null, _bad);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testFoldedField7230.
@Test
public void testFoldedField7230() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.0\r\n" + "Host: localhost\r\n" + "Name: value\r\n" + " extra\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler, 4096, HttpCompliance.RFC7230);
parseAll(parser, buffer);
Assert.assertThat(_bad, Matchers.notNullValue());
Assert.assertThat(_bad, Matchers.containsString("Header Folding"));
Assert.assertNull(_complianceViolation);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testBadContentLength1.
@Test
public void testBadContentLength1() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.0\r\n" + "Content-Length: 9999999999999999999999999999999999999999999999\r\n" + "Connection: close\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals("GET", _methodOrVersion);
Assert.assertEquals("Invalid Content-Length Value", _bad);
Assert.assertFalse(buffer.hasRemaining());
Assert.assertEquals(HttpParser.State.CLOSE, parser.getState());
parser.atEOF();
parser.parseNext(BufferUtil.EMPTY_BUFFER);
Assert.assertEquals(HttpParser.State.CLOSED, parser.getState());
}
Aggregations