Search in sources :

Example 1 with ParserCursor

use of org.apache.hc.core5.http.message.ParserCursor 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;
}
Also used : BasicNameValuePair(org.apache.hc.core5.http.message.copied.BasicNameValuePair) NameValuePair(org.apache.hc.core5.http.copied.NameValuePair) ArrayList(java.util.ArrayList)

Example 2 with ParserCursor

use of org.apache.hc.core5.http.message.ParserCursor 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 3 with ParserCursor

use of org.apache.hc.core5.http.message.ParserCursor 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 4 with ParserCursor

use of org.apache.hc.core5.http.message.ParserCursor 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)

Example 5 with ParserCursor

use of org.apache.hc.core5.http.message.ParserCursor in project httpcomponents-core by apache.

the class TestBasicHeaderValueParser method testNVParse.

@Test
public void testNVParse() {
    String s = "test";
    CharArrayBuffer buffer = new CharArrayBuffer(64);
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, s.length());
    NameValuePair param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertNull(param.getValue());
    Assertions.assertEquals(s.length(), cursor.getPos());
    Assertions.assertTrue(cursor.atEnd());
    s = "test;";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertNull(param.getValue());
    Assertions.assertEquals(s.length(), cursor.getPos());
    Assertions.assertTrue(cursor.atEnd());
    s = "test  ,12";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertNull(param.getValue());
    Assertions.assertEquals(s.length() - 2, cursor.getPos());
    Assertions.assertFalse(cursor.atEnd());
    s = "test=stuff";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertEquals("stuff", param.getValue());
    Assertions.assertEquals(s.length(), cursor.getPos());
    Assertions.assertTrue(cursor.atEnd());
    s = "   test  =   stuff ";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertEquals("stuff", param.getValue());
    Assertions.assertEquals(s.length(), cursor.getPos());
    Assertions.assertTrue(cursor.atEnd());
    s = "   test  =   stuff ;1234";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertEquals("stuff", param.getValue());
    Assertions.assertEquals(s.length() - 4, cursor.getPos());
    Assertions.assertFalse(cursor.atEnd());
    s = "test  = \"stuff\"";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertEquals("stuff", param.getValue());
    s = "test  = \"  stuff\\\"\"";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertEquals("  stuff\"", param.getValue());
    s = "  test";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("test", param.getName());
    Assertions.assertNull(param.getValue());
    s = "  ";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("", param.getName());
    Assertions.assertNull(param.getValue());
    s = " = stuff ";
    buffer = new CharArrayBuffer(16);
    buffer.append(s);
    cursor = new ParserCursor(0, s.length());
    param = this.parser.parseNameValuePair(buffer, cursor);
    Assertions.assertEquals("", param.getName());
    Assertions.assertEquals("stuff", param.getValue());
}
Also used : NameValuePair(org.apache.hc.core5.http.NameValuePair) CharArrayBuffer(org.apache.hc.core5.util.CharArrayBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)12 Test (org.junit.jupiter.api.Test)11 HeaderElement (org.apache.hc.core5.http.HeaderElement)8 NameValuePair (org.apache.hc.core5.http.NameValuePair)7 ArrayList (java.util.ArrayList)5 ParserCursor (org.apache.hc.core5.http.message.ParserCursor)4 ParseException (org.apache.hc.core5.http.ParseException)3 FormattedHeader (org.apache.hc.core5.http.FormattedHeader)2 Header (org.apache.hc.core5.http.Header)2 ProtocolVersion (org.apache.hc.core5.http.ProtocolVersion)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 LinkedList (java.util.LinkedList)1 HttpVersion (org.apache.hc.core5.http.HttpVersion)1 NameValuePair (org.apache.hc.core5.http.copied.NameValuePair)1 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)1 BasicNameValuePair (org.apache.hc.core5.http.message.BasicNameValuePair)1 BasicNameValuePair (org.apache.hc.core5.http.message.copied.BasicNameValuePair)1 ParserCursor (org.apache.hc.core5.http.message.copied.ParserCursor)1 Tokenizer (org.apache.hc.core5.util.Tokenizer)1