// we don't actually enforce the lease time because GNU
// Social/StatusNet doesn't honour it (yet)
- $body = Network::fetchUrl($hub_callback . "?" . $params);
- $ret = Network::getCurl()->getCode();
+ $fetchResult = Network::fetchUrlFull($hub_callback . "?" . $params);
+ $body = $fetchResult->getBody();
+ $ret = $fetchResult->getReturnCode();
// give up if the HTTP return code wasn't a success (2xx)
if ($ret < 200 || $ret > 299) {
$help = "";
$error_msg = "";
if (function_exists('curl_init')) {
- $test = Network::fetchUrlFull(System::baseUrl() . "/install/testrewrite");
+ $fetchResult = Network::fetchUrlFull(System::baseUrl() . "/install/testrewrite");
$url = normalise_link(System::baseUrl() . "/install/testrewrite");
- if ($test['body'] != "ok") {
- $test = Network::fetchUrlFull($url);
+ if ($fetchResult->getBody() != "ok") {
+ $fetchResult = Network::fetchUrlFull($url);
}
- if ($test['body'] != "ok") {
+ if ($fetchResult->getBody() != "ok") {
$status = false;
$help = L10n::t('Url rewrite in .htaccess is not working. Check your server configuration.');
$error_msg = [];
$error_msg['head'] = L10n::t('Error message from Curl when fetching');
- $error_msg['url'] = $test['redirect_url'];
- $error_msg['msg'] = defaults($test, 'error', '');
+ $error_msg['url'] = $fetchResult->getRedirectUrl();
+ $error_msg['msg'] = $fetchResult->getError();
}
self::addCheck($checks, L10n::t('Url rewrite is working'), $status, true, $help, $error_msg);
} else {
// It shouldn't happen but it does - spaces in URL
$_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']);
$redirects = 0;
- $img_str = Network::fetchUrl($_REQUEST['url'], true, $redirects, 10);
+ $fetchResult = Network::fetchUrlFull($_REQUEST['url'], true, $redirects, 10);
+ $img_str = $fetchResult->getBody();
$tempfile = tempnam(get_temppath(), 'cache');
file_put_contents($tempfile, $img_str);
unlink($tempfile);
// If there is an error then return a blank image
- if ((substr(Network::getCurl()->getCode(), 0, 1) == '4') || (!$img_str)) {
+ if ((substr($fetchResult->getReturnCode(), 0, 1) == '4') || (!$img_str)) {
$img_str = file_get_contents('images/blank.png');
$mime = 'image/png';
$cachefile = ''; // Clear the cachefile so that the dummy isn't stored
private $isTimeout;
/**
- * @var int optional error numer
+ * @var int the error number or 0 (zero) if no error
*/
private $errorNumber;
/**
- * @var string optional error message
+ * @var string the error message or '' (the empty string) if no
*/
private $error;
return new Curl(
$url,
'',
- ['http_code' => 0]
+ [ 'http_code' => 0 ]
);
}
*/
public function __construct($url, $result, $info, $errorNumber = 0, $error = '')
{
- if (empty($info['http_code'])) {
+ if (!array_key_exists('http_code', $info)) {
throw new InternalServerErrorException('CURL response doesn\'t contains a response HTTP code');
}
private function checkSuccess()
{
- $this->isSuccess = ((($this->returnCode >= 200 && $this->returnCode <= 299) || !empty($this->errorNumber)) ? true : false);
+ $this->isSuccess = ($this->returnCode >= 200 && $this->returnCode <= 299) || $this->errorNumber == 0;
if (!$this->isSuccess) {
- logger('error: ' . $this->url . ': ' . $this->returnCode . ' - ' . $this->error, LOGGER_DEBUG);
+ logger('error: ' . $this->url . ': ' . $this->returnCode . ' - ' . $this->error, LOGGER_INFO);
logger('debug: ' . print_r($this->info, true), LOGGER_DATA);
}
private function checkRedirect()
{
- if (empty($this->info['url'])) {
+ if (!array_key_exists('url', $this->info)) {
$this->redirectUrl = '';
} else {
$this->redirectUrl = $this->info['url'];
}
if ($this->returnCode == 301 || $this->returnCode == 302 || $this->returnCode == 303 || $this->returnCode== 307) {
- $new_location_info = (empty($this->info['redirect_url']) ? '' : @parse_url($this->info['redirect_url']));
- $old_location_info = (empty($this->info['url'] ? '' : @parse_url($this->info['url']));
+ $new_location_info = (!array_key_exists('redirect_url', $this->info) ? '' : @parse_url($this->info['redirect_url']));
+ $old_location_info = (!array_key_exists('url', $this->info) ? '' : @parse_url($this->info['url']));
$this->redirectUrl = $new_location_info;
*
* @param string $filename Image filename
* @param boolean $fromcurl Check Content-Type header from curl request
+ * @param string $header passed headers to take into account
*
* @return object
*/
- public static function guessType($filename, $fromcurl = false)
+ public static function guessType($filename, $fromcurl = false, $header = '')
{
logger('Image: guessType: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
$type = null;
if ($fromcurl) {
$a = get_app();
$headers=[];
- $h = explode("\n", Network::getCurl()->getHeaders());
+ $h = explode("\n", $header);
foreach ($h as $l) {
$data = array_map("trim", explode(":", trim($l), 2));
if (count($data) > 1) {
logger("transmit: ".$logid."-".$guid." to ".$dest_url." returns: ".$return_code);
- if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeaders(), "retry-after")))) {
+ if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeader(), "retry-after")))) {
if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::ACCOUNT_TYPE_RELAY)) {
logger("queue message");
// queue message for redelivery
logger('load: ' . $url, LOGGER_DEBUG);
- $s = Network::fetchUrl($url);
+ $fetchresult = Network::fetchUrlFull($url);
+ $s = $fetchresult->getBody();
logger('load: returns ' . $s, LOGGER_DATA);
- logger('load: return code: ' . Network::getCurl()->getCode(), LOGGER_DEBUG);
+ logger('load: return code: ' . $fetchresult->getReturnCode(), LOGGER_DEBUG);
- if ((Network::getCurl()->getCode() > 299) || (! $s)) {
+ if (($fetchresult->getReturnCode() > 299) || (! $s)) {
return;
}
return -1;
}
- if (($return_code == 503) && (stristr(Network::getCurl()->getHeaders(), 'retry-after'))) {
+ if (($return_code == 503) && (stristr($postResult->getHeader(), 'retry-after'))) {
return -1;
}
$curl_info = @curl_getinfo($ch);
}
- if (curl_errno($ch) !== CURLE_OK) {
- logger('error fetching ' . $url . ': ' . curl_error($ch), LOGGER_INFO);
- }
-
$curlResponse = new Curl($url, $s, $curl_info, curl_errno($ch), curl_error($ch));
if ($curlResponse->isRedirectUrl()) {