Search in sources :

Example 1 with HeaderElement

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

Example 2 with HeaderElement

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());
}
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 3 with HeaderElement

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");
}
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 HeaderElement

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");
}
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 HeaderElement

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

Aggregations

HeaderElement (org.apache.hc.core5.http.HeaderElement)17 Test (org.junit.jupiter.api.Test)13 CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)9 NameValuePair (org.apache.hc.core5.http.NameValuePair)5 Header (org.apache.hc.core5.http.Header)3 ParserCursor (org.apache.hc.core5.http.message.ParserCursor)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 RequestConfig (org.apache.hc.client5.http.config.RequestConfig)1 HttpClientContext (org.apache.hc.client5.http.protocol.HttpClientContext)1 HttpRequest (org.apache.hc.core5.http.HttpRequest)1 ProtocolVersion (org.apache.hc.core5.http.ProtocolVersion)1 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)1 TimeValue (org.apache.hc.core5.util.TimeValue)1 Option (org.eclipse.californium.core.coap.Option)1 OptionSet (org.eclipse.californium.core.coap.OptionSet)1