use of org.apache.hc.core5.http.io.SessionInputBuffer in project httpcomponents-core by apache.
the class TestMessageParser method testMaxHeaderCountForFoldedHeader.
@Test
public void testMaxHeaderCountForFoldedHeader() throws Exception {
final String s = "header1: stuff\r\n" + " stuff \r\n" + " 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());
Assertions.assertThrows(IOException.class, () -> AbstractMessageParser.parseHeaders(inBuffer, inputStream, 2, 15, null));
}
use of org.apache.hc.core5.http.io.SessionInputBuffer in project httpcomponents-core by apache.
the class TestMessageParser method testParsingHeader.
@Test
public void testParsingHeader() throws Exception {
final String s = "header1: stuff; param1 = value1; param2 = \"value 2\" \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 Header[] headers = AbstractMessageParser.parseHeaders(inBuffer, inputStream, -1, -1, null);
Assertions.assertNotNull(headers);
Assertions.assertEquals(1, headers.length);
Assertions.assertEquals("header1: stuff; param1 = value1; param2 = \"value 2\" ", headers[0].toString());
}
use of org.apache.hc.core5.http.io.SessionInputBuffer in project httpcomponents-core by apache.
the class TestMessageParser method testParsingMalformedFirstHeader.
@Test
public void testParsingMalformedFirstHeader() throws Exception {
final String s = " header1: stuff\r\n" + "header2: stuff \r\n";
final ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII));
final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, StandardCharsets.US_ASCII.newDecoder());
final Header[] headers = AbstractMessageParser.parseHeaders(inBuffer, inputStream, -1, -1, null);
Assertions.assertNotNull(headers);
Assertions.assertEquals(2, headers.length);
Assertions.assertEquals("header1", headers[0].getName());
Assertions.assertEquals("stuff", headers[0].getValue());
Assertions.assertEquals("header2", headers[1].getName());
Assertions.assertEquals("stuff", headers[1].getValue());
}
use of org.apache.hc.core5.http.io.SessionInputBuffer in project httpcomponents-core by apache.
the class TestMessageParser method testEmptyDataStream.
@Test
public void testEmptyDataStream() throws Exception {
final String s = "";
final ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII));
final SessionInputBuffer inBuffer = new SessionInputBufferImpl(16, StandardCharsets.US_ASCII.newDecoder());
final Header[] headers = AbstractMessageParser.parseHeaders(inBuffer, inputStream, -1, -1, null);
Assertions.assertNotNull(headers);
Assertions.assertEquals(0, headers.length);
}
use of org.apache.hc.core5.http.io.SessionInputBuffer in project httpcomponents-core by apache.
the class TestRequestParser method testMessageParsingTimeout.
@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++;
}
}
Assertions.assertNotNull(httprequest);
Assertions.assertEquals(5, timeoutCount);
Assertions.assertEquals(Method.GET.name(), httprequest.getMethod());
Assertions.assertEquals("/", httprequest.getPath());
final Header[] headers = httprequest.getHeaders();
Assertions.assertEquals(3, headers.length);
}
Aggregations