]> git.mxchange.org Git - friendica.git/commitdiff
Curl Response Refactoring
authorPhilipp Holzer <admin@philipp.info>
Wed, 10 Oct 2018 19:15:26 +0000 (21:15 +0200)
committerPhilipp Holzer <admin@philipp.info>
Wed, 10 Oct 2018 19:15:26 +0000 (21:15 +0200)
- refactored Network::post()
- replaced every Network::post() execution with the new Curl container

include/items.php
mod/dfrn_confirm.php
mod/dfrn_poll.php
mod/match.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/Salmon.php
src/Util/HTTPSignature.php
src/Worker/OnePoll.php
src/Worker/PubSubPublish.php

index 236e63dd25e88e48783e7b3da76fa7b679cb6106..27a7db767b4d16c6ee8a8a8a57abc02507524a27 100644 (file)
@@ -316,9 +316,9 @@ function subscribe_to_hub($url, array $importer, array $contact, $hubmode = 'sub
                DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
        }
 
-       Network::post($url, $params);
+       $postResult = Network::post($url, $params);
 
-       logger('subscribe_to_hub: returns: ' . Network::getCurl()->getCode(), LOGGER_DEBUG);
+       logger('subscribe_to_hub: returns: ' . $postResult->getReturnCode(), LOGGER_DEBUG);
 
        return;
 
index d3fa45d361219a1ce9632e209ca18cd8ca06ec2b..969e2286c864076a8b5770300612c6f7f3dd6857 100644 (file)
@@ -221,7 +221,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                         *
                         */
 
-                       $res = Network::post($dfrn_confirm, $params, null, $redirects, 120);
+                       $res = Network::post($dfrn_confirm, $params, null, $redirects, 120)->getBody();
 
                        logger(' Confirm: received data: ' . $res, LOGGER_DATA);
 
index 54539ee03d7bd4cc580bb7845b9fa34b59734488..af597d76ff7a6c55d3be3b29a5fc77c5f9ee62fb 100644 (file)
@@ -502,7 +502,7 @@ function dfrn_poll_content(App $a)
                                        'dfrn_version' => DFRN_PROTOCOL_VERSION,
                                        'challenge' => $challenge,
                                        'sec' => $sec
-                               ]);
+                               ])->getBody();
                        }
 
                        $profile = ((DBA::isResult($r) && $r[0]['nickname']) ? $r[0]['nickname'] : $nickname);
index bb1e4542aed0004eab693cdba92b3c10e4475291..7e805d5baf4c4d9272e462f5c62a7a365bfd8549 100644 (file)
@@ -59,9 +59,9 @@ function match_content(App $a)
                }
 
                if (strlen(Config::get('system', 'directory'))) {
-                       $x = Network::post(get_server().'/msearch', $params);
+                       $x = Network::post(get_server().'/msearch', $params)->getBody();
                } else {
-                       $x = Network::post(System::baseUrl() . '/msearch', $params);
+                       $x = Network::post(System::baseUrl() . '/msearch', $params)->getBody();
                }
 
                $j = json_decode($x);
index 3a001de0491ca80d06c4c4b087d31c804fca7420..f92d1401dfe49f7c5365217f35a1fa1cabfd507d 100644 (file)
@@ -1469,16 +1469,17 @@ class DFRN
 
                $content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json");
 
-               $xml = Network::post($dest_url, $envelope, ["Content-Type: ".$content_type]);
+               $postResult = Network::post($dest_url, $envelope, ["Content-Type: ".$content_type]);
+               $xml = $postResult->getBody();
 
-               $curl_stat = Network::getCurl()->getCode();
+               $curl_stat = $postResult->getReturnCode();
                if (empty($curl_stat) || empty($xml)) {
                        logger('Empty answer from ' . $contact['id'] . ' - ' . $dest_url);
                        Contact::markForArchival($contact);
                        return -9; // timed out
                }
 
-               if (($curl_stat == 503) && (stristr(Network::getCurl()->getHeaders(), 'retry-after'))) {
+               if (($curl_stat == 503) && (stristr($postResult->getHeader(), 'retry-after'))) {
                        Contact::markForArchival($contact);
                        return -10;
                }
index ebdc84ce7fdd049278d5b2b082ed33ad2442f931..d3cda6c2da4c5333e5b08458d1916db6bf599751 100644 (file)
@@ -3079,8 +3079,8 @@ class Diaspora
                        if (!intval(Config::get("system", "diaspora_test"))) {
                                $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
 
-                               Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
-                               $return_code = Network::getCurl()->getCode();
+                               $postResult = Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]);
+                               $return_code = $postResult->getReturnCode();
                        } else {
                                logger("test_mode");
                                return 200;
@@ -3089,7 +3089,7 @@ class Diaspora
 
                logger("transmit: ".$logid."-".$guid." to ".$dest_url." returns: ".$return_code);
 
-               if (!$return_code || (($return_code == 503) && (stristr(Network::getCurl()->getHeaders(), "retry-after")))) {
+               if (!$return_code || (($return_code == 503) && (stristr($postResult->getHeaders(), "retry-after")))) {
                        if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::ACCOUNT_TYPE_RELAY)) {
                                logger("queue message");
                                // queue message for redelivery
index b71be6e2fa55b590fa936e0ac782cb1aae6495a5..02d08c3d4e99722c0208f32a8ed0cd54c7468a58 100644 (file)
@@ -133,13 +133,12 @@ class Salmon
                $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
 
                // slap them
-               Network::post($url, $salmon, [
+               $postResult = Network::post($url, $salmon, [
                        'Content-type: application/magic-envelope+xml',
                        'Content-length: ' . strlen($salmon)
                ]);
 
-               $a = get_app();
-               $return_code = Network::getCurl()->getCode();
+               $return_code = $postResult->getReturnCode();
 
                // check for success, e.g. 2xx
 
@@ -159,11 +158,11 @@ class Salmon
                        $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
 
                        // slap them
-                       Network::post($url, $salmon, [
+                       $postResult = Network::post($url, $salmon, [
                                'Content-type: application/magic-envelope+xml',
                                'Content-length: ' . strlen($salmon)
                        ]);
-                       $return_code = Network::getCurl()->getCode();
+                       $return_code = $postResult->getReturnCode();
                }
 
                if ($return_code > 299) {
@@ -182,10 +181,10 @@ class Salmon
                        $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
 
                        // slap them
-                       Network::post($url, $salmon, [
+                       $postResult = Network::post($url, $salmon, [
                                'Content-type: application/magic-envelope+xml',
                                'Content-length: ' . strlen($salmon)]);
-                       $return_code = Network::getCurl()->getCode();
+                       $return_code = $postResult->getReturnCode();
                }
 
                logger('slapper for '.$url.' returned ' . $return_code);
index 247e554f00d83868b712d09dae4f7c40c1497d8a..503cbff0ade45b0af04c35d039380f28ff267cbc 100644 (file)
@@ -302,10 +302,9 @@ class HTTPSignature
 
                $headers[] = 'Content-Type: application/activity+json';
 
-               Network::post($target, $content, $headers);
-               $return_code = Network::getCurl()->getCode();
+               $postResult = Network::post($target, $content, $headers);
 
-               logger('Transmit to ' . $target . ' returned ' . $return_code);
+               logger('Transmit to ' . $target . ' returned ' . $postResult->getReturnCode());
        }
 
        /**
index ab8a305494337c679c1fdbbb2539d668ed1ab5ce..a68ad1336d3aca7bdc5463b5c45d77a7bdc7a25e 100644 (file)
@@ -287,7 +287,7 @@ class OnePoll
                        $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
                        $postvars['perm'] = 'rw';
 
-                       $xml = Network::post($contact['poll'], $postvars);
+                       $xml = Network::post($contact['poll'], $postvars)->getBody();
 
                } elseif (($contact['network'] === Protocol::OSTATUS)
                        || ($contact['network'] === Protocol::DIASPORA)
index 07023e824793a1c8332d35fb4cd3ff3b4db855d0..38d9c07868a56b75edc592d22f3f55a3d55255ae 100644 (file)
@@ -56,8 +56,8 @@ class PubSubPublish
 
                logger('POST ' . print_r($headers, true) . "\n" . $params, LOGGER_DATA);
 
-               Network::post($subscriber['callback_url'], $params, $headers);
-               $ret = Network::getCurl()->getCode();
+               $postResult = Network::post($subscriber['callback_url'], $params, $headers);
+               $ret = $postResult->getReturnCode();
 
                $condition = ['id' => $subscriber['id']];