diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php
index 522f0790cdb83558437991766139c6b095b270e0..43dd4478f5ef1f61b6c4d291d0fdd1242975e648 100644
--- a/_test/tests/inc/httpclient_http.test.php
+++ b/_test/tests/inc/httpclient_http.test.php
@@ -122,9 +122,14 @@ class httpclient_http_test extends DokuWikiTest {
     function test_maxbody(){
         $http = new HTTPClient();
         $http->max_bodysize = 250;
+
+        // this should abort completely
         $data = $http->get($this->server.'/stream/30');
         $this->assertTrue($data === false, 'HTTP response');
+
+        // this should read just the needed bytes
         $http->max_bodysize_abort = false;
+        $http->keep_alive = false;
         $data = $http->get($this->server.'/stream/30');
         $this->assertFalse($data === false, 'HTTP response');
         /* should read no more than max_bodysize+1 */
diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php
index 3964c8fbc3056e8403321111a9274b7596e3abc0..b2621bdbbb355630bca7c235d23acabde7dbca40 100644
--- a/inc/HTTPClient.php
+++ b/inc/HTTPClient.php
@@ -463,6 +463,8 @@ class HTTPClient {
                 }
 
                 $r_body = $this->_readData($socket, $length, 'response (content-length limited)', true);
+            }elseif( !isset($this->resp_headers['transfer-encoding']) && $this->max_bodysize && !$this->keep_alive){
+                $r_body = $this->_readData($socket, $this->max_bodysize, 'response (content-length limited)', true);
             }else{
                 // read entire socket
                 $r_size = 0;