Search in sources :

Example 6 with ContentLengthStrategy

use of org.apache.hc.core5.http.ContentLengthStrategy 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)

Example 7 with ContentLengthStrategy

use of org.apache.hc.core5.http.ContentLengthStrategy 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 8 with ContentLengthStrategy

use of org.apache.hc.core5.http.ContentLengthStrategy 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)8 HttpMessage (org.apache.hc.core5.http.HttpMessage)7 Test (org.junit.jupiter.api.Test)7 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 InterruptedIOException (java.io.InterruptedIOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 InetSocketAddress (java.net.InetSocketAddress)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ByteBuffer (java.nio.ByteBuffer)1 WritableByteChannel (java.nio.channels.WritableByteChannel)1 Charset (java.nio.charset.Charset)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1