use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testTransferEncodingChunkedThenContentLength.
@Test
public void testTransferEncodingChunkedThenContentLength() {
ByteBuffer buffer = BufferUtil.toBuffer("POST /chunk HTTP/1.1\r\n" + "Host: localhost\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Length: 1\r\n" + "\r\n" + "1\r\n" + "X\r\n" + "0\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
Assert.assertEquals("POST", _methodOrVersion);
Assert.assertEquals("/chunk", _uriOrStatus);
Assert.assertEquals("HTTP/1.1", _versionOrReason);
Assert.assertEquals("X", _content);
Assert.assertTrue(_headerCompleted);
Assert.assertTrue(_messageCompleted);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testChunkParseNoTrailer.
@Test
public void testChunkParseNoTrailer() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET /chunk HTTP/1.0\r\n" + "Header1: value1\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "a;\r\n" + "0123456789\r\n" + "1a\r\n" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + "0\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
parser.atEOF();
parser.parseNext(BufferUtil.EMPTY_BUFFER);
Assert.assertEquals("GET", _methodOrVersion);
Assert.assertEquals("/chunk", _uriOrStatus);
Assert.assertEquals("HTTP/1.0", _versionOrReason);
Assert.assertEquals(1, _headers);
Assert.assertEquals("Header1", _hdr[0]);
Assert.assertEquals("value1", _val[0]);
Assert.assertEquals("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", _content);
Assert.assertTrue(_headerCompleted);
Assert.assertTrue(_messageCompleted);
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testNoURI2.
@Test
public void testNoURI2() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET \r\n" + "Content-Length: 0\r\n" + "Connection: close\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals(null, _methodOrVersion);
Assert.assertEquals("No URI", _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());
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testDuplicateContentLengthWithLargerThenCorrectValue.
@Test
public void testDuplicateContentLengthWithLargerThenCorrectValue() {
ByteBuffer buffer = BufferUtil.toBuffer("POST / HTTP/1.1\r\n" + "Content-Length: 2\r\n" + "Content-Length: 1\r\n" + "Connection: close\r\n" + "\r\n" + "X");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals("POST", _methodOrVersion);
Assert.assertEquals("Duplicate Content-Length", _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());
}
use of org.junit.Test in project jetty.project by eclipse.
the class HttpParserTest method testChunkParseTrailer.
@Test
public void testChunkParseTrailer() throws Exception {
ByteBuffer buffer = BufferUtil.toBuffer("GET /chunk HTTP/1.0\r\n" + "Header1: value1\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "a;\r\n" + "0123456789\r\n" + "1a\r\n" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + "0\r\n" + "Trailer: value\r\n" + "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
Assert.assertEquals("GET", _methodOrVersion);
Assert.assertEquals("/chunk", _uriOrStatus);
Assert.assertEquals("HTTP/1.0", _versionOrReason);
Assert.assertEquals(1, _headers);
Assert.assertEquals("Header1", _hdr[0]);
Assert.assertEquals("value1", _val[0]);
Assert.assertEquals("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", _content);
Assert.assertEquals(1, _trailers.size());
HttpField trailer1 = _trailers.get(0);
Assert.assertEquals("Trailer", trailer1.getName());
Assert.assertEquals("value", trailer1.getValue());
Assert.assertTrue(_headerCompleted);
Assert.assertTrue(_messageCompleted);
}
Aggregations