1
0
Fork 0

Curl Response Refactoring

- extended Curl to parse Curl Response
- refactored Network::curl()
- replaced every Network::curl() execution with the new Curl container
This commit is contained in:
Philipp Holzer 2018-10-10 21:08:43 +02:00
commit 2dec8895a9
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
20 changed files with 466 additions and 382 deletions

View file

@ -2567,6 +2567,5 @@ function admin_page_features(App $a)
function admin_page_server_vital()
{
// Fetch the host-meta to check if this really is a vital server
$serverret = Network::curl(System::baseUrl() . '/.well-known/host-meta');
return $serverret["success"];
return Network::curl(System::baseUrl() . '/.well-known/host-meta')->isSuccess();
}

View file

@ -32,8 +32,7 @@ function feedtest_content(App $a)
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
$ret = Network::curl($contact['poll']);
$xml = $ret['body'];
$xml = Network::fetchUrl($contact['poll']);
$dummy = null;
$import_result = Feed::import($xml, $importer, $contact, $dummy, true);

View file

@ -44,14 +44,14 @@ function ostatus_subscribe_content(App $a) {
$api = $contact["baseurl"]."/api/";
// Fetching friends
$data = Network::curl($api."statuses/friends.json?screen_name=".$contact["nick"]);
$curlResult = Network::curl($api."statuses/friends.json?screen_name=".$contact["nick"]);
if (!$data["success"]) {
if (!$curlResult->isSuccess()) {
PConfig::delete($uid, "ostatus", "legacy_contact");
return $o.L10n::t("Couldn't fetch friends for contact.");
}
PConfig::set($uid, "ostatus", "legacy_friends", $data["body"]);
PConfig::set($uid, "ostatus", "legacy_friends", $curlResult->getBody());
}
$friends = json_decode(PConfig::get($uid, "ostatus", "legacy_friends"));
@ -72,8 +72,8 @@ function ostatus_subscribe_content(App $a) {
$o .= "<p>".$counter."/".$total.": ".$url;
$data = Probe::uri($url);
if ($data["network"] == Protocol::OSTATUS) {
$curlResult = Probe::uri($url);
if ($curlResult["network"] == Protocol::OSTATUS) {
$result = Contact::createFromProbe($uid, $url, true, Protocol::OSTATUS);
if ($result["success"]) {
$o .= " - ".L10n::t("success");

View file

@ -60,12 +60,12 @@ function parse_url_content(App $a)
// the URL with the corresponding BBCode media tag
$redirects = 0;
// Fetch the header of the URL
$result = Network::curl($url, false, $redirects, ['novalidate' => true, 'nobody' => true]);
$curlResponse = Network::curl($url, false, $redirects, ['novalidate' => true, 'nobody' => true]);
if ($result['success']) {
if ($curlResponse->isSuccess()) {
// Convert the header fields into an array
$hdrs = [];
$h = explode("\n", $result['header']);
$h = explode("\n", $curlResponse->getHeader());
foreach ($h as $l) {
$header = array_map('trim', explode(':', trim($l), 2));
if (count($header) == 2) {