Move post/curl/fetchUrl/fetchUrlFull to own class "Network\HTTPRequest"

This commit is contained in:
nupplaPhil 2020-03-04 22:07:05 +01:00 committed by Hypolite Petovan
parent 2889d59b83
commit 5344efef71
43 changed files with 528 additions and 485 deletions

View file

@ -42,10 +42,10 @@ use Friendica\Model\Contact;
use Friendica\Model\Group; use Friendica\Model\Group;
use Friendica\Model\Notify\Type; use Friendica\Model\Notify\Type;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -224,7 +224,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
* *
*/ */
$res = Network::post($dfrn_confirm, $params, [], 120)->getBody(); $res = HTTPRequest::post($dfrn_confirm, $params, [], 120)->getBody();
Logger::log(' Confirm: received data: ' . $res, Logger::DATA); Logger::log(' Confirm: received data: ' . $res, Logger::DATA);

View file

@ -21,13 +21,13 @@
use Friendica\App; use Friendica\App;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Core\Session; use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPRequest;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -115,7 +115,7 @@ function dfrn_poll_init(App $a)
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$s = Network::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); $s = HTTPRequest::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check');
Logger::log("dfrn_poll: old profile returns " . $s, Logger::DATA); Logger::log("dfrn_poll: old profile returns " . $s, Logger::DATA);
@ -499,7 +499,7 @@ function dfrn_poll_content(App $a)
// URL reply // URL reply
if ($dfrn_version < 2.2) { if ($dfrn_version < 2.2) {
$s = Network::fetchUrl($r[0]['poll'] $s = HTTPRequest::fetchUrl($r[0]['poll']
. '?dfrn_id=' . $encrypted_id . '?dfrn_id=' . $encrypted_id
. '&type=profile-check' . '&type=profile-check'
. '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
@ -507,7 +507,7 @@ function dfrn_poll_content(App $a)
. '&sec=' . $sec . '&sec=' . $sec
); );
} else { } else {
$s = Network::post($r[0]['poll'], [ $s = HTTPRequest::post($r[0]['poll'], [
'dfrn_id' => $encrypted_id, 'dfrn_id' => $encrypted_id,
'type' => 'profile-check', 'type' => 'profile-check',
'dfrn_version' => DFRN_PROTOCOL_VERSION, 'dfrn_version' => DFRN_PROTOCOL_VERSION,

View file

@ -29,8 +29,8 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\Search; use Friendica\Core\Search;
use Friendica\Core\System;
use Friendica\Core\Session; use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
@ -39,6 +39,7 @@ use Friendica\Model\Notify\Type;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
use Friendica\Network\HTTPRequest;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -203,7 +204,7 @@ function dfrn_request_post(App $a)
} }
if (!empty($dfrn_request) && strlen($confirm_key)) { if (!empty($dfrn_request) && strlen($confirm_key)) {
Network::fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key); HTTPRequest::fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key);
} }
// (ignore reply, nothing we can do it failed) // (ignore reply, nothing we can do it failed)

View file

@ -27,7 +27,7 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
/** /**
@ -76,7 +76,7 @@ function match_content(App $a)
$host = DI::baseUrl(); $host = DI::baseUrl();
} }
$msearch_json = Network::post($host . '/msearch', $params)->getBody(); $msearch_json = HTTPRequest::post($host . '/msearch', $params)->getBody();
$msearch = json_decode($msearch_json); $msearch = json_decode($msearch_json);

View file

@ -23,7 +23,7 @@ use Friendica\App;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\Security\Login; use Friendica\Module\Security\Login;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
use Friendica\Util\Strings; use Friendica\Util\Strings;
function oexchange_init(App $a) { function oexchange_init(App $a) {
@ -58,7 +58,7 @@ function oexchange_content(App $a) {
$tags = ((!empty($_REQUEST['tags'])) $tags = ((!empty($_REQUEST['tags']))
? '&tags=' . urlencode(Strings::escapeTags(trim($_REQUEST['tags']))) : ''); ? '&tags=' . urlencode(Strings::escapeTags(trim($_REQUEST['tags']))) : '');
$s = Network::fetchUrl(DI::baseUrl() . '/parse_url?url=' . $url . $title . $description . $tags); $s = HTTPRequest::fetchUrl(DI::baseUrl() . '/parse_url?url=' . $url . $title . $description . $tags);
if (!strlen($s)) { if (!strlen($s)) {
return; return;

View file

@ -23,7 +23,7 @@ use Friendica\App;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
function ostatus_subscribe_content(App $a) function ostatus_subscribe_content(App $a)
{ {
@ -55,7 +55,7 @@ function ostatus_subscribe_content(App $a)
$api = $contact['baseurl'] . '/api/'; $api = $contact['baseurl'] . '/api/';
// Fetching friends // Fetching friends
$curlResult = Network::curl($api . 'statuses/friends.json?screen_name=' . $contact['nick']); $curlResult = HTTPRequest::curl($api . 'statuses/friends.json?screen_name=' . $contact['nick']);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact'); DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');

View file

@ -28,7 +28,7 @@ use Friendica\Content\PageInfo;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -85,7 +85,7 @@ function parse_url_content(App $a)
// Check if the URL is an image, video or audio file. If so format // Check if the URL is an image, video or audio file. If so format
// the URL with the corresponding BBCode media tag // the URL with the corresponding BBCode media tag
// Fetch the header of the URL // Fetch the header of the URL
$curlResponse = Network::curl($url, false, ['novalidate' => true, 'nobody' => true]); $curlResponse = HTTPRequest::curl($url, false, ['novalidate' => true, 'nobody' => true]);
if ($curlResponse->isSuccess()) { if ($curlResponse->isSuccess()) {
// Convert the header fields into an array // Convert the header fields into an array

View file

@ -24,7 +24,7 @@ use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\PushSubscriber; use Friendica\Model\PushSubscriber;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
use Friendica\Util\Strings; use Friendica\Util\Strings;
function post_var($name) { function post_var($name) {
@ -126,7 +126,7 @@ function pubsubhubbub_init(App $a) {
$hub_callback = rtrim($hub_callback, ' ?&#'); $hub_callback = rtrim($hub_callback, ' ?&#');
$separator = parse_url($hub_callback, PHP_URL_QUERY) === null ? '?' : '&'; $separator = parse_url($hub_callback, PHP_URL_QUERY) === null ? '?' : '&';
$fetchResult = Network::fetchUrlFull($hub_callback . $separator . $params); $fetchResult = HTTPRequest::fetchUrlFull($hub_callback . $separator . $params);
$body = $fetchResult->getBody(); $body = $fetchResult->getBody();
$ret = $fetchResult->getReturnCode(); $ret = $fetchResult->getReturnCode();

View file

@ -27,7 +27,7 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
use Friendica\Util\Strings; use Friendica\Util\Strings;
function redir_init(App $a) { function redir_init(App $a) {
@ -171,7 +171,7 @@ function redir_magic($a, $cid, $url)
} }
// Test for magic auth on the target system // Test for magic auth on the target system
$serverret = Network::curl($basepath . '/magic'); $serverret = HTTPRequest::curl($basepath . '/magic');
if ($serverret->isSuccess()) { if ($serverret->isSuccess()) {
$separator = strpos($target_url, '?') ? '&' : '?'; $separator = strpos($target_url, '?') ? '&' : '?';
$target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url); $target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url);

View file

@ -31,6 +31,7 @@ use Friendica\Core\Hook;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPRequest;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
@ -95,7 +96,7 @@ class OEmbed
if (!in_array($ext, $noexts)) { if (!in_array($ext, $noexts)) {
// try oembed autodiscovery // try oembed autodiscovery
$html_text = Network::fetchUrl($embedurl, false, 15, 'text/*'); $html_text = HTTPRequest::fetchUrl($embedurl, false, 15, 'text/*');
if ($html_text) { if ($html_text) {
$dom = @DOMDocument::loadHTML($html_text); $dom = @DOMDocument::loadHTML($html_text);
if ($dom) { if ($dom) {
@ -103,14 +104,14 @@ class OEmbed
$entries = $xpath->query("//link[@type='application/json+oembed']"); $entries = $xpath->query("//link[@type='application/json+oembed']");
foreach ($entries as $e) { foreach ($entries as $e) {
$href = $e->getAttributeNode('href')->nodeValue; $href = $e->getAttributeNode('href')->nodeValue;
$json_string = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth); $json_string = HTTPRequest::fetchUrl($href . '&maxwidth=' . $a->videowidth);
break; break;
} }
$entries = $xpath->query("//link[@type='text/json+oembed']"); $entries = $xpath->query("//link[@type='text/json+oembed']");
foreach ($entries as $e) { foreach ($entries as $e) {
$href = $e->getAttributeNode('href')->nodeValue; $href = $e->getAttributeNode('href')->nodeValue;
$json_string = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth); $json_string = HTTPRequest::fetchUrl($href . '&maxwidth=' . $a->videowidth);
break; break;
} }
} }

View file

@ -38,12 +38,11 @@ use Friendica\Model\Contact;
use Friendica\Model\Event; use Friendica\Model\Event;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Network\Probe; use Friendica\Network\HTTPRequest;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\Map; use Friendica\Util\Map;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -487,7 +486,7 @@ class BBCode
continue; continue;
} }
$curlResult = Network::curl($mtch[1], true); $curlResult = HTTPRequest::curl($mtch[1], true);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
continue; continue;
} }
@ -1108,7 +1107,7 @@ class BBCode
$text = "[url=" . $match[2] . ']' . $match[2] . "[/url]"; $text = "[url=" . $match[2] . ']' . $match[2] . "[/url]";
// if its not a picture then look if its a page that contains a picture link // if its not a picture then look if its a page that contains a picture link
$body = Network::fetchUrl($match[1]); $body = HTTPRequest::fetchUrl($match[1]);
$doc = new DOMDocument(); $doc = new DOMDocument();
@$doc->loadHTML($body); @$doc->loadHTML($body);
@ -1187,7 +1186,7 @@ class BBCode
} }
// if its not a picture then look if its a page that contains a picture link // if its not a picture then look if its a page that contains a picture link
$body = Network::fetchUrl($match[1]); $body = HTTPRequest::fetchUrl($match[1]);
$doc = new DOMDocument(); $doc = new DOMDocument();
@$doc->loadHTML($body); @$doc->loadHTML($body);

View file

@ -27,8 +27,8 @@ use Friendica\Core\Config\Cache;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPRequest;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
/** /**
@ -548,11 +548,11 @@ class Installer
$help = ""; $help = "";
$error_msg = ""; $error_msg = "";
if (function_exists('curl_init')) { if (function_exists('curl_init')) {
$fetchResult = Network::fetchUrlFull($baseurl . "/install/testrewrite"); $fetchResult = HTTPRequest::fetchUrlFull($baseurl . "/install/testrewrite");
$url = Strings::normaliseLink($baseurl . "/install/testrewrite"); $url = Strings::normaliseLink($baseurl . "/install/testrewrite");
if ($fetchResult->getReturnCode() != 204) { if ($fetchResult->getReturnCode() != 204) {
$fetchResult = Network::fetchUrlFull($url); $fetchResult = HTTPRequest::fetchUrlFull($url);
} }
if ($fetchResult->getReturnCode() != 204) { if ($fetchResult->getReturnCode() != 204) {

View file

@ -21,7 +21,7 @@
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
/** /**
* Manage compatibility with federated networks * Manage compatibility with federated networks
@ -123,7 +123,7 @@ class Protocol
if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) { if (preg_match('=https?://(.*)/user/(.*)=ism', $profile_url, $matches)) {
$statusnet_host = $matches[1]; $statusnet_host = $matches[1];
$statusnet_user = $matches[2]; $statusnet_user = $matches[2];
$UserData = Network::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user); $UserData = HTTPRequest::fetchUrl('http://' . $statusnet_host . '/api/users/show.json?user_id=' . $statusnet_user);
$user = json_decode($UserData); $user = json_decode($UserData);
if ($user) { if ($user) {
$matches[2] = $user->screen_name; $matches[2] = $user->screen_name;

View file

@ -26,6 +26,7 @@ use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\HTTPRequest;
use Friendica\Object\Search\ContactResult; use Friendica\Object\Search\ContactResult;
use Friendica\Object\Search\ResultList; use Friendica\Object\Search\ResultList;
use Friendica\Util\Network; use Friendica\Util\Network;
@ -123,7 +124,7 @@ class Search
$searchUrl .= '&page=' . $page; $searchUrl .= '&page=' . $page;
} }
$resultJson = Network::fetchUrl($searchUrl, false, 0, 'application/json'); $resultJson = HTTPRequest::fetchUrl($searchUrl, false, 0, 'application/json');
$results = json_decode($resultJson, true); $results = json_decode($resultJson, true);
@ -284,7 +285,7 @@ class Search
$return = GContact::searchByName($search, $mode); $return = GContact::searchByName($search, $mode);
} else { } else {
$p = $page > 1 ? 'p=' . $page : ''; $p = $page > 1 ? 'p=' . $page : '';
$curlResult = Network::curl(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), false, ['accept_content' => 'application/json']); $curlResult = HTTPRequest::curl(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), false, ['accept_content' => 'application/json']);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$searchResult = json_decode($curlResult->getBody(), true); $searchResult = json_decode($curlResult->getBody(), true);
if (!empty($searchResult['profiles'])) { if (!empty($searchResult['profiles'])) {

View file

@ -25,8 +25,8 @@ use Friendica\Core;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Process; use Friendica\Model\Process;
use Friendica\Network\HTTPRequest;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
/** /**
* Contains the class for the worker background job processing * Contains the class for the worker background job processing
@ -997,7 +997,7 @@ class Worker
} }
$url = DI::baseUrl() . '/worker'; $url = DI::baseUrl() . '/worker';
Network::fetchUrl($url, false, 1); HTTPRequest::fetchUrl($url, false, 1);
} }
/** /**

View file

@ -24,15 +24,13 @@ namespace Friendica\Model;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityNamespace;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\JsonLD;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings; use Friendica\Util\JsonLD;
use Friendica\Util\Network;
class APContact class APContact
{ {

View file

@ -26,11 +26,12 @@ use DOMXPath;
use Exception; use Exception;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Core\Search; use Friendica\Core\Search;
use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPRequest;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
@ -537,7 +538,7 @@ class GContact
$done[] = DI::baseUrl() . '/poco'; $done[] = DI::baseUrl() . '/poco';
if (strlen(DI::config()->get('system', 'directory'))) { if (strlen(DI::config()->get('system', 'directory'))) {
$x = Network::fetchUrl(Search::getGlobalDirectory() . '/pubsites'); $x = HTTPRequest::fetchUrl(Search::getGlobalDirectory() . '/pubsites');
if (!empty($x)) { if (!empty($x)) {
$j = json_decode($x); $j = json_decode($x);
if (!empty($j->entries)) { if (!empty($j->entries)) {
@ -845,7 +846,7 @@ class GContact
return false; return false;
} }
$curlResult = Network::curl($gserver['noscrape'] . '/' . $data['nick']); $curlResult = HTTPRequest::curl($gserver['noscrape'] . '/' . $data['nick']);
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
$noscrape = json_decode($curlResult->getBody(), true); $noscrape = json_decode($curlResult->getBody(), true);
@ -927,7 +928,7 @@ class GContact
private static function updateFromFeed(array $data) private static function updateFromFeed(array $data)
{ {
// Search for the newest entry in the feed // Search for the newest entry in the feed
$curlResult = Network::curl($data['poll']); $curlResult = HTTPRequest::curl($data['poll']);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
$fields = ['failed' => true, 'last_failure' => DateTimeFormat::utcNow()]; $fields = ['failed' => true, 'last_failure' => DateTimeFormat::utcNow()];
DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]); DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]);
@ -1205,7 +1206,7 @@ class GContact
$url = $server . '/main/statistics'; $url = $server . '/main/statistics';
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return false; return false;
} }

View file

@ -23,20 +23,21 @@ namespace Friendica\Model;
use DOMDocument; use DOMDocument;
use DOMXPath; use DOMXPath;
use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Module\Register; use Friendica\Module\Register;
use Friendica\Network\CurlResult; use Friendica\Network\CurlResult;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\PortableContact;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Protocol\PortableContact;
use Friendica\Protocol\Diaspora;
/** /**
* This class handles GServer related functions * This class handles GServer related functions
@ -309,7 +310,7 @@ class GServer
// When a nodeinfo is present, we don't need to dig further // When a nodeinfo is present, we don't need to dig further
$xrd_timeout = DI::config()->get('system', 'xrd_timeout'); $xrd_timeout = DI::config()->get('system', 'xrd_timeout');
$curlResult = Network::curl($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]); $curlResult = HTTPRequest::curl($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::setFailure($url); self::setFailure($url);
return false; return false;
@ -342,7 +343,7 @@ class GServer
$basedata = ['detection-method' => self::DETECT_MANUAL]; $basedata = ['detection-method' => self::DETECT_MANUAL];
} }
$curlResult = Network::curl($baseurl, false, ['timeout' => $xrd_timeout]); $curlResult = HTTPRequest::curl($baseurl, false, ['timeout' => $xrd_timeout]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$basedata = self::analyseRootHeader($curlResult, $basedata); $basedata = self::analyseRootHeader($curlResult, $basedata);
$basedata = self::analyseRootBody($curlResult, $basedata, $baseurl); $basedata = self::analyseRootBody($curlResult, $basedata, $baseurl);
@ -498,7 +499,7 @@ class GServer
{ {
Logger::info('Discover relay data', ['server' => $server_url]); Logger::info('Discover relay data', ['server' => $server_url]);
$curlResult = Network::curl($server_url . '/.well-known/x-social-relay'); $curlResult = HTTPRequest::curl($server_url . '/.well-known/x-social-relay');
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return; return;
} }
@ -579,7 +580,7 @@ class GServer
*/ */
private static function fetchStatistics(string $url) private static function fetchStatistics(string $url)
{ {
$curlResult = Network::curl($url . '/statistics.json'); $curlResult = HTTPRequest::curl($url . '/statistics.json');
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return []; return [];
} }
@ -689,7 +690,8 @@ class GServer
*/ */
private static function parseNodeinfo1(string $nodeinfo_url) private static function parseNodeinfo1(string $nodeinfo_url)
{ {
$curlResult = Network::curl($nodeinfo_url); $curlResult = HTTPRequest::curl($nodeinfo_url);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return []; return [];
} }
@ -765,7 +767,7 @@ class GServer
*/ */
private static function parseNodeinfo2(string $nodeinfo_url) private static function parseNodeinfo2(string $nodeinfo_url)
{ {
$curlResult = Network::curl($nodeinfo_url); $curlResult = HTTPRequest::curl($nodeinfo_url);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return []; return [];
} }
@ -842,7 +844,7 @@ class GServer
*/ */
private static function fetchSiteinfo(string $url, array $serverdata) private static function fetchSiteinfo(string $url, array $serverdata)
{ {
$curlResult = Network::curl($url . '/siteinfo.json'); $curlResult = HTTPRequest::curl($url . '/siteinfo.json');
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return $serverdata; return $serverdata;
} }
@ -911,7 +913,7 @@ class GServer
private static function validHostMeta(string $url) private static function validHostMeta(string $url)
{ {
$xrd_timeout = DI::config()->get('system', 'xrd_timeout'); $xrd_timeout = DI::config()->get('system', 'xrd_timeout');
$curlResult = Network::curl($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]); $curlResult = HTTPRequest::curl($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return false; return false;
} }
@ -1007,7 +1009,7 @@ class GServer
{ {
$serverdata['poco'] = ''; $serverdata['poco'] = '';
$curlResult = Network::curl($url. '/poco'); $curlResult = HTTPRequest::curl($url . '/poco');
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return $serverdata; return $serverdata;
} }
@ -1037,7 +1039,7 @@ class GServer
*/ */
public static function checkMastodonDirectory(string $url, array $serverdata) public static function checkMastodonDirectory(string $url, array $serverdata)
{ {
$curlResult = Network::curl($url . '/api/v1/directory?limit=1'); $curlResult = HTTPRequest::curl($url . '/api/v1/directory?limit=1');
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return $serverdata; return $serverdata;
} }
@ -1064,7 +1066,8 @@ class GServer
*/ */
private static function detectNextcloud(string $url, array $serverdata) private static function detectNextcloud(string $url, array $serverdata)
{ {
$curlResult = Network::curl($url . '/status.php'); $curlResult = HTTPRequest::curl($url . '/status.php');
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
return $serverdata; return $serverdata;
} }
@ -1097,7 +1100,8 @@ class GServer
*/ */
private static function detectMastodonAlikes(string $url, array $serverdata) private static function detectMastodonAlikes(string $url, array $serverdata)
{ {
$curlResult = Network::curl($url . '/api/v1/instance'); $curlResult = HTTPRequest::curl($url . '/api/v1/instance');
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
return $serverdata; return $serverdata;
} }
@ -1162,7 +1166,7 @@ class GServer
*/ */
private static function detectHubzilla(string $url, array $serverdata) private static function detectHubzilla(string $url, array $serverdata)
{ {
$curlResult = Network::curl($url . '/api/statusnet/config.json'); $curlResult = HTTPRequest::curl($url . '/api/statusnet/config.json');
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
return $serverdata; return $serverdata;
} }
@ -1260,7 +1264,7 @@ class GServer
private static function detectGNUSocial(string $url, array $serverdata) private static function detectGNUSocial(string $url, array $serverdata)
{ {
// Test for GNU Social // Test for GNU Social
$curlResult = Network::curl($url . '/api/gnusocial/version.json'); $curlResult = HTTPRequest::curl($url . '/api/gnusocial/version.json');
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') && if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) { ($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$serverdata['platform'] = 'gnusocial'; $serverdata['platform'] = 'gnusocial';
@ -1278,7 +1282,7 @@ class GServer
} }
// Test for Statusnet // Test for Statusnet
$curlResult = Network::curl($url . '/api/statusnet/version.json'); $curlResult = HTTPRequest::curl($url . '/api/statusnet/version.json');
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') && if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) { ($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
@ -1314,9 +1318,9 @@ class GServer
*/ */
private static function detectFriendica(string $url, array $serverdata) private static function detectFriendica(string $url, array $serverdata)
{ {
$curlResult = Network::curl($url . '/friendica/json'); $curlResult = HTTPRequest::curl($url . '/friendica/json');
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
$curlResult = Network::curl($url . '/friendika/json'); $curlResult = HTTPRequest::curl($url . '/friendika/json');
$friendika = true; $friendika = true;
$platform = 'Friendika'; $platform = 'Friendika';
} else { } else {
@ -1631,7 +1635,7 @@ class GServer
$protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus']; $protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus'];
foreach ($protocols as $protocol) { foreach ($protocols as $protocol) {
$query = '{nodes(protocol:"' . $protocol . '"){host}}'; $query = '{nodes(protocol:"' . $protocol . '"){host}}';
$curlResult = Network::fetchUrl('https://the-federation.info/graphql?query=' . urlencode($query)); $curlResult = HTTPRequest::fetchUrl('https://the-federation.info/graphql?query=' . urlencode($query));
if (!empty($curlResult)) { if (!empty($curlResult)) {
$data = json_decode($curlResult, true); $data = json_decode($curlResult, true);
if (!empty($data['data']['nodes'])) { if (!empty($data['data']['nodes'])) {
@ -1649,7 +1653,8 @@ class GServer
if (!empty($accesstoken)) { if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0'; $api = 'https://instances.social/api/1.0/instances/list?count=0';
$header = ['Authorization: Bearer '.$accesstoken]; $header = ['Authorization: Bearer '.$accesstoken];
$curlResult = Network::curl($api, false, ['headers' => $header]); $curlResult = HTTPRequest::curl($api, false, ['headers' => $header]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$servers = json_decode($curlResult->getBody(), true); $servers = json_decode($curlResult->getBody(), true);

View file

@ -28,10 +28,10 @@ use Friendica\Database\DBA;
use Friendica\Database\DBStructure; use Friendica\Database\DBStructure;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Storage\SystemResource; use Friendica\Model\Storage\SystemResource;
use Friendica\Network\HTTPRequest;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Security; use Friendica\Util\Security;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -421,7 +421,7 @@ class Photo
$filename = basename($image_url); $filename = basename($image_url);
if (!empty($image_url)) { if (!empty($image_url)) {
$ret = Network::curl($image_url, true); $ret = HTTPRequest::curl($image_url, true);
$img_str = $ret->getBody(); $img_str = $ret->getBody();
$type = $ret->getContentType(); $type = $ret->getContentType();
} else { } else {

View file

@ -33,6 +33,7 @@ use Friendica\Core\Session;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPRequest;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -737,7 +738,7 @@ class Profile
$magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request; $magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request;
// We have to check if the remote server does understand /magic without invoking something // We have to check if the remote server does understand /magic without invoking something
$serverret = Network::curl($basepath . '/magic'); $serverret = HTTPRequest::curl($basepath . '/magic');
if ($serverret->isSuccess()) { if ($serverret->isSuccess()) {
Logger::log('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path, Logger::DEBUG); Logger::log('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path, Logger::DEBUG);
System::externalRedirect($magic_path); System::externalRedirect($magic_path);

View file

@ -34,6 +34,7 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\TwoFactor\AppSpecificPassword; use Friendica\Model\TwoFactor\AppSpecificPassword;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPRequest;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -823,7 +824,7 @@ class User
$photo_failure = false; $photo_failure = false;
$filename = basename($photo); $filename = basename($photo);
$curlResult = Network::curl($photo, true); $curlResult = HTTPRequest::curl($photo, true);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$img_str = $curlResult->getBody(); $img_str = $curlResult->getBody();
$type = $curlResult->getContentType(); $type = $curlResult->getContentType();

View file

@ -31,12 +31,10 @@ use Friendica\Database\DBStructure;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Register; use Friendica\Model\Register;
use Friendica\Module\BaseAdmin; use Friendica\Module\BaseAdmin;
use Friendica\Module\Update\Profile;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Render\FriendicaSmarty; use Friendica\Network\HTTPRequest;
use Friendica\Util\ConfigFileLoader; use Friendica\Util\ConfigFileLoader;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
class Summary extends BaseAdmin class Summary extends BaseAdmin
{ {
@ -249,7 +247,7 @@ class Summary extends BaseAdmin
private static function checkSelfHostMeta() private static function checkSelfHostMeta()
{ {
// Fetch the host-meta to check if this really is a vital server // Fetch the host-meta to check if this really is a vital server
return Network::curl(DI::baseUrl()->get() . '/.well-known/host-meta')->isSuccess(); return HTTPRequest::curl(DI::baseUrl()->get() . '/.well-known/host-meta')->isSuccess();
} }
} }

View file

@ -25,8 +25,8 @@ use Friendica\BaseModule;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
use Friendica\Model; use Friendica\Model;
use Friendica\Network\HTTPRequest;
use Friendica\Protocol; use Friendica\Protocol;
use Friendica\Util\Network;
/** /**
* Tests a given feed of a contact * Tests a given feed of a contact
@ -49,7 +49,7 @@ class Feed extends BaseModule
$contact = Model\Contact::getByURLForUser($url, local_user(), false); $contact = Model\Contact::getByURLForUser($url, local_user(), false);
$xml = Network::fetchUrl($contact['poll']); $xml = HTTPRequest::fetchUrl($contact['poll']);
$import_result = Protocol\Feed::import($xml); $import_result = Protocol\Feed::import($xml);

View file

@ -27,8 +27,8 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPRequest;
use Friendica\Util\HTTPSignature; use Friendica\Util\HTTPSignature;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
/** /**
@ -101,7 +101,7 @@ class Magic extends BaseModule
); );
// Try to get an authentication token from the other instance. // Try to get an authentication token from the other instance.
$curlResult = Network::curl($basepath . '/owa', false, ['headers' => $headers]); $curlResult = HTTPRequest::curl($basepath . '/owa', false, ['headers' => $headers]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$j = json_decode($curlResult->getBody(), true); $j = json_decode($curlResult->getBody(), true);

364
src/Network/HTTPRequest.php Normal file
View file

@ -0,0 +1,364 @@
<?php
/**
* @copyright Copyright (C) 2020, Friendica
*
* @license GNU APGL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Network;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Util\Network;
/**
* Performs HTTP requests to a given URL
*/
class HTTPRequest
{
/**
* fetches an URL.
*
* @param string $url URL to fetch
* @param bool $binary default false
* TRUE if asked to return binary results (file download)
* @param array $opts (optional parameters) assoziative array with:
* 'accept_content' => supply Accept: header with 'accept_content' as the value
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
* 'http_auth' => username:password
* 'novalidate' => do not validate SSL certs, default is to validate using our CA list
* 'nobody' => only return the header
* 'cookiejar' => path to cookie jar file
* 'header' => header array
* @param int $redirects The recursion counter for internal use - default 0
*
* @return CurlResult
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function curl(string $url, bool $binary = false, array $opts = [], int &$redirects = 0)
{
$stamp1 = microtime(true);
$a = DI::app();
if (strlen($url) > 1000) {
Logger::log('URL is longer than 1000 characters. Callstack: ' . System::callstack(20), Logger::DEBUG);
return CurlResult::createErrorCurl(substr($url, 0, 200));
}
$parts2 = [];
$parts = parse_url($url);
$path_parts = explode('/', $parts['path'] ?? '');
foreach ($path_parts as $part) {
if (strlen($part) <> mb_strlen($part)) {
$parts2[] = rawurlencode($part);
} else {
$parts2[] = $part;
}
}
$parts['path'] = implode('/', $parts2);
$url = Network::unparseURL($parts);
if (Network::isUrlBlocked($url)) {
Logger::log('domain of ' . $url . ' is blocked', Logger::DATA);
return CurlResult::createErrorCurl($url);
}
$ch = @curl_init($url);
if (($redirects > 8) || (!$ch)) {
return CurlResult::createErrorCurl($url);
}
@curl_setopt($ch, CURLOPT_HEADER, true);
if (!empty($opts['cookiejar'])) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]);
curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]);
}
// These settings aren't needed. We're following the location already.
// @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
if (!empty($opts['accept_content'])) {
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
['Accept: ' . $opts['accept_content']]
);
}
if (!empty($opts['header'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['header']);
}
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
$range = intval(DI::config()->get('system', 'curl_range_bytes', 0));
if ($range > 0) {
@curl_setopt($ch, CURLOPT_RANGE, '0-' . $range);
}
// Without this setting it seems as if some webservers send compressed content
// This seems to confuse curl so that it shows this uncompressed.
/// @todo We could possibly set this value to "gzip" or something similar
curl_setopt($ch, CURLOPT_ENCODING, '');
if (!empty($opts['headers'])) {
@curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
}
if (!empty($opts['nobody'])) {
@curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']);
}
if (!empty($opts['timeout'])) {
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
} else {
$curl_time = DI::config()->get('system', 'curl_timeout', 60);
@curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
}
// by default we will allow self-signed certs
// but you can override this
$check_cert = DI::config()->get('system', 'verifyssl');
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$proxy = DI::config()->get('system', 'proxy');
if (strlen($proxy)) {
@curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
@curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxyuser = @DI::config()->get('system', 'proxyuser');
if (strlen($proxyuser)) {
@curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
}
}
if (DI::config()->get('system', 'ipv4_resolve', false)) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
if ($binary) {
@curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
}
// don't let curl abort the entire application
// if it throws any errors.
$s = @curl_exec($ch);
$curl_info = @curl_getinfo($ch);
// Special treatment for HTTP Code 416
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416
if (($curl_info['http_code'] == 416) && ($range > 0)) {
@curl_setopt($ch, CURLOPT_RANGE, '');
$s = @curl_exec($ch);
$curl_info = @curl_getinfo($ch);
}
$curlResponse = new CurlResult($url, $s, $curl_info, curl_errno($ch), curl_error($ch));
if ($curlResponse->isRedirectUrl()) {
$redirects++;
Logger::log('curl: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
@curl_close($ch);
return self::curl($curlResponse->getRedirectUrl(), $binary, $opts, $redirects);
}
@curl_close($ch);
DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack());
return $curlResponse;
}
/**
* Send POST request to $url
*
* @param string $url URL to post
* @param mixed $params array of POST variables
* @param array $headers HTTP headers
* @param int $redirects Recursion counter for internal use - default = 0
* @param int $timeout The timeout in seconds, default system config value or 60 seconds
*
* @return CurlResult The content
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function post(string $url, $params, array $headers = [], int $timeout = 0, int &$redirects = 0)
{
$stamp1 = microtime(true);
if (Network::isUrlBlocked($url)) {
Logger::log('post_url: domain of ' . $url . ' is blocked', Logger::DATA);
return CurlResult::createErrorCurl($url);
}
$a = DI::app();
$ch = curl_init($url);
if (($redirects > 8) || (!$ch)) {
return CurlResult::createErrorCurl($url);
}
Logger::log('post_url: start ' . $url, Logger::DATA);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
if (DI::config()->get('system', 'ipv4_resolve', false)) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
if (intval($timeout)) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
} else {
$curl_time = DI::config()->get('system', 'curl_timeout', 60);
curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
}
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$check_cert = DI::config()->get('system', 'verifyssl');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$proxy = DI::config()->get('system', 'proxy');
if (strlen($proxy)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxyuser = DI::config()->get('system', 'proxyuser');
if (strlen($proxyuser)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
}
}
// don't let curl abort the entire application
// if it throws any errors.
$s = @curl_exec($ch);
$curl_info = curl_getinfo($ch);
$curlResponse = new CurlResult($url, $s, $curl_info, curl_errno($ch), curl_error($ch));
if ($curlResponse->isRedirectUrl()) {
$redirects++;
Logger::log('post_url: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
curl_close($ch);
return self::post($curlResponse->getRedirectUrl(), $params, $headers, $redirects, $timeout);
}
curl_close($ch);
DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack());
// Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed
if ($curlResponse->getReturnCode() == 417) {
$redirects++;
if (empty($headers)) {
$headers = ['Expect:'];
} else {
if (!in_array('Expect:', $headers)) {
array_push($headers, 'Expect:');
}
}
Logger::info('Server responds with 417, applying workaround', ['url' => $url]);
return self::post($url, $params, $headers, $redirects, $timeout);
}
Logger::log('post_url: end ' . $url, Logger::DATA);
return $curlResponse;
}
/**
* Curl wrapper
*
* If binary flag is true, return binary results.
* Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
* to preserve cookies from one request to the next.
*
* @param string $url URL to fetch
* @param bool $binary default false
* TRUE if asked to return binary results (file download)
* @param int $timeout Timeout in seconds, default system config value or 60 seconds
* @param string $accept_content supply Accept: header with 'accept_content' as the value
* @param string $cookiejar Path to cookie jar file
* @param int $redirects The recursion counter for internal use - default 0
*
* @return string The fetched content
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function fetchUrl(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
{
$ret = self::fetchUrlFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects);
return $ret->getBody();
}
/**
* Curl wrapper with array of return values.
*
* Inner workings and parameters are the same as @ref fetchUrl but returns an array with
* all the information collected during the fetch.
*
* @param string $url URL to fetch
* @param bool $binary default false
* TRUE if asked to return binary results (file download)
* @param int $timeout Timeout in seconds, default system config value or 60 seconds
* @param string $accept_content supply Accept: header with 'accept_content' as the value
* @param string $cookiejar Path to cookie jar file
* @param int $redirects The recursion counter for internal use - default 0
*
* @return CurlResult With all relevant information, 'body' contains the actual fetched content.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function fetchUrlFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
{
return self::curl(
$url,
$binary,
[
'timeout' => $timeout,
'accept_content' => $accept_content,
'cookiejar' => $cookiejar
],
$redirects
);
}
}

View file

@ -166,7 +166,7 @@ class Probe
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]); Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]);
$xrd = null; $xrd = null;
$curlResult = Network::curl($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); $curlResult = HTTPRequest::curl($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0); $ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$xml = $curlResult->getBody(); $xml = $curlResult->getBody();
@ -183,7 +183,7 @@ class Probe
} }
if (!is_object($xrd) && !empty($url)) { if (!is_object($xrd) && !empty($url)) {
$curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); $curlResult = HTTPRequest::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
$connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0); $connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $url]); Logger::info('Probing timeout', ['url' => $url]);
@ -427,7 +427,7 @@ class Probe
*/ */
private static function getHideStatus($url) private static function getHideStatus($url)
{ {
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return false; return false;
} }
@ -841,7 +841,7 @@ class Probe
public static function pollZot($url, $data) public static function pollZot($url, $data)
{ {
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
return $data; return $data;
} }
@ -938,7 +938,7 @@ class Probe
{ {
$xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20); $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
$curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]); $curlResult = HTTPRequest::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];
@ -1007,7 +1007,7 @@ class Probe
*/ */
private static function pollNoscrape($noscrape_url, $data) private static function pollNoscrape($noscrape_url, $data)
{ {
$curlResult = Network::curl($noscrape_url); $curlResult = HTTPRequest::curl($noscrape_url);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];
@ -1265,7 +1265,7 @@ class Probe
*/ */
private static function pollHcard($hcard_url, $data, $dfrn = false) private static function pollHcard($hcard_url, $data, $dfrn = false)
{ {
$curlResult = Network::curl($hcard_url); $curlResult = HTTPRequest::curl($hcard_url);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];
@ -1519,7 +1519,7 @@ class Probe
$pubkey = substr($pubkey, 5); $pubkey = substr($pubkey, 5);
} }
} elseif (Strings::normaliseLink($pubkey) == 'http://') { } elseif (Strings::normaliseLink($pubkey) == 'http://') {
$curlResult = Network::curl($pubkey); $curlResult = HTTPRequest::curl($pubkey);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return $short ? false : []; return $short ? false : [];
@ -1552,7 +1552,7 @@ class Probe
} }
// Fetch all additional data from the feed // Fetch all additional data from the feed
$curlResult = Network::curl($data["poll"]); $curlResult = HTTPRequest::curl($data["poll"]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];
@ -1604,7 +1604,7 @@ class Probe
*/ */
private static function pumpioProfileData($profile_link) private static function pumpioProfileData($profile_link)
{ {
$curlResult = Network::curl($profile_link); $curlResult = HTTPRequest::curl($profile_link);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return []; return [];
} }
@ -1835,7 +1835,7 @@ class Probe
*/ */
private static function feed($url, $probe = true) private static function feed($url, $probe = true)
{ {
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];

View file

@ -21,12 +21,12 @@
namespace Friendica\Protocol; namespace Friendica\Protocol;
use Friendica\Util\JsonLD;
use Friendica\Util\Network;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Model\APContact; use Friendica\Model\APContact;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
use Friendica\Util\HTTPSignature; use Friendica\Util\HTTPSignature;
use Friendica\Util\JsonLD;
/** /**
* ActivityPub Protocol class * ActivityPub Protocol class
@ -93,7 +93,7 @@ class ActivityPub
return HTTPSignature::fetch($url, $uid); return HTTPSignature::fetch($url, $uid);
} }
$curlResult = Network::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']); $curlResult = HTTPRequest::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return false; return false;
} }

View file

@ -43,6 +43,7 @@ use Friendica\Model\Post\Category;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -1194,7 +1195,7 @@ class DFRN
Logger::log('dfrn_deliver: ' . $url); Logger::log('dfrn_deliver: ' . $url);
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
return -2; // timed out return -2; // timed out
@ -1343,7 +1344,7 @@ class DFRN
Logger::debug('dfrn_deliver', ['post' => $postvars]); Logger::debug('dfrn_deliver', ['post' => $postvars]);
$postResult = Network::post($contact['notify'], $postvars); $postResult = HTTPRequest::post($contact['notify'], $postvars);
$xml = $postResult->getBody(); $xml = $postResult->getBody();
@ -1440,7 +1441,7 @@ class DFRN
$content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json"); $content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json");
$postResult = Network::post($dest_url, $envelope, ["Content-Type: ".$content_type]); $postResult = HTTPRequest::post($dest_url, $envelope, ["Content-Type: " . $content_type]);
$xml = $postResult->getBody(); $xml = $postResult->getBody();
$curl_stat = $postResult->getReturnCode(); $curl_stat = $postResult->getReturnCode();

View file

@ -41,6 +41,7 @@ use Friendica\Model\Mail;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -1379,7 +1380,7 @@ class Diaspora
Logger::log("Fetch post from ".$source_url, Logger::DEBUG); Logger::log("Fetch post from ".$source_url, Logger::DEBUG);
$envelope = Network::fetchUrl($source_url); $envelope = HTTPRequest::fetchUrl($source_url);
if ($envelope) { if ($envelope) {
Logger::log("Envelope was fetched.", Logger::DEBUG); Logger::log("Envelope was fetched.", Logger::DEBUG);
$x = self::verifyMagicEnvelope($envelope); $x = self::verifyMagicEnvelope($envelope);
@ -3260,7 +3261,7 @@ class Diaspora
if (!intval(DI::config()->get("system", "diaspora_test"))) { if (!intval(DI::config()->get("system", "diaspora_test"))) {
$content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json"); $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
$postResult = Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]); $postResult = HTTPRequest::post($dest_url . "/", $envelope, ["Content-Type: " . $content_type]);
$return_code = $postResult->getReturnCode(); $return_code = $postResult->getReturnCode();
} else { } else {
Logger::log("test_mode"); Logger::log("test_mode");

View file

@ -39,10 +39,10 @@ use Friendica\Model\Item;
use Friendica\Model\ItemURI; use Friendica\Model\ItemURI;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -756,7 +756,7 @@ class OStatus
self::$conv_list[$conversation] = true; self::$conv_list[$conversation] = true;
$curlResult = Network::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']); $curlResult = HTTPRequest::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return; return;
@ -785,7 +785,7 @@ class OStatus
} }
} }
if ($file != '') { if ($file != '') {
$conversation_atom = Network::curl($attribute['href']); $conversation_atom = HTTPRequest::curl($attribute['href']);
if ($conversation_atom->isSuccess()) { if ($conversation_atom->isSuccess()) {
$xml = $conversation_atom->getBody(); $xml = $conversation_atom->getBody();
@ -902,7 +902,7 @@ class OStatus
return; return;
} }
$curlResult = Network::curl($self); $curlResult = HTTPRequest::curl($self);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return; return;
@ -949,7 +949,7 @@ class OStatus
} }
$stored = false; $stored = false;
$curlResult = Network::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']); $curlResult = HTTPRequest::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return; return;
@ -980,7 +980,7 @@ class OStatus
} }
} }
if ($atom_file != '') { if ($atom_file != '') {
$curlResult = Network::curl($atom_file); $curlResult = HTTPRequest::curl($atom_file);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
Logger::log('Fetched XML for URI ' . $related_uri, Logger::DEBUG); Logger::log('Fetched XML for URI ' . $related_uri, Logger::DEBUG);
@ -992,7 +992,7 @@ class OStatus
// Workaround for older GNU Social servers // Workaround for older GNU Social servers
if (($xml == '') && strstr($related, '/notice/')) { if (($xml == '') && strstr($related, '/notice/')) {
$curlResult = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); $curlResult = HTTPRequest::curl(str_replace('/notice/', '/api/statuses/show/', $related) . '.atom');
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
Logger::log('GNU Social workaround to fetch XML for URI ' . $related_uri, Logger::DEBUG); Logger::log('GNU Social workaround to fetch XML for URI ' . $related_uri, Logger::DEBUG);
@ -1003,7 +1003,7 @@ class OStatus
// Even more worse workaround for GNU Social ;-) // Even more worse workaround for GNU Social ;-)
if ($xml == '') { if ($xml == '') {
$related_guess = self::convertHref($related_uri); $related_guess = self::convertHref($related_uri);
$curlResult = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); $curlResult = HTTPRequest::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess) . '.atom');
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
Logger::log('GNU Social workaround 2 to fetch XML for URI ' . $related_uri, Logger::DEBUG); Logger::log('GNU Social workaround 2 to fetch XML for URI ' . $related_uri, Logger::DEBUG);

View file

@ -30,8 +30,8 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\GServer; use Friendica\Model\GServer;
use Friendica\Network\HTTPRequest;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
/** /**
@ -103,7 +103,7 @@ class PortableContact
Logger::log('load: ' . $url, Logger::DEBUG); Logger::log('load: ' . $url, Logger::DEBUG);
$fetchresult = Network::fetchUrlFull($url); $fetchresult = HTTPRequest::fetchUrlFull($url);
$s = $fetchresult->getBody(); $s = $fetchresult->getBody();
Logger::log('load: returns ' . $s, Logger::DATA); Logger::log('load: returns ' . $s, Logger::DATA);
@ -251,7 +251,7 @@ class PortableContact
*/ */
private static function fetchServerlist($poco) private static function fetchServerlist($poco)
{ {
$curlResult = Network::curl($poco . "/@server"); $curlResult = HTTPRequest::curl($poco . "/@server");
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return; return;
@ -291,7 +291,7 @@ class PortableContact
Logger::info("Fetch all users from the server " . $server["url"]); Logger::info("Fetch all users from the server " . $server["url"]);
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
$data = json_decode($curlResult->getBody(), true); $data = json_decode($curlResult->getBody(), true);
@ -314,7 +314,7 @@ class PortableContact
$success = false; $success = false;
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
Logger::info("Fetch all global contacts from the server " . $server["nurl"]); Logger::info("Fetch all global contacts from the server " . $server["nurl"]);
@ -372,7 +372,7 @@ class PortableContact
// Fetch all contacts from a given user from the other server // Fetch all contacts from a given user from the other server
$url = $server['poco'] . '/' . $username . '/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,contactType,generation'; $url = $server['poco'] . '/' . $username . '/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,contactType,generation';
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$data = json_decode($curlResult->getBody(), true); $data = json_decode($curlResult->getBody(), true);

View file

@ -22,9 +22,9 @@
namespace Friendica\Protocol; namespace Friendica\Protocol;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Network\HTTPRequest;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -72,7 +72,7 @@ class Salmon
$ret[$x] = substr($ret[$x], 5); $ret[$x] = substr($ret[$x], 5);
} }
} elseif (Strings::normaliseLink($ret[$x]) == 'http://') { } elseif (Strings::normaliseLink($ret[$x]) == 'http://') {
$ret[$x] = Network::fetchUrl($ret[$x]); $ret[$x] = HTTPRequest::fetchUrl($ret[$x]);
} }
} }
} }
@ -155,7 +155,7 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
$postResult = Network::post($url, $salmon, [ $postResult = HTTPRequest::post($url, $salmon, [
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon) 'Content-length: ' . strlen($salmon)
]); ]);
@ -180,7 +180,7 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
$postResult = Network::post($url, $salmon, [ $postResult = HTTPRequest::post($url, $salmon, [
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon) 'Content-length: ' . strlen($salmon)
]); ]);
@ -203,7 +203,7 @@ class Salmon
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces); $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
// slap them // slap them
$postResult = Network::post($url, $salmon, [ $postResult = HTTPRequest::post($url, $salmon, [
'Content-type: application/magic-envelope+xml', 'Content-type: application/magic-envelope+xml',
'Content-length: ' . strlen($salmon)]); 'Content-length: ' . strlen($salmon)]);
$return_code = $postResult->getReturnCode(); $return_code = $postResult->getReturnCode();

View file

@ -37,6 +37,7 @@ namespace Friendica\Util;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
class ExAuth class ExAuth
{ {
@ -181,7 +182,7 @@ class ExAuth
$url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user;
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return false; return false;

View file

@ -21,11 +21,12 @@
namespace Friendica\Util; namespace Friendica\Util;
use Friendica\Database\DBA;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\User;
use Friendica\Model\APContact; use Friendica\Model\APContact;
use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
/** /**
* Implements HTTP Signatures per draft-cavage-http-signatures-07. * Implements HTTP Signatures per draft-cavage-http-signatures-07.
@ -297,7 +298,7 @@ class HTTPSignature
$headers[] = 'Content-Type: application/activity+json'; $headers[] = 'Content-Type: application/activity+json';
$postResult = Network::post($target, $content, $headers); $postResult = HTTPRequest::post($target, $content, $headers);
$return_code = $postResult->getReturnCode(); $return_code = $postResult->getReturnCode();
Logger::log('Transmit to ' . $target . ' returned ' . $return_code, Logger::DEBUG); Logger::log('Transmit to ' . $target . ' returned ' . $return_code, Logger::DEBUG);
@ -442,7 +443,7 @@ class HTTPSignature
$curl_opts = $opts; $curl_opts = $opts;
$curl_opts['header'] = $headers; $curl_opts['header'] = $headers;
$curlResult = Network::curl($request, false, $curl_opts); $curlResult = HTTPRequest::curl($request, false, $curl_opts);
$return_code = $curlResult->getReturnCode(); $return_code = $curlResult->getReturnCode();
Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG); Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG);

View file

@ -24,6 +24,7 @@ namespace Friendica\Util;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPRequest;
/** /**
* Image utilities * Image utilities
@ -184,7 +185,7 @@ class Images
return $data; return $data;
} }
$img_str = Network::fetchUrl($url, true, 4); $img_str = HTTPRequest::fetchUrl($url, true, 4);
if (!$img_str) { if (!$img_str) {
return []; return [];

View file

@ -27,340 +27,9 @@ use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\CurlResult;
class Network class Network
{ {
/**
* Curl wrapper
*
* If binary flag is true, return binary results.
* Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
* to preserve cookies from one request to the next.
*
* @param string $url URL to fetch
* @param bool $binary default false
* TRUE if asked to return binary results (file download)
* @param int $timeout Timeout in seconds, default system config value or 60 seconds
* @param string $accept_content supply Accept: header with 'accept_content' as the value
* @param string $cookiejar Path to cookie jar file
* @param int $redirects The recursion counter for internal use - default 0
*
* @return string The fetched content
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function fetchUrl(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
{
$ret = self::fetchUrlFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects);
return $ret->getBody();
}
/**
* Curl wrapper with array of return values.
*
* Inner workings and parameters are the same as @ref fetchUrl but returns an array with
* all the information collected during the fetch.
*
* @param string $url URL to fetch
* @param bool $binary default false
* TRUE if asked to return binary results (file download)
* @param int $timeout Timeout in seconds, default system config value or 60 seconds
* @param string $accept_content supply Accept: header with 'accept_content' as the value
* @param string $cookiejar Path to cookie jar file
* @param int $redirects The recursion counter for internal use - default 0
*
* @return CurlResult With all relevant information, 'body' contains the actual fetched content.
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function fetchUrlFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
{
return self::curl(
$url,
$binary,
[
'timeout' => $timeout,
'accept_content' => $accept_content,
'cookiejar' => $cookiejar
],
$redirects
);
}
/**
* fetches an URL.
*
* @param string $url URL to fetch
* @param bool $binary default false
* TRUE if asked to return binary results (file download)
* @param array $opts (optional parameters) assoziative array with:
* 'accept_content' => supply Accept: header with 'accept_content' as the value
* 'timeout' => int Timeout in seconds, default system config value or 60 seconds
* 'http_auth' => username:password
* 'novalidate' => do not validate SSL certs, default is to validate using our CA list
* 'nobody' => only return the header
* 'cookiejar' => path to cookie jar file
* 'header' => header array
* @param int $redirects The recursion counter for internal use - default 0
*
* @return CurlResult
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function curl(string $url, bool $binary = false, array $opts = [], int &$redirects = 0)
{
$stamp1 = microtime(true);
$a = DI::app();
if (strlen($url) > 1000) {
Logger::log('URL is longer than 1000 characters. Callstack: ' . System::callstack(20), Logger::DEBUG);
return CurlResult::createErrorCurl(substr($url, 0, 200));
}
$parts2 = [];
$parts = parse_url($url);
$path_parts = explode('/', $parts['path'] ?? '');
foreach ($path_parts as $part) {
if (strlen($part) <> mb_strlen($part)) {
$parts2[] = rawurlencode($part);
} else {
$parts2[] = $part;
}
}
$parts['path'] = implode('/', $parts2);
$url = self::unparseURL($parts);
if (self::isUrlBlocked($url)) {
Logger::log('domain of ' . $url . ' is blocked', Logger::DATA);
return CurlResult::createErrorCurl($url);
}
$ch = @curl_init($url);
if (($redirects > 8) || (!$ch)) {
return CurlResult::createErrorCurl($url);
}
@curl_setopt($ch, CURLOPT_HEADER, true);
if (!empty($opts['cookiejar'])) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]);
curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]);
}
// These settings aren't needed. We're following the location already.
// @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
if (!empty($opts['accept_content'])) {
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
['Accept: ' . $opts['accept_content']]
);
}
if (!empty($opts['header'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['header']);
}
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
$range = intval(DI::config()->get('system', 'curl_range_bytes', 0));
if ($range > 0) {
@curl_setopt($ch, CURLOPT_RANGE, '0-' . $range);
}
// Without this setting it seems as if some webservers send compressed content
// This seems to confuse curl so that it shows this uncompressed.
/// @todo We could possibly set this value to "gzip" or something similar
curl_setopt($ch, CURLOPT_ENCODING, '');
if (!empty($opts['headers'])) {
@curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
}
if (!empty($opts['nobody'])) {
@curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']);
}
if (!empty($opts['timeout'])) {
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
} else {
$curl_time = DI::config()->get('system', 'curl_timeout', 60);
@curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
}
// by default we will allow self-signed certs
// but you can override this
$check_cert = DI::config()->get('system', 'verifyssl');
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$proxy = DI::config()->get('system', 'proxy');
if (strlen($proxy)) {
@curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
@curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxyuser = @DI::config()->get('system', 'proxyuser');
if (strlen($proxyuser)) {
@curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
}
}
if (DI::config()->get('system', 'ipv4_resolve', false)) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
if ($binary) {
@curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
}
// don't let curl abort the entire application
// if it throws any errors.
$s = @curl_exec($ch);
$curl_info = @curl_getinfo($ch);
// Special treatment for HTTP Code 416
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416
if (($curl_info['http_code'] == 416) && ($range > 0)) {
@curl_setopt($ch, CURLOPT_RANGE, '');
$s = @curl_exec($ch);
$curl_info = @curl_getinfo($ch);
}
$curlResponse = new CurlResult($url, $s, $curl_info, curl_errno($ch), curl_error($ch));
if ($curlResponse->isRedirectUrl()) {
$redirects++;
Logger::log('curl: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
@curl_close($ch);
return self::curl($curlResponse->getRedirectUrl(), $binary, $opts, $redirects);
}
@curl_close($ch);
DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack());
return $curlResponse;
}
/**
* Send POST request to $url
*
* @param string $url URL to post
* @param mixed $params array of POST variables
* @param array $headers HTTP headers
* @param int $redirects Recursion counter for internal use - default = 0
* @param int $timeout The timeout in seconds, default system config value or 60 seconds
*
* @return CurlResult The content
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function post(string $url, $params, array $headers = [], int $timeout = 0, int &$redirects = 0)
{
$stamp1 = microtime(true);
if (self::isUrlBlocked($url)) {
Logger::log('post_url: domain of ' . $url . ' is blocked', Logger::DATA);
return CurlResult::createErrorCurl($url);
}
$a = DI::app();
$ch = curl_init($url);
if (($redirects > 8) || (!$ch)) {
return CurlResult::createErrorCurl($url);
}
Logger::log('post_url: start ' . $url, Logger::DATA);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
if (DI::config()->get('system', 'ipv4_resolve', false)) {
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
}
if (intval($timeout)) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
} else {
$curl_time = DI::config()->get('system', 'curl_timeout', 60);
curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
}
if (!empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$check_cert = DI::config()->get('system', 'verifyssl');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$proxy = DI::config()->get('system', 'proxy');
if (strlen($proxy)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxyuser = DI::config()->get('system', 'proxyuser');
if (strlen($proxyuser)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
}
}
// don't let curl abort the entire application
// if it throws any errors.
$s = @curl_exec($ch);
$curl_info = curl_getinfo($ch);
$curlResponse = new CurlResult($url, $s, $curl_info, curl_errno($ch), curl_error($ch));
if ($curlResponse->isRedirectUrl()) {
$redirects++;
Logger::log('post_url: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
curl_close($ch);
return self::post($curlResponse->getRedirectUrl(), $params, $headers, $redirects, $timeout);
}
curl_close($ch);
DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack());
// Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed
if ($curlResponse->getReturnCode() == 417) {
$redirects++;
if (empty($headers)) {
$headers = ['Expect:'];
} else {
if (!in_array('Expect:', $headers)) {
array_push($headers, 'Expect:');
}
}
Logger::info('Server responds with 417, applying workaround', ['url' => $url]);
return self::post($url, $params, $headers, $redirects, $timeout);
}
Logger::log('post_url: end ' . $url, Logger::DATA);
return $curlResponse;
}
/** /**
* Return raw post data from a post request * Return raw post data from a post request

View file

@ -27,6 +27,7 @@ use Friendica\Content\OEmbed;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Network\HTTPRequest;
/** /**
* Get information about a given URL * Get information about a given URL
@ -159,7 +160,7 @@ class ParseUrl
return $siteinfo; return $siteinfo;
} }
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return $siteinfo; return $siteinfo;
} }

View file

@ -24,7 +24,7 @@ namespace Friendica\Worker;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
/** /**
* Check the git repository VERSION file and save the version to the DB * Check the git repository VERSION file and save the version to the DB
@ -55,7 +55,7 @@ class CheckVersion
Logger::log("Checking VERSION from: ".$checked_url, Logger::DEBUG); Logger::log("Checking VERSION from: ".$checked_url, Logger::DEBUG);
// fetch the VERSION file // fetch the VERSION file
$gitversion = DBA::escape(trim(Network::fetchUrl($checked_url))); $gitversion = DBA::escape(trim(HTTPRequest::fetchUrl($checked_url)));
Logger::log("Upstream VERSION is: ".$gitversion, Logger::DEBUG); Logger::log("Upstream VERSION is: ".$gitversion, Logger::DEBUG);
DI::config()->set('system', 'git_friendica_version', $gitversion); DI::config()->set('system', 'git_friendica_version', $gitversion);

View file

@ -30,12 +30,10 @@ use Friendica\Database\PostUpdate;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\GServer;
use Friendica\Model\Nodeinfo; use Friendica\Model\Nodeinfo;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\Probe; use Friendica\Network\HTTPRequest;
use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -63,7 +61,7 @@ class CronJobs
// Now trying to register // Now trying to register
$url = 'http://the-federation.info/register/' . DI::baseUrl()->getHostname(); $url = 'http://the-federation.info/register/' . DI::baseUrl()->getHostname();
Logger::debug('Check registering url', ['url' => $url]); Logger::debug('Check registering url', ['url' => $url]);
$ret = Network::fetchUrl($url); $ret = HTTPRequest::fetchUrl($url);
Logger::debug('Check registering answer', ['answer' => $ret]); Logger::debug('Check registering answer', ['answer' => $ret]);
Logger::info('cron_end'); Logger::info('cron_end');
break; break;

View file

@ -26,7 +26,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
/** /**
* Sends updated profile data to the directory * Sends updated profile data to the directory
@ -54,7 +54,7 @@ class Directory
Logger::log('Updating directory: ' . $arr['url'], Logger::DEBUG); Logger::log('Updating directory: ' . $arr['url'], Logger::DEBUG);
if (strlen($arr['url'])) { if (strlen($arr['url'])) {
Network::fetchUrl($dir . '?url=' . bin2hex($arr['url'])); HTTPRequest::fetchUrl($dir . '?url=' . bin2hex($arr['url']));
} }
return; return;

View file

@ -28,13 +28,13 @@ use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\Email; use Friendica\Protocol\Email;
use Friendica\Protocol\Feed; use Friendica\Protocol\Feed;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -291,7 +291,7 @@ class OnePoll
. '&type=data&last_update=' . $last_update . '&type=data&last_update=' . $last_update
. '&perm=' . $perm; . '&perm=' . $perm;
$curlResult = Network::curl($url); $curlResult = HTTPRequest::curl($url);
if (!$curlResult->isSuccess() && ($curlResult->getErrorNumber() == CURLE_OPERATION_TIMEDOUT)) { if (!$curlResult->isSuccess() && ($curlResult->getErrorNumber() == CURLE_OPERATION_TIMEDOUT)) {
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
@ -405,7 +405,7 @@ class OnePoll
$postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
$postvars['perm'] = 'rw'; $postvars['perm'] = 'rw';
return Network::post($contact['poll'], $postvars)->getBody(); return HTTPRequest::post($contact['poll'], $postvars)->getBody();
} }
/** /**
@ -444,7 +444,7 @@ class OnePoll
} }
$cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
$curlResult = Network::curl($contact['poll'], false, ['cookiejar' => $cookiejar]); $curlResult = HTTPRequest::curl($contact['poll'], false, ['cookiejar' => $cookiejar]);
unlink($cookiejar); unlink($cookiejar);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
@ -756,7 +756,7 @@ class OnePoll
DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]); DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
} }
$postResult = Network::post($url, $params); $postResult = HTTPRequest::post($url, $params);
Logger::log('subscribe_to_hub: returns: ' . $postResult->getReturnCode(), Logger::DEBUG); Logger::log('subscribe_to_hub: returns: ' . $postResult->getReturnCode(), Logger::DEBUG);

View file

@ -25,8 +25,8 @@ use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\PushSubscriber; use Friendica\Model\PushSubscriber;
use Friendica\Network\HTTPRequest;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
use Friendica\Util\Network;
class PubSubPublish class PubSubPublish
{ {
@ -68,7 +68,7 @@ class PubSubPublish
Logger::log('POST ' . print_r($headers, true) . "\n" . $params, Logger::DATA); Logger::log('POST ' . print_r($headers, true) . "\n" . $params, Logger::DATA);
$postResult = Network::post($subscriber['callback_url'], $params, $headers); $postResult = HTTPRequest::post($subscriber['callback_url'], $params, $headers);
$ret = $postResult->getReturnCode(); $ret = $postResult->getReturnCode();
if ($ret >= 200 && $ret <= 299) { if ($ret >= 200 && $ret <= 299) {

View file

@ -30,7 +30,7 @@ use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\GServer; use Friendica\Model\GServer;
use Friendica\Util\Network; use Friendica\Network\HTTPRequest;
use Friendica\Util\Strings; use Friendica\Util\Strings;
class SearchDirectory class SearchDirectory
@ -52,7 +52,7 @@ class SearchDirectory
} }
} }
$x = Network::fetchUrl(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search)); $x = HTTPRequest::fetchUrl(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search));
$j = json_decode($x); $j = json_decode($x);
if (!empty($j->results)) { if (!empty($j->results)) {