use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testIPv6HostPort.
@Test
public void testIPv6HostPort() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.1\r\n" + "Host: [::1]:8888\r\n" + "Connection: close\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals("[::1]", _host);
Assert.assertEquals(8888, _port);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testResponseParse2.
@Test
public void testResponseParse2() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("HTTP/1.1 204 No-Content\r\n" + "Header: value\r\n" + "\r\n" + "HTTP/1.1 200 Correct\r\n" + "Content-Length: 10\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "0123456789\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals("HTTP/1.1", _methodOrVersion);
Assert.assertEquals("204", _uriOrStatus);
Assert.assertEquals("No-Content", _versionOrReason);
Assert.assertTrue(_headerCompleted);
Assert.assertTrue(_messageCompleted);
parser.reset();
init();
parser.parseNext(buffer);
parser.atEOF();
Assert.assertEquals("HTTP/1.1", _methodOrVersion);
Assert.assertEquals("200", _uriOrStatus);
Assert.assertEquals("Correct", _versionOrReason);
Assert.assertEquals(_content.length(), 10);
Assert.assertTrue(_headerCompleted);
Assert.assertTrue(_messageCompleted);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testNoValue.
@Test
public void testNoValue() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.0\r\n" + "Host: localhost\r\n" + "Name0: \r\n" + "Name1:\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
Assert.assertTrue(_headerCompleted);
Assert.assertTrue(_messageCompleted);
Assert.assertEquals("GET", _methodOrVersion);
Assert.assertEquals("/", _uriOrStatus);
Assert.assertEquals("HTTP/1.0", _versionOrReason);
Assert.assertEquals("Host", _hdr[0]);
Assert.assertEquals("localhost", _val[0]);
Assert.assertEquals("Name0", _hdr[1]);
Assert.assertEquals("", _val[1]);
Assert.assertEquals("Name1", _hdr[2]);
Assert.assertEquals("", _val[2]);
Assert.assertEquals(2, _headers);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testLineParse1.
@Test
public void testLineParse1() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET /999\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
Assert.assertEquals("HTTP/0.9 not supported", _bad);
Assert.assertNull(_complianceViolation);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testIPHost.
@Test
public void testIPHost() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET / HTTP/1.1\r\n" + "Host: 192.168.0.1\r\n" + "Connection: close\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals("192.168.0.1", _host);
Assert.assertEquals(0, _port);
}
Aggregations