summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_url.class')
-rw-r--r--it_url.class106
1 files changed, 3 insertions, 103 deletions
diff --git a/it_url.class b/it_url.class
index 4ffbc6b..05cd9f2 100644
--- a/it_url.class
+++ b/it_url.class
@@ -113,7 +113,7 @@ function get($p=null, $timeout=5)
it::error("Wrong value for second argument of it_url::get()!");
if (!is_array($p))
$p = array('url' => $p, 'timeout' => $timeout);
- $p += array('retries' => 1, 'curl' => true);
+ $p += array('retries' => 1);
if (($filter = EDC('req')) && ($filter == 1 || strstr($p['url'], "/$filter.")))
ED($p['url']);
@@ -127,10 +127,7 @@ function get($p=null, $timeout=5)
else # called statically
$url = new it_url($p['url']);
- if ($url->protocol == 'http' && !$p['curl'] && !$p['files'] && !$p['compression']) # only curl can do file upload or non-http protocols
- $result = $url->request($p);
- else
- $result = $url->request_curl($p);
+ $result = $url->request_curl($p);
# Handle redirects (supports relative and global) but not for HTTP 201 Created because that can send the Location of the new resource
if ($url->headers['Location'] && $url->result != 201 && preg_match('#^(https?://[^/]*)?(/)?(.*)$#i', $url->headers['Location'], $parts) && ($parts[1] != $url->url))
@@ -182,104 +179,7 @@ static function _default_headers($url, $p)
function request($p=array())
{
- $p += array('totaltimeout' => "999999", 'timeout' => 5);
-
- $url = $this;
- if ($p['url'])
- $this->it_url($p['url']);
-
- $url->result = $result = false;
- unset($url->data);
- $url->headers = $url->cookies = array();
- $p['timeout'] = min($p['timeout'], $p['totaltimeout']); # No operation may be longer than totaltimeout
- $endtime = time() + $p['totaltimeout'];
-
- if ($fp = @fsockopen($url->realhostname, $url->port, $dummy_errno, $errstr, $p['timeout']))
- {
- # urlencode data pairs if is array
- $data = is_array($p['data']) ? it_url::params($p['data']) : $p['data'];
-
- $p['headers'] = (array)$p['headers'] + self::_default_headers($url, $p);
-
- if ($datalen = strlen($data))
- {
- $method = $p['method'] ?: "POST";
- $p['headers'] += array(
- 'Content-Type' => "application/x-www-form-urlencoded",
- 'Content-Length' => $datalen,
- );
- }
- else
- $method = $p['method'] ?: "GET";
-
- if ($url->user || $url->pass)
- $p['headers'] += array('Authorization' => 'Basic ' . base64_encode($url->user . ':' . $url->pass));
-
- foreach ($p['headers'] as $header => $value) {
- if ($value !== null)
- $headers .= "$header: $value\r\n";
- }
-
- $lastio = microtime(true);
- stream_set_timeout($fp, intval($p['timeout']), intval(($p['timeout']*1000000)%1000000));
- @fputs($fp, "$method /$url->path HTTP/1.0\r\n$headers\r\n$data");
-
- $url->header = '';
- while (!feof($fp) && ($lastio = microtime(true)) &&($origline = @fgets($fp, 10240)) && (trim($origline)) && (time() < $endtime))
- {
- $url->header .= $origline;
- $origline = '';
- }
- $url->header .= $origline;
- $this->parse_http_header($url->header);
-
- if ($url->result)
- {
- if ($url->headers['Transfer-Encoding'] == "chunked") # Bogus HTTP/1.1 chunked answer from server (e.g. Wordpress/Apache2/PHP5)
- {
- while (($lastio = microtime(true)) && ($len = hexdec(fgets($fp))) && (!$p['maxlength'] || strlen($url->data) + $len <= $p['maxlength']))
- {
- $chunk = "";
-
- while (!feof($fp) && (strlen($chunk) < $len) && (time() < $endtime))
- $chunk .= @fread($fp, $len - strlen($chunk));
-
- $url->data .= $chunk;
- }
- }
- else
- {
- while (!feof($fp) && (time() < $endtime) && (!$p['maxlength'] || strlen($url->data) <= $p['maxlength']))
- {
- $lastio = microtime(true);
- $url->data .= @fread($fp, 20480);
- }
- }
-
- if ($p['filemtime'] && ($url->result == 304))
- $result = true; # Not modified, success but no data
- else if ($url->result < 400)
- $result =& $url->data;
- }
-
- @fclose($fp);
- } else
- $this->errstr = $errstr;
-
- if (time() >= $endtime) {
- $result = $this->result = false;
- $errstr = $this->errstr = "totaltimeout " . $p['totaltimeout'] . " reached";
- }
-
- if ($p['maxlength'] && (strlen($this->data) + $len > $p['maxlength'])) {
- $result = $this->result = false;
- $errstr = $this->errstr = "maxlength reached";
- }
-
- if ($result === false && $p['retries'] <= 0)
- it::error((array)$p['it_error'] + ['title' => "problem (" . ($errstr ?: ($p['timeout'] && microtime(true) - $lastio > $p['timeout'] ? "timeout " . $p['timeout'] : "unknown")) . ") getting $url->url "]);
-
- return $result;
+ return $this->request_curl($p);
}
static function curl_opts($p=array())