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());
}
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()));
}
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)))));
}
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));
}
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);
}
Aggregations