use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class TestBufferedHeader method testInvalidHeaderParsing.
@Test
public void testInvalidHeaderParsing() throws Exception {
final CharArrayBuffer buf = new CharArrayBuffer(16);
buf.clear();
buf.append("");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append("blah");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append(":");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append(" :");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append(": blah");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append(" : blah");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, false));
buf.clear();
buf.append("header : blah");
Assertions.assertThrows(ParseException.class, () -> new BufferedHeader(buf, true));
}
use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class TestHeaderElement method testParamByName.
@Test
public void testParamByName() throws Exception {
final String s = "name = value; param1 = value1; param2 = value2";
final CharArrayBuffer buf = new CharArrayBuffer(64);
buf.append(s);
final ParserCursor cursor = new ParserCursor(0, buf.length());
final HeaderElement element = BasicHeaderValueParser.INSTANCE.parseHeaderElement(buf, cursor);
Assertions.assertEquals("value1", element.getParameterByName("param1").getValue());
Assertions.assertEquals("value2", element.getParameterByName("param2").getValue());
Assertions.assertNull(element.getParameterByName("param3"));
Assertions.assertThrows(NullPointerException.class, () -> element.getParameterByName(null));
}
use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class DefaultHttpRequestWriter method writeHeadLine.
@Override
protected void writeHeadLine(final T message, final CharArrayBuffer lineBuf) throws IOException {
lineBuf.clear();
final ProtocolVersion transportVersion = message.getVersion();
getLineFormatter().formatRequestLine(lineBuf, new RequestLine(message.getMethod(), message.getRequestUri(), transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1));
}
use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class DefaultHttpRequestParser method createMessage.
@Override
protected ClassicHttpRequest createMessage(final CharArrayBuffer buffer) throws IOException, HttpException {
final RequestLine requestLine = getLineParser().parseRequestLine(buffer);
final ClassicHttpRequest request = this.requestFactory.newHttpRequest(requestLine.getMethod(), requestLine.getUri());
request.setVersion(requestLine.getProtocolVersion());
return request;
}
use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.
the class DefaultHttpRequestWriter method writeHeadLine.
@Override
protected void writeHeadLine(final ClassicHttpRequest message, final CharArrayBuffer lineBuf) throws IOException {
final ProtocolVersion transportVersion = message.getVersion();
getLineFormatter().formatRequestLine(lineBuf, new RequestLine(message.getMethod(), message.getRequestUri(), transportVersion != null ? transportVersion : HttpVersion.HTTP_1_1));
}
Aggregations