Search in sources :

Example 6 with CharArrayBuffer

use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.

the class TestMessageSupport method testParseTokenBufferedHeader.

@Test
public void testParseTokenBufferedHeader() throws Exception {
    final CharArrayBuffer buf = new CharArrayBuffer(128);
    buf.append("stuff: a, b, c, c");
    final Header header = BufferedHeader.create(buf);
    Assertions.assertEquals(makeSet("a", "b", "c"), MessageSupport.parseTokens(header));
}
Also used : Header(org.apache.hc.core5.http.Header) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Example 7 with CharArrayBuffer

use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.

the class TestBasicHeaderValueFormatter method testHEFormatting.

@Test
public void testHEFormatting() throws Exception {
    final NameValuePair param1 = new BasicNameValuePair("param", "regular_stuff");
    final NameValuePair param2 = new BasicNameValuePair("param", "this\\that");
    final NameValuePair param3 = new BasicNameValuePair("param", "this,that");
    final NameValuePair param4 = new BasicNameValuePair("param", null);
    final NameValuePair[] params = new NameValuePair[] { param1, param2, param3, param4 };
    final HeaderElement element = new BasicHeaderElement("name", "value", params);
    final CharArrayBuffer buf = new CharArrayBuffer(64);
    this.formatter.formatHeaderElement(buf, element, false);
    Assertions.assertEquals("name=value; param=regular_stuff; param=\"this\\\\that\"; param=\"this,that\"; param", buf.toString());
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair) HeaderElement(org.apache.hc.core5.http.HeaderElement) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Example 8 with CharArrayBuffer

use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.

the class TestBasicHeaderValueParser method testHEFringeCase1.

@Test
public void testHEFringeCase1() throws Exception {
    final String headerValue = "name1 = value1,";
    final CharArrayBuffer buf = new CharArrayBuffer(64);
    buf.append(headerValue);
    final ParserCursor cursor = new ParserCursor(0, buf.length());
    final HeaderElement[] elements = this.parser.parseElements(buf, cursor);
    Assertions.assertEquals(1, elements.length, "Number of elements");
}
Also used : HeaderElement(org.apache.hc.core5.http.HeaderElement) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Example 9 with CharArrayBuffer

use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.

the class TestBasicHeaderValueParser method testHEFringeCase3.

@Test
public void testHEFringeCase3() throws Exception {
    final String headerValue = ",, ,, ,";
    final CharArrayBuffer buf = new CharArrayBuffer(64);
    buf.append(headerValue);
    final ParserCursor cursor = new ParserCursor(0, buf.length());
    final HeaderElement[] elements = this.parser.parseElements(buf, cursor);
    Assertions.assertEquals(0, elements.length, "Number of elements");
}
Also used : HeaderElement(org.apache.hc.core5.http.HeaderElement) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Example 10 with CharArrayBuffer

use of org.apache.hc.core5.util.CharArrayBuffer in project httpcomponents-core by apache.

the class TestBasicHeaderValueParser method testHEFringeCase2.

@Test
public void testHEFringeCase2() throws Exception {
    final String headerValue = "name1 = value1, ";
    final CharArrayBuffer buf = new CharArrayBuffer(64);
    buf.append(headerValue);
    final ParserCursor cursor = new ParserCursor(0, buf.length());
    final HeaderElement[] elements = this.parser.parseElements(buf, cursor);
    Assertions.assertEquals(1, elements.length, "Number of elements");
}
Also used : HeaderElement(org.apache.hc.core5.http.HeaderElement) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

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