From c35d4e4ae45c69b163c5089e84e3bf90f43b59c4 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 8 May 2007 13:56:22 +0000 Subject: Handle bogus chunked transfer encoding response from Wordpress/Apache2/PHP5 --- url.class | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/url.class b/url.class index 7f9cfb3..5635dac 100644 --- a/url.class +++ b/url.class @@ -287,8 +287,23 @@ function get($p=null, $timeout=5000) if ($url->result) { - while (!feof($fp)) - $url->data .= @fread($fp, 20480); + if ($url->headers['Transfer-Encoding'] == "chunked") # Bogus HTTP/1.1 chunked answer from server (e.g. Wordpress/Apach2/PHP5) + { + while ($len = hexdec(fgets($fp))) + { + $chunk = ""; + + while (!feof($fp) && (strlen($chunk) < $len)) + $chunk .= @fread($fp, $len - strlen($chunk)); + + $url->data .= $chunk; + } + } + else + { + while (!feof($fp)) + $url->data .= @fread($fp, 20480); + } if ($url->result < 400) $result =& $url->data; -- cgit v1.2.3