[ 
https://issues.apache.org/jira/browse/HTTPCORE-559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16645795#comment-16645795
 ] 

David Maplesden commented on HTTPCORE-559:
------------------------------------------

You need to add a unit test that looks something like the below to 
{{org.apache.hc.core5.http.impl.io.TestDefaultBHttpClientConnection}}
{code:java}
    @Test
    public void testReadResponseEntityWithoutContentLength() throws Exception {
        final String s = "HTTP/1.1 200 OK\r\nServer: test\r\n\r\n123";
        final ByteArrayInputStream inStream = new 
ByteArrayInputStream(s.getBytes(StandardCharsets.US_ASCII));
        Mockito.when(socket.getInputStream()).thenReturn(inStream);

        conn.bind(socket);

        Assert.assertEquals(0, conn.getEndpointDetails().getResponseCount());

        final ClassicHttpResponse response = conn.receiveResponseHeader();

        Assert.assertNotNull(response);
        Assert.assertEquals(200, response.getCode());
        Assert.assertTrue(response.containsHeader("Server"));
        Assert.assertEquals(1, conn.getEndpointDetails().getResponseCount());

        conn.receiveResponseEntity(response);

        final HttpEntity entity = response.getEntity();
        Assert.assertNotNull(entity);
        Assert.assertEquals(-1, entity.getContentLength());
        Assert.assertEquals(1, conn.getEndpointDetails().getResponseCount());

        final InputStream content = entity.getContent();
        Assert.assertNotNull(content);
        Assert.assertEquals(3, content.available());
        Assert.assertEquals('1', content.read());
        Assert.assertEquals('2', content.read());
        Assert.assertEquals('3', content.read());
    }
{code}

> The DefaultBHttpClientConnection will not read a simple end-of-stream 
> terminated HTTP response body
> ---------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCORE-559
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-559
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore
>    Affects Versions: 5.0-beta3
>            Reporter: David Maplesden
>            Priority: Major
>
> When you use the Classic HttpClient to execute a GET request for a resource 
> which is returned with no Content-Length or Transfer-Encoding header then the 
> response body (which should be now terminated by the closing of the stream) 
> is not read.  Instead the client returns an empty response with no attempt 
> made to read from the stream.
> I realize that virtually no responses are ever sent this way, they almost 
> always either have a content length or use chunked transfer encoding, but it 
> is still legal as per the HTTP spec to return a response without using either 
> of these and relying on the end-of-stream to terminate the response body.  
> Currently if a server is doing this, the HttpClient won't receive the 
> response.
> I found this problem testing the HttpClient, but I believe the root source of 
> the problem is in the DefaultBHttpClientConnection implementation.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to