Search in sources :

Example 6 with HeaderGroup

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

the class TestHeaderGroup method testFirstLastHeaders.

@Test
public void testFirstLastHeaders() {
    final HeaderGroup headergroup = new HeaderGroup();
    final Header header1 = new BasicHeader("name", "value1");
    final Header header2 = new BasicHeader("name", "value2");
    final Header header3 = new BasicHeader("name", "value3");
    headergroup.setHeaders(header1, header2, header3);
    Assertions.assertNull(headergroup.getFirstHeader("whatever"));
    Assertions.assertNull(headergroup.getLastHeader("whatever"));
    Assertions.assertEquals("value1", headergroup.getFirstHeader("name").getValue());
    Assertions.assertEquals("value3", headergroup.getLastHeader("name").getValue());
}
Also used : Header(org.apache.hc.core5.http.Header) Test(org.junit.jupiter.api.Test)

Example 7 with HeaderGroup

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

the class IncomingEntityDetailsTest method getContentLength.

@Test
public void getContentLength() {
    final MessageHeaders messageHeaders = new HeaderGroup();
    final HeaderGroup headerGroup = new HeaderGroup();
    final Header header = new BasicHeader("name", "value");
    headerGroup.addHeader(header);
    final IncomingEntityDetails incomingEntityDetails = new IncomingEntityDetails(messageHeaders);
    assertAll(() -> assertEquals(-1, incomingEntityDetails.getContentLength()), () -> assertTrue(incomingEntityDetails.isChunked()));
}
Also used : Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) HeaderGroup(org.apache.hc.core5.http.message.HeaderGroup) MessageHeaders(org.apache.hc.core5.http.MessageHeaders) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) Test(org.junit.jupiter.api.Test)

Example 8 with HeaderGroup

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

the class IncomingEntityDetailsTest method getTrailerNames.

@Test
public void getTrailerNames() {
    final HeaderGroup messageHeaders = new HeaderGroup();
    final Header header = new BasicHeader(HttpHeaders.TRAILER, "a, b, c, c");
    messageHeaders.setHeaders(header);
    final IncomingEntityDetails incomingEntityDetails = new IncomingEntityDetails(messageHeaders);
    final Set<String> incomingSet = incomingEntityDetails.getTrailerNames();
    assertAll(() -> assertFalse(incomingSet.isEmpty()), () -> assertTrue(incomingSet.containsAll(Stream.of("a", "b", "c").collect(Collectors.toCollection(HashSet::new)))));
}
Also used : Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) HeaderGroup(org.apache.hc.core5.http.message.HeaderGroup) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 9 with HeaderGroup

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

the class IncomingEntityDetailsTest method getContentLengthEmpty.

@Test
public void getContentLengthEmpty() {
    final MessageHeaders messageHeaders = new HeaderGroup();
    final IncomingEntityDetails incomingEntityDetails = new IncomingEntityDetails(messageHeaders);
    assertAll(() -> assertEquals(-1, incomingEntityDetails.getContentLength()), () -> assertNull(incomingEntityDetails.getContentType()), () -> assertNull(incomingEntityDetails.getContentEncoding()), () -> assertEquals(incomingEntityDetails.getTrailerNames().size(), 0));
}
Also used : HeaderGroup(org.apache.hc.core5.http.message.HeaderGroup) MessageHeaders(org.apache.hc.core5.http.MessageHeaders) Test(org.junit.jupiter.api.Test)

Example 10 with HeaderGroup

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

the class TestHeaderGroup method testAddRemoveHeader.

@Test
public void testAddRemoveHeader() {
    final HeaderGroup headerGroup = new HeaderGroup();
    final Header header = new BasicHeader("name", "value");
    headerGroup.addHeader(header);
    headerGroup.addHeader(null);
    Assertions.assertEquals(1, headerGroup.getHeaders().length);
    Assertions.assertTrue(headerGroup.removeHeader(header));
    Assertions.assertFalse(headerGroup.removeHeader(null));
    Assertions.assertEquals(0, headerGroup.getHeaders().length);
}
Also used : Header(org.apache.hc.core5.http.Header) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)12 Header (org.apache.hc.core5.http.Header)11 HeaderGroup (org.apache.hc.core5.http.message.HeaderGroup)3 MessageHeaders (org.apache.hc.core5.http.MessageHeaders)2 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashSet (java.util.HashSet)1