use of org.apache.hc.core5.http.HttpMessage in project httpcomponents-core by apache.
the class TestDefaultContentLengthStrategy method testEntityWithIdentityTransferEncoding.
@Test
public void testEntityWithIdentityTransferEncoding() throws Exception {
final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Transfer-Encoding", "Identity");
Assertions.assertThrows(NotImplementedException.class, () -> lenStrategy.determineLength(message));
}
use of org.apache.hc.core5.http.HttpMessage in project httpcomponents-core by apache.
the class TestDefaultContentLengthStrategy method testEntityWithContentLength.
@Test
public void testEntityWithContentLength() throws Exception {
final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Content-Length", "100");
Assertions.assertEquals(100, lenStrategy.determineLength(message));
}
use of org.apache.hc.core5.http.HttpMessage in project httpcomponents-core by apache.
the class TestDefaultContentLengthStrategy method testEntityWithInvalidContentLength.
@Test
public void testEntityWithInvalidContentLength() throws Exception {
final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Content-Length", "whatever");
Assertions.assertThrows(ProtocolException.class, () -> lenStrategy.determineLength(message));
}
use of org.apache.hc.core5.http.HttpMessage in project httpcomponents-core by apache.
the class TestMessageSupport method testContentHeadersAlreadyPresent.
@Test
public void testContentHeadersAlreadyPresent() throws Exception {
final HttpEntity entity = HttpEntities.create("some stuff with trailers", StandardCharsets.US_ASCII, new BasicHeader("z", "this"), new BasicHeader("b", "that"), new BasicHeader("a", "this and that"));
final HttpMessage message = new BasicHttpResponse(200);
message.addHeader(HttpHeaders.TRAILER, "a, a, a");
message.addHeader(HttpHeaders.CONTENT_TYPE, "text/plain; charset=ascii");
MessageSupport.addTrailerHeader(message, entity);
MessageSupport.addContentTypeHeader(message, entity);
final Header h1 = message.getFirstHeader(HttpHeaders.TRAILER);
final Header h2 = message.getFirstHeader(HttpHeaders.CONTENT_TYPE);
Assertions.assertNotNull(h1);
Assertions.assertEquals("a, a, a", h1.getValue());
Assertions.assertNotNull(h2);
Assertions.assertEquals("text/plain; charset=ascii", h2.getValue());
}
use of org.apache.hc.core5.http.HttpMessage in project httpcomponents-core by apache.
the class TestMessageSupport method testAddContentHeaders.
@Test
public void testAddContentHeaders() throws Exception {
final HttpEntity entity = HttpEntities.create("some stuff with trailers", StandardCharsets.US_ASCII, new BasicHeader("z", "this"), new BasicHeader("b", "that"), new BasicHeader("a", "this and that"));
final HttpMessage message = new BasicHttpResponse(200);
MessageSupport.addTrailerHeader(message, entity);
MessageSupport.addContentTypeHeader(message, entity);
final Header h1 = message.getFirstHeader(HttpHeaders.TRAILER);
final Header h2 = message.getFirstHeader(HttpHeaders.CONTENT_TYPE);
Assertions.assertNotNull(h1);
Assertions.assertEquals("z, b, a", h1.getValue());
Assertions.assertNotNull(h2);
Assertions.assertEquals("text/plain; charset=US-ASCII", h2.getValue());
}
Aggregations