From 2fe6daea539c94704c1932f546ad01d3bfc5d04c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 27 Nov 2011 16:59:14 +0100 Subject: suppress errors on stream_select FS#2276 On certain environments, stream_select might produce temporary errors when file descriptors are running scarce. --- inc/HTTPClient.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'inc/HTTPClient.php') diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index fdf95d113..641950348 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -338,7 +338,10 @@ class HTTPClient { } // wait for stream ready or timeout (1sec) - if(stream_select($sel_r,$sel_w,$sel_e,1) === false) continue; + if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ + usleep(1000); + continue; + } // write to stream $ret = fwrite($socket, substr($request,$written,4096)); -- cgit v1.2.3 From 361171a4e89a313fae8aa823c2279b32ec0c08bc Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 22 Feb 2012 17:34:53 +0100 Subject: simpler/more robust header parsing in HTTPClient The previous regexp approach failed for empty headers. --- inc/HTTPClient.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'inc/HTTPClient.php') diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index 641950348..f0470e736 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -580,13 +580,14 @@ class HTTPClient { */ function _parseHeaders($string){ $headers = array(); - if (!preg_match_all('/^\s*([\w-]+)\s*:\s*([\S \t]+)\s*$/m', $string, - $matches, PREG_SET_ORDER)) { - return $headers; - } - foreach($matches as $match){ - list(, $key, $val) = $match; + $lines = explode("\n",$string); + array_shift($lines); //skip first line (status) + foreach($lines as $line){ + list($key, $val) = explode(':',$line,2); + $key = trim($key); + $val = trim($val); $key = strtolower($key); + if(!$key) continue; if(isset($headers[$key])){ if(is_array($headers[$key])){ $headers[$key][] = $val; -- cgit v1.2.3 From 63703ba5bd81f50c43bc45f8bf79c514afa3ee49 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 Mar 2012 12:09:30 +0100 Subject: coding style updates --- inc/HTTPClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/HTTPClient.php') diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index f0470e736..62c3fde2f 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -22,7 +22,7 @@ class DokuHTTPClient extends HTTPClient { * * @author Andreas Gohr */ - function DokuHTTPClient(){ + function __construct(){ global $conf; // call parent constructor @@ -121,7 +121,7 @@ class HTTPClient { * * @author Andreas Gohr */ - function HTTPClient(){ + function __construct(){ $this->agent = 'Mozilla/4.0 (compatible; DokuWiki HTTP Client; '.PHP_OS.')'; $this->timeout = 15; $this->cookies = array(); -- cgit v1.2.3 From 053d9e5dfd8af184722ff762028c824de4c7858c Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Sun, 18 Mar 2012 14:43:27 +0100 Subject: Fixed call to new constructor name --- inc/HTTPClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/HTTPClient.php') diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index 62c3fde2f..26bee52a7 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -26,7 +26,7 @@ class DokuHTTPClient extends HTTPClient { global $conf; // call parent constructor - $this->HTTPClient(); + parent::__construct(); // set some values from the config $this->proxy_host = $conf['proxy']['host']; -- cgit v1.2.3