use of org.apache.hc.core5.http.HeaderElement in project httpcomponents-core by apache.
the class TestBasicHeaderElementIterator method testMultiHeader.
@Test
public void testMultiHeader() {
final Header[] headers = new Header[] { new BasicHeader("Name", "value0"), new BasicHeader("Name", "value1") };
final Iterator<HeaderElement> hei = new BasicHeaderElementIterator(new BasicHeaderIterator(headers, "Name"));
Assertions.assertTrue(hei.hasNext());
HeaderElement elem = hei.next();
Assertions.assertEquals("value0", elem.getName(), "The two header values must be equal");
Assertions.assertTrue(hei.hasNext());
elem = hei.next();
Assertions.assertEquals("value1", elem.getName(), "The two header values must be equal");
Assertions.assertFalse(hei.hasNext());
Assertions.assertThrows(NoSuchElementException.class, () -> hei.next());
Assertions.assertFalse(hei.hasNext());
Assertions.assertThrows(NoSuchElementException.class, () -> hei.next());
}
use of org.apache.hc.core5.http.HeaderElement 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());
}
use of org.apache.hc.core5.http.HeaderElement 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");
}
use of org.apache.hc.core5.http.HeaderElement 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");
}
use of org.apache.hc.core5.http.HeaderElement 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");
}
Aggregations