diff options
author | Tom N Harris <tnharris@whoopdedo.org> | 2012-06-20 03:00:18 -0400 |
---|---|---|
committer | Tom N Harris <tnharris@whoopdedo.org> | 2012-06-20 03:00:18 -0400 |
commit | 769b429a77368df14e3753f624466f658e971df6 (patch) | |
tree | 306216ba947cf3ebbea4ad11b88ccd0aa7239dac | |
parent | fbf63b6e769b92fc1964c09132dfc937910d04f3 (diff) | |
download | rpg-769b429a77368df14e3753f624466f658e971df6.tar.gz rpg-769b429a77368df14e3753f624466f658e971df6.tar.bz2 |
HTTPClient will read up to max_bodysize if it can
-rw-r--r-- | _test/tests/inc/httpclient_http.test.php | 6 | ||||
-rw-r--r-- | inc/HTTPClient.php | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/_test/tests/inc/httpclient_http.test.php b/_test/tests/inc/httpclient_http.test.php index cf8137152..c3ee182dc 100644 --- a/_test/tests/inc/httpclient_http.test.php +++ b/_test/tests/inc/httpclient_http.test.php @@ -124,6 +124,12 @@ class httpclient_http_test extends DokuWikiTest { $http->max_bodysize = 250; $data = $http->get($this->server.'/stream/30'); $this->assertTrue($data === false, 'HTTP response'); + $http->max_bodysize_abort = false; + $data = $http->get($this->server.'/stream/30'); + $this->assertFalse($data === false, 'HTTP response'); + /* the current implementation will read in max_bodysize blocks, + and aborts if the response is larger, thus a limit of 2*max_bodysize */ + $this->assertLessThanOrEqual(500,strlen($data)); } /** diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index 901c46ec9..b5e665cb1 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -402,6 +402,7 @@ class HTTPClient { $r_body = ''; if((isset($this->resp_headers['transfer-encoding']) && $this->resp_headers['transfer-encoding'] == 'chunked') || (isset($this->resp_headers['transfer-coding']) && $this->resp_headers['transfer-coding'] == 'chunked')){ + $abort = false; do { $chunk_size = ''; while (preg_match('/^[a-zA-Z0-9]?$/',$byte=$this->_readData($socket,1,'chunk'))){ @@ -417,18 +418,19 @@ class HTTPClient { if ($this->max_bodysize_abort) throw new HTTPClientException('Allowed response size exceeded'); $this->error = 'Allowed response size exceeded'; - break; + $chunk_size = $this->max_bodysize - strlen($r_body); + $abort = true; } - if ($chunk_size) { + if ($chunk_size > 0) { $r_body .= $this->_readData($socket, $chunk_size, 'chunk'); $byte = $this->_readData($socket, 2, 'chunk'); // read trailing \r\n } - } while ($chunk_size); + } while ($chunk_size && !$abort); }else{ // read entire socket while (!feof($socket)) { - $r_body .= $this->_readData($socket, 0, 'response', true); + $r_body .= $this->_readData($socket, -$this->max_bodysize, 'response', true); $r_size = strlen($r_body); if($this->max_bodysize && $r_size > $this->max_bodysize){ if ($this->max_bodysize_abort) { |