Search in sources :

Example 6 with DefaultContentLengthStrategy

use of org.apache.hc.core5.http.impl.DefaultContentLengthStrategy 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));
}
Also used : ContentLengthStrategy(org.apache.hc.core5.http.ContentLengthStrategy) HttpMessage(org.apache.hc.core5.http.HttpMessage) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultContentLengthStrategy

use of org.apache.hc.core5.http.impl.DefaultContentLengthStrategy 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));
}
Also used : ContentLengthStrategy(org.apache.hc.core5.http.ContentLengthStrategy) HttpMessage(org.apache.hc.core5.http.HttpMessage) Test(org.junit.jupiter.api.Test)

Aggregations

ContentLengthStrategy (org.apache.hc.core5.http.ContentLengthStrategy)7 HttpMessage (org.apache.hc.core5.http.HttpMessage)7 Test (org.junit.jupiter.api.Test)7