]> git.mxchange.org Git - friendica.git/commitdiff
Make "HTTPRequest::post" dynamic
authornupplaPhil <admin+github@philipp.info>
Wed, 4 Mar 2020 21:18:28 +0000 (22:18 +0100)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 21 Jul 2020 07:02:51 +0000 (03:02 -0400)
mod/dfrn_confirm.php
mod/dfrn_poll.php
mod/match.php
src/Network/HTTPRequest.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 f78e8d55aa2c7e772a94312c72bbcb1fca14f86e..f7460b79f3403f3e8fd0efda8e1aa60c51469fce 100644 (file)
@@ -42,7 +42,6 @@ use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Notify\Type;
 use Friendica\Model\User;
-use Friendica\Network\HTTPRequest;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
@@ -224,7 +223,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                 *
                 */
 
-               $res = HTTPRequest::post($dfrn_confirm, $params, [], 120)->getBody();
+               $res = DI::httpRequest()->post($dfrn_confirm, $params, [], 120)->getBody();
 
                Logger::log(' Confirm: received data: ' . $res, Logger::DATA);
 
index faa55a10824805925ba5418f5e8206734f9010da..00732982ed8b77a07192cff2f212a5384bc42034 100644 (file)
@@ -507,7 +507,7 @@ function dfrn_poll_content(App $a)
                                                           . '&sec=' . $sec
                                );
                        } else {
-                               $s = HTTPRequest::post($r[0]['poll'], [
+                               $s = DI::httpRequest()->post($r[0]['poll'], [
                                        'dfrn_id'      => $encrypted_id,
                                        'type'         => 'profile-check',
                                        'dfrn_version' => DFRN_PROTOCOL_VERSION,
index 4ec47c4cc6f1ed4dd55cef82840f7437d918b641..064107764ac99bbf0266363301a656802cb66fcc 100644 (file)
@@ -27,7 +27,6 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
-use Friendica\Network\HTTPRequest;
 use Friendica\Util\Proxy as ProxyUtils;
 
 /**
@@ -76,7 +75,7 @@ function match_content(App $a)
                $host = DI::baseUrl();
        }
 
-       $msearch_json = HTTPRequest::post($host . '/msearch', $params)->getBody();
+       $msearch_json = DI::httpRequest()->post($host . '/msearch', $params)->getBody();
 
        $msearch = json_decode($msearch_json);
 
index 73e5cd8e0b3939207cf3a51adef80176d78066b7..131fac8a78f896e2baf82ca24d5abf896884045e 100644 (file)
@@ -25,7 +25,6 @@ use Friendica\App;
 use Friendica\Core\Config\IConfig;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
-use Friendica\DI;
 use Friendica\Util\Network;
 use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
@@ -228,23 +227,22 @@ class HTTPRequest
         * @return CurlResult The content
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function post(string $url, $params, array $headers = [], int $timeout = 0, int &$redirects = 0)
+       public 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);
+                       $this->logger->info('Domain is blocked.'. ['url' => $url]);
                        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);
+               $this->logger->debug('Post_url: start.', ['url' => $url]);
 
                curl_setopt($ch, CURLOPT_HEADER, true);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -252,14 +250,14 @@ class HTTPRequest
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
                curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
 
-               if (DI::config()->get('system', 'ipv4_resolve', false)) {
+               if ($this->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_time = $this->config->get('system', 'curl_timeout', 60);
                        curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
                }
 
@@ -267,20 +265,20 @@ class HTTPRequest
                        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                }
 
-               $check_cert = DI::config()->get('system', 'verifyssl');
+               $check_cert = $this->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');
+               $proxy = $this->config->get('system', 'proxy');
 
-               if (strlen($proxy)) {
+               if (!empty($proxy)) {
                        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
                        curl_setopt($ch, CURLOPT_PROXY, $proxy);
-                       $proxyuser = DI::config()->get('system', 'proxyuser');
-                       if (strlen($proxyuser)) {
+                       $proxyuser = $this->config->get('system', 'proxyuser');
+                       if (!empty($proxyuser)) {
                                curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
                        }
                }
@@ -296,14 +294,14 @@ class HTTPRequest
 
                if ($curlResponse->isRedirectUrl()) {
                        $redirects++;
-                       Logger::log('post_url: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
+                       $this->logger->info('Post redirect.', ['url' => $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());
+               $this->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) {
index ef7eb0f481570816ffdda6819c7b72216d7d5955..7c87ee0b258e2422d878b031ad5331cbc4bbfc0a 100644 (file)
@@ -43,7 +43,6 @@ use Friendica\Model\Post\Category;
 use Friendica\Model\Profile;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
-use Friendica\Network\HTTPRequest;
 use Friendica\Network\Probe;
 use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
@@ -1344,7 +1343,7 @@ class DFRN
 
                Logger::debug('dfrn_deliver', ['post' => $postvars]);
 
-               $postResult = HTTPRequest::post($contact['notify'], $postvars);
+               $postResult = DI::httpRequest()->post($contact['notify'], $postvars);
 
                $xml = $postResult->getBody();
 
@@ -1441,7 +1440,7 @@ class DFRN
 
                $content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json");
 
-               $postResult = HTTPRequest::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();
index 46d2bc1d4ac9c7a0b75cdf9cbaa132b36dee7e72..ed369a3047336972bbe4ce8572fc5da9804350f4 100644 (file)
@@ -3261,7 +3261,7 @@ class Diaspora
                if (!intval(DI::config()->get("system", "diaspora_test"))) {
                        $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
 
-                       $postResult = HTTPRequest::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");
index d01ea2ce12b89eefbe3047c68ae7679335133bf9..35707b63567c5acaf048c9f0b437f38d8269cf71 100644 (file)
@@ -155,7 +155,7 @@ class Salmon
                $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
 
                // slap them
-               $postResult = HTTPRequest::post($url, $salmon, [
+               $postResult = DI::httpRequest()->post($url, $salmon, [
                        'Content-type: application/magic-envelope+xml',
                        'Content-length: ' . strlen($salmon)
                ]);
@@ -180,7 +180,7 @@ class Salmon
                        $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
 
                        // slap them
-                       $postResult = HTTPRequest::post($url, $salmon, [
+                       $postResult = DI::httpRequest()->post($url, $salmon, [
                                'Content-type: application/magic-envelope+xml',
                                'Content-length: ' . strlen($salmon)
                        ]);
@@ -203,7 +203,7 @@ class Salmon
                        $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
 
                        // slap them
-                       $postResult = HTTPRequest::post($url, $salmon, [
+                       $postResult = DI::httpRequest()->post($url, $salmon, [
                                'Content-type: application/magic-envelope+xml',
                                'Content-length: ' . strlen($salmon)]);
                        $return_code = $postResult->getReturnCode();
index 8c1d4f986ef33f15834553b7904ce1955a47dd54..84a11b8ec0c82069bf48561e1c855233b1f862b7 100644 (file)
@@ -26,7 +26,6 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\APContact;
 use Friendica\Model\User;
-use Friendica\Network\HTTPRequest;
 
 /**
  * Implements HTTP Signatures per draft-cavage-http-signatures-07.
@@ -298,7 +297,7 @@ class HTTPSignature
 
                $headers[] = 'Content-Type: application/activity+json';
 
-               $postResult = HTTPRequest::post($target, $content, $headers);
+               $postResult = DI::httpRequest()->post($target, $content, $headers);
                $return_code = $postResult->getReturnCode();
 
                Logger::log('Transmit to ' . $target . ' returned ' . $return_code, Logger::DEBUG);
index 0dc67d80f5e64c633d7d8713b96487d8cba5f36e..ed6bfacb35d7a0414d9129ea26c2198c69bce336 100644 (file)
@@ -28,7 +28,6 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\User;
-use Friendica\Network\HTTPRequest;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\Email;
@@ -405,7 +404,7 @@ class OnePoll
                $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
                $postvars['perm'] = 'rw';
 
-               return HTTPRequest::post($contact['poll'], $postvars)->getBody();
+               return DI::httpRequest()->post($contact['poll'], $postvars)->getBody();
        }
 
        /**
@@ -756,7 +755,7 @@ class OnePoll
                        DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
                }
 
-               $postResult = HTTPRequest::post($url, $params);
+               $postResult = DI::httpRequest()->post($url, $params);
 
                Logger::log('subscribe_to_hub: returns: ' . $postResult->getReturnCode(), Logger::DEBUG);
 
index 4fa3b3e8941d2478659feaa828cd14492b3c1cf5..eab68b43041e26d4d30eef6270b6d8d96d011ffe 100644 (file)
@@ -25,7 +25,6 @@ use Friendica\Core\Logger;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\PushSubscriber;
-use Friendica\Network\HTTPRequest;
 use Friendica\Protocol\OStatus;
 
 class PubSubPublish
@@ -68,7 +67,7 @@ class PubSubPublish
 
                Logger::log('POST ' . print_r($headers, true) . "\n" . $params, Logger::DATA);
 
-               $postResult = HTTPRequest::post($subscriber['callback_url'], $params, $headers);
+               $postResult = DI::httpRequest()->post($subscriber['callback_url'], $params, $headers);
                $ret = $postResult->getReturnCode();
 
                if ($ret >= 200 && $ret <= 299) {