Search in sources :

Example 16 with CharArrayBuffer

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));
}
Also used : CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Example 17 with CharArrayBuffer

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));
}
Also used : HeaderElement(org.apache.hc.core5.http.HeaderElement) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Example 18 with CharArrayBuffer

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));
}
Also used : RequestLine(org.apache.hc.core5.http.message.RequestLine) ProtocolVersion(org.apache.hc.core5.http.ProtocolVersion)

Example 19 with CharArrayBuffer

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;
}
Also used : RequestLine(org.apache.hc.core5.http.message.RequestLine) ClassicHttpRequest(org.apache.hc.core5.http.ClassicHttpRequest)

Example 20 with CharArrayBuffer

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));
}
Also used : RequestLine(org.apache.hc.core5.http.message.RequestLine) ProtocolVersion(org.apache.hc.core5.http.ProtocolVersion)

Aggregations

CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)91 Test (org.junit.jupiter.api.Test)74 SessionOutputBuffer (org.apache.hc.core5.http.nio.SessionOutputBuffer)18 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 SessionInputBuffer (org.apache.hc.core5.http.io.SessionInputBuffer)13 BasicHttpTransportMetrics (org.apache.hc.core5.http.impl.BasicHttpTransportMetrics)11 ReadableByteChannel (java.nio.channels.ReadableByteChannel)10 Header (org.apache.hc.core5.http.Header)10 WritableByteChannelMock (org.apache.hc.core5.http.WritableByteChannelMock)10 SessionInputBuffer (org.apache.hc.core5.http.nio.SessionInputBuffer)10 HeaderElement (org.apache.hc.core5.http.HeaderElement)9 SessionOutputBuffer (org.apache.hc.core5.http.io.SessionOutputBuffer)9 NameValuePair (org.apache.hc.core5.http.NameValuePair)8 MessageConstraintException (org.apache.hc.core5.http.MessageConstraintException)7 WritableByteChannel (java.nio.channels.WritableByteChannel)6 CharsetDecoder (java.nio.charset.CharsetDecoder)6 CharsetEncoder (java.nio.charset.CharsetEncoder)6 ProtocolVersion (org.apache.hc.core5.http.ProtocolVersion)6 FormattedHeader (org.apache.hc.core5.http.FormattedHeader)5