Merge pull request #8911 from MrPetovan/task/curl_DI

Introduce "HTTPRequest" class
This commit is contained in:
Michael Vogel 2020-07-25 09:50:20 +02:00 committed by GitHub
commit 398e65d66b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 765 additions and 647 deletions

View file

@ -21,12 +21,12 @@
namespace Friendica\Protocol;
use Friendica\Util\JsonLD;
use Friendica\Util\Network;
use Friendica\Core\Protocol;
use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\User;
use Friendica\Util\HTTPSignature;
use Friendica\Util\JsonLD;
/**
* ActivityPub Protocol class
@ -87,13 +87,13 @@ class ActivityPub
* @return array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function fetchContent($url, $uid = 0)
public static function fetchContent(string $url, int $uid = 0)
{
if (!empty($uid)) {
return HTTPSignature::fetch($url, $uid);
}
$curlResult = Network::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']);
$curlResult = DI::httpRequest()->get($url, false, ['accept_content' => 'application/activity+json, application/ld+json']);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return false;
}

View file

@ -699,7 +699,7 @@ class Processor
* @return string fetched message URL
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function fetchMissingActivity($url, $child = [])
public static function fetchMissingActivity(string $url, array $child = [])
{
if (!empty($child['receiver'])) {
$uid = ActivityPub\Receiver::getFirstUserFromReceivers($child['receiver']);

View file

@ -1194,7 +1194,7 @@ class DFRN
Logger::log('dfrn_deliver: ' . $url);
$curlResult = Network::curl($url);
$curlResult = DI::httpRequest()->get($url);
if ($curlResult->isTimeout()) {
return -2; // timed out
@ -1343,7 +1343,7 @@ class DFRN
Logger::debug('dfrn_deliver', ['post' => $postvars]);
$postResult = Network::post($contact['notify'], $postvars);
$postResult = DI::httpRequest()->post($contact['notify'], $postvars);
$xml = $postResult->getBody();
@ -1440,7 +1440,7 @@ class DFRN
$content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json");
$postResult = Network::post($dest_url, $envelope, ["Content-Type: ".$content_type]);
$postResult = DI::httpRequest()->post($dest_url, $envelope, ["Content-Type: " . $content_type]);
$xml = $postResult->getBody();
$curl_stat = $postResult->getReturnCode();

View file

@ -1379,7 +1379,7 @@ class Diaspora
Logger::log("Fetch post from ".$source_url, Logger::DEBUG);
$envelope = Network::fetchUrl($source_url);
$envelope = DI::httpRequest()->fetch($source_url);
if ($envelope) {
Logger::log("Envelope was fetched.", Logger::DEBUG);
$x = self::verifyMagicEnvelope($envelope);
@ -3260,7 +3260,7 @@ class Diaspora
if (!intval(DI::config()->get("system", "diaspora_test"))) {
$content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
$postResult = Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
$postResult = DI::httpRequest()->post($dest_url . "/", $envelope, ["Content-Type: " . $content_type]);
$return_code = $postResult->getReturnCode();
} else {
Logger::log("test_mode");

View file

@ -35,6 +35,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Tag;
use Friendica\Model\User;
use Friendica\Network\HTTPRequest;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
@ -350,7 +351,7 @@ class Feed
$orig_plink = $item["plink"];
$item["plink"] = Network::finalUrl($item["plink"]);
$item["plink"] = DI::httpRequest()->finalUrl($item["plink"]);
$item["parent-uri"] = $item["uri"];

View file

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

View file

@ -31,7 +31,6 @@ use Friendica\DI;
use Friendica\Model\GContact;
use Friendica\Model\GServer;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\Strings;
/**
@ -103,7 +102,7 @@ class PortableContact
Logger::log('load: ' . $url, Logger::DEBUG);
$fetchresult = Network::fetchUrlFull($url);
$fetchresult = DI::httpRequest()->fetchFull($url);
$s = $fetchresult->getBody();
Logger::log('load: returns ' . $s, Logger::DATA);
@ -251,7 +250,7 @@ class PortableContact
*/
private static function fetchServerlist($poco)
{
$curlResult = Network::curl($poco . "/@server");
$curlResult = DI::httpRequest()->get($poco . "/@server");
if (!$curlResult->isSuccess()) {
return;
@ -291,7 +290,7 @@ class PortableContact
Logger::info("Fetch all users from the server " . $server["url"]);
$curlResult = Network::curl($url);
$curlResult = DI::httpRequest()->get($url);
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
$data = json_decode($curlResult->getBody(), true);
@ -314,7 +313,7 @@ class PortableContact
$success = false;
$curlResult = Network::curl($url);
$curlResult = DI::httpRequest()->get($url);
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
Logger::info("Fetch all global contacts from the server " . $server["nurl"]);
@ -372,7 +371,7 @@ class PortableContact
// 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';
$curlResult = Network::curl($url);
$curlResult = DI::httpRequest()->get($url);
if ($curlResult->isSuccess()) {
$data = json_decode($curlResult->getBody(), true);

View file

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