use of org.apache.hc.core5.util.copied.CharArrayBuffer in project light-4j by networknt.
the class DistinguishedNameParser method parse.
List<NameValuePair> parse(final CharArrayBuffer buf, final ParserCursor cursor) {
final List<NameValuePair> params = new ArrayList<>();
tokenParser.skipWhiteSpace(buf, cursor);
while (!cursor.atEnd()) {
final NameValuePair param = parseParameter(buf, cursor);
params.add(param);
}
return params;
}
use of org.apache.hc.core5.util.copied.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBasicLineFormatter method testRLFormatting.
@Test
public void testRLFormatting() throws Exception {
final RequestLine requestline = new RequestLine(Method.GET.name(), "/stuff", HttpVersion.HTTP_1_1);
final CharArrayBuffer buf = new CharArrayBuffer(64);
this.formatter.formatRequestLine(buf, requestline);
Assertions.assertEquals("GET /stuff HTTP/1.1", buf.toString());
}
use of org.apache.hc.core5.util.copied.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBasicLineParser method testSLParseFailure.
@Test
public void testSLParseFailure() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.clear();
buf.append("xxx 200 OK");
Assertions.assertThrows(ParseException.class, () -> parser.parseStatusLine(buf));
buf.clear();
buf.append("HTTP/1.1 xxx OK");
Assertions.assertThrows(ParseException.class, () -> parser.parseStatusLine(buf));
buf.clear();
buf.append("HTTP/1.1 ");
Assertions.assertThrows(ParseException.class, () -> parser.parseStatusLine(buf));
buf.clear();
buf.append("HTTP/1.1");
Assertions.assertThrows(ParseException.class, () -> parser.parseStatusLine(buf));
buf.clear();
buf.append("HTTP/1.1 -200 OK");
Assertions.assertThrows(ParseException.class, () -> parser.parseStatusLine(buf));
}
use of org.apache.hc.core5.util.copied.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBasicLineParser method testSLParse.
@Test
public void testSLParse() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(64);
// typical status line
buf.clear();
buf.append("HTTP/1.1 200 OK");
StatusLine statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals("HTTP/1.1 200 OK", statusLine.toString());
Assertions.assertEquals(HttpVersion.HTTP_1_1, statusLine.getProtocolVersion());
Assertions.assertEquals(200, statusLine.getStatusCode());
Assertions.assertEquals("OK", statusLine.getReasonPhrase());
// status line with multi word reason phrase
buf.clear();
buf.append("HTTP/1.1 404 Not Found");
statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals(404, statusLine.getStatusCode());
Assertions.assertEquals("Not Found", statusLine.getReasonPhrase());
// reason phrase can be anyting
buf.clear();
buf.append("HTTP/1.1 404 Non Trouve");
statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals("Non Trouve", statusLine.getReasonPhrase());
// its ok to end with a \n\r
buf.clear();
buf.append("HTTP/1.1 404 Not Found\r\n");
statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals("Not Found", statusLine.getReasonPhrase());
// this is valid according to the Status-Line BNF
buf.clear();
buf.append("HTTP/1.1 200 ");
statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals(200, statusLine.getStatusCode());
Assertions.assertEquals("", statusLine.getReasonPhrase());
// this is not strictly valid, but is lenient
buf.clear();
buf.append("HTTP/1.1 200");
statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals(200, statusLine.getStatusCode());
Assertions.assertEquals("", statusLine.getReasonPhrase());
// this is not strictly valid, but is lenient
buf.clear();
buf.append("HTTP/1.1 200 OK");
statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals(200, statusLine.getStatusCode());
Assertions.assertEquals("OK", statusLine.getReasonPhrase());
// this is not strictly valid, but is lenient
buf.clear();
buf.append("\nHTTP/1.1 200 OK");
statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals(200, statusLine.getStatusCode());
Assertions.assertEquals("OK", statusLine.getReasonPhrase());
Assertions.assertEquals(HttpVersion.HTTP_1_1, statusLine.getProtocolVersion());
// this is not strictly valid, but is lenient
buf.clear();
buf.append(" HTTP/1.1 200 OK");
statusLine = this.parser.parseStatusLine(buf);
Assertions.assertEquals(200, statusLine.getStatusCode());
Assertions.assertEquals("OK", statusLine.getReasonPhrase());
Assertions.assertEquals(HttpVersion.HTTP_1_1, statusLine.getProtocolVersion());
}
use of org.apache.hc.core5.util.copied.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBasicLineParser method testRLParseFailure.
@Test
public void testRLParseFailure() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.clear();
buf.append(" ");
Assertions.assertThrows(ParseException.class, () -> parser.parseRequestLine(buf));
buf.clear();
buf.append(" GET");
Assertions.assertThrows(ParseException.class, () -> parser.parseRequestLine(buf));
buf.clear();
buf.append("GET /stuff");
Assertions.assertThrows(ParseException.class, () -> parser.parseRequestLine(buf));
buf.clear();
buf.append("GET/stuff HTTP/1.1");
Assertions.assertThrows(ParseException.class, () -> parser.parseRequestLine(buf));
buf.clear();
buf.append("GET /stuff HTTP/1.1 Oooooooooooppsie");
Assertions.assertThrows(ParseException.class, () -> parser.parseRequestLine(buf));
}
Aggregations