summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom N Harris <tnharris@whoopdedo.org>2012-06-16 03:23:17 -0400
committerTom N Harris <tnharris@whoopdedo.org>2012-06-18 21:47:10 -0400
commitfc6c2b2f78f7278af30dd2dd0758e90ae771322e (patch)
tree94815801dbec3b3860a2828d5f26033baefd7037
parenta09831ea8abf0abcf3e7f72f0974dc5e0fc301c8 (diff)
downloadrpg-fc6c2b2f78f7278af30dd2dd0758e90ae771322e.tar.gz
rpg-fc6c2b2f78f7278af30dd2dd0758e90ae771322e.tar.bz2
Correct handling of chunked transfer encoding. (FS#2535)
-rw-r--r--inc/HTTPClient.php12
1 files changed, 8 insertions, 4 deletions
diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php
index 524dd9a2c..a07d263dd 100644
--- a/inc/HTTPClient.php
+++ b/inc/HTTPClient.php
@@ -456,7 +456,7 @@ class HTTPClient {
$r_body = '';
if(preg_match('/transfer\-(en)?coding:\s*chunked\r\n/i',$r_headers)){
do {
- unset($chunk_size);
+ $chunk_size = '';
do {
if(feof($socket)){
$this->error = 'Premature End of File (socket)';
@@ -471,13 +471,17 @@ class HTTPClient {
}
$byte = fread($socket,1);
$chunk_size .= $byte;
- } while (preg_match('/[a-zA-Z0-9]/',$byte)); // read chunksize including \r
+ } while (preg_match('/^[a-zA-Z0-9]?$/',$byte)); // read chunksize including \r
$byte = fread($socket,1); // readtrailing \n
$chunk_size = hexdec($chunk_size);
if ($chunk_size) {
- $this_chunk = fread($socket,$chunk_size);
- $r_body .= $this_chunk;
+ $read_size = $chunk_size;
+ while ($read_size > 0) {
+ $this_chunk = fread($socket,$read_size);
+ $r_body .= $this_chunk;
+ $read_size -= strlen($this_chunk);
+ }
$byte = fread($socket,2); // read trailing \r\n
}