Search in sources :

Example 1 with DefaultContentLengthStrategy

use of org.apache.hc.core5.http.impl.DefaultContentLengthStrategy in project httpcomponents-core by apache.

the class TestDefaultContentLengthStrategy method testEntityWithChunkTransferEncoding.

@Test
public void testEntityWithChunkTransferEncoding() throws Exception {
    final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
    final HttpMessage message = new TestHttpMessage();
    message.addHeader("Transfer-Encoding", "Chunked");
    Assertions.assertEquals(ContentLengthStrategy.CHUNKED, 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 2 with DefaultContentLengthStrategy

use of org.apache.hc.core5.http.impl.DefaultContentLengthStrategy in project httpcomponents-core by apache.

the class TestDefaultContentLengthStrategy method testEntityWithNegativeContentLength.

@Test
public void testEntityWithNegativeContentLength() throws Exception {
    final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
    final HttpMessage message = new TestHttpMessage();
    message.addHeader("Content-Length", "-10");
    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)

Example 3 with DefaultContentLengthStrategy

use of org.apache.hc.core5.http.impl.DefaultContentLengthStrategy in project httpcomponents-core by apache.

the class TestDefaultContentLengthStrategy method testEntityNoContentDelimiter.

@Test
public void testEntityNoContentDelimiter() throws Exception {
    final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
    final HttpMessage message = new TestHttpMessage();
    Assertions.assertEquals(ContentLengthStrategy.UNDEFINED, 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 4 with DefaultContentLengthStrategy

use of org.apache.hc.core5.http.impl.DefaultContentLengthStrategy in project httpcomponents-core by apache.

the class TestDefaultContentLengthStrategy method testEntityWithInvalidTransferEncoding.

@Test
public void testEntityWithInvalidTransferEncoding() throws Exception {
    final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
    final HttpMessage message = new TestHttpMessage();
    message.addHeader("Transfer-Encoding", "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)

Example 5 with DefaultContentLengthStrategy

use of org.apache.hc.core5.http.impl.DefaultContentLengthStrategy 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));
}
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