@Override public HttpMessageParser<ClassicHttpRequest> create(final H1Config h1Config) { return new DefaultHttpRequestParser(this.lineParser, this.requestFactory, h1Config); }
@Override public HttpMessageParser<ClassicHttpRequest> create(final H1Config h1Config) { return new DefaultHttpRequestParser(this.lineParser, this.requestFactory, h1Config); }
@Test(expected = ConnectionClosedException.class) public void testConnectionClosedException() throws Exception { final ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] {}); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16); final DefaultHttpRequestParser parser = new DefaultHttpRequestParser(); parser.parse(inBuffer, inputStream); }
@Test(expected = MessageConstraintException.class) public void testBasicMessageParsingTooManyLeadingEmptyLines() throws Exception { final String s = "\r\n" + "\r\n" + "\r\n" + "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n"; final ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII)); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, StandardCharsets.US_ASCII.newDecoder()); final DefaultHttpRequestParser parser = new DefaultHttpRequestParser( H1Config.custom().setMaxEmptyLineCount(3).build()); parser.parse(inBuffer, inputStream); }
@Test public void testBasicMessageParsing() throws Exception { final String s = "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "User-Agent: whatever\r\n" + "Cookie: c1=stuff\r\n" + "\r\n"; final ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII)); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, StandardCharsets.US_ASCII.newDecoder()); final DefaultHttpRequestParser parser = new DefaultHttpRequestParser(); final ClassicHttpRequest httprequest = parser.parse(inBuffer, inputStream); Assert.assertEquals("GET", httprequest.getMethod()); Assert.assertEquals("/", httprequest.getPath()); final Header[] headers = httprequest.getHeaders(); Assert.assertEquals(3, headers.length); }
@Test public void testBasicMessageParsingLeadingEmptyLines() throws Exception { final String s = "\r\n" + "\r\n" + "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "\r\n"; final ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII)); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, StandardCharsets.US_ASCII.newDecoder()); final DefaultHttpRequestParser parser = new DefaultHttpRequestParser( H1Config.custom().setMaxEmptyLineCount(3).build()); final ClassicHttpRequest httprequest = parser.parse(inBuffer, inputStream); Assert.assertEquals("GET", httprequest.getMethod()); Assert.assertEquals("/", httprequest.getPath()); final Header[] headers = httprequest.getHeaders(); Assert.assertEquals(1, headers.length); }
@Test public void testMessageParsingTimeout() throws Exception { final String s = "GET \000/ HTTP/1.1\r\000\n" + "Host: loca\000lhost\r\n" + "User-Agent: whatever\r\n" + "Coo\000kie: c1=stuff\r\n" + "\000\r\n"; final TimeoutByteArrayInputStream inputStream = new TimeoutByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII)); final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16); final DefaultHttpRequestParser parser = new DefaultHttpRequestParser(); int timeoutCount = 0; ClassicHttpRequest httprequest = null; for (int i = 0; i < 10; i++) { try { httprequest = parser.parse(inBuffer, inputStream); break; } catch (final InterruptedIOException ex) { timeoutCount++; } } Assert.assertNotNull(httprequest); Assert.assertEquals(5, timeoutCount); Assert.assertEquals("GET", httprequest.getMethod()); Assert.assertEquals("/", httprequest.getPath()); final Header[] headers = httprequest.getHeaders(); Assert.assertEquals(3, headers.length); }