]> git.mxchange.org Git - friendica.git/commitdiff
Revert "HTTPRequest: Replace getInfo() with new parameter 'content_length'"
authorPhilipp <admin@philipp.info>
Sun, 11 Oct 2020 21:25:47 +0000 (23:25 +0200)
committerPhilipp <admin@philipp.info>
Sun, 11 Oct 2020 21:25:47 +0000 (23:25 +0200)
This reverts commit f3cd973c

src/Network/CurlResult.php
src/Network/GuzzleResponse.php
src/Network/HTTPRequest.php
src/Network/IHTTPRequest.php
src/Network/IHTTPResult.php
src/Network/Probe.php
src/Util/ParseUrl.php

index b2eefcbaa92bcb04fbd9c753e590e8ec9ef9e736..b0e801010d4ea0615f749feb3f50f355cee5d653 100644 (file)
@@ -319,6 +319,12 @@ class CurlResult implements IHTTPResult
                return $this->body;
        }
 
+       /** {@inheritDoc} */
+       public function getInfo()
+       {
+               return $this->info;
+       }
+
        /** {@inheritDoc} */
        public function isRedirectUrl()
        {
index 69e88b40250c3568cb3c4023e42c700cb00f9500..c6cab7c9e8742fc5394112599fea69ae6e5fe978 100644 (file)
@@ -121,6 +121,11 @@ class GuzzleResponse extends Response implements IHTTPResult, ResponseInterface
                return $this->url;
        }
 
+       public function getInfo()
+       {
+               // TODO: Implement getInfo() method.
+       }
+
        /** {@inheritDoc} */
        public function isRedirectUrl()
        {
index 1f6b262921ba37c337a1c8d190b8788294c472a1..ffc095b66aca1f1e6ffea01ee5ef34066c7ff19b 100644 (file)
@@ -30,7 +30,6 @@ use Friendica\Util\Network;
 use Friendica\Util\Profiler;
 use GuzzleHttp\Client;
 use GuzzleHttp\Exception\RequestException;
-use GuzzleHttp\Exception\TransferException;
 use Psr\Http\Message\RequestInterface;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\UriInterface;
@@ -187,13 +186,6 @@ class HTTPRequest implements IHTTPRequest
                        $this->logger->notice('Curl redirect.', ['url' => $request->getUri(), 'to' => $uri]);
                };
 
-               $onHeaders = function (ResponseInterface $response) use ($opts) {
-                       if (!empty($opts['content_length']) &&
-                               $response->getHeaderLine('Content-Length') > $opts['content_length']) {
-                               throw new TransferException('The file is too big!');
-                       }
-               };
-
                $client = new Client([
                        'allow_redirect' => [
                                'max' => 8,
@@ -210,9 +202,8 @@ class HTTPRequest implements IHTTPRequest
                try {
                        $response = $client->get($url);
                        return new GuzzleResponse($response, $url);
-               } catch (TransferException $exception) {
-                       if ($exception instanceof RequestException &&
-                               $exception->hasResponse()) {
+               } catch (RequestException $exception) {
+                       if ($exception->hasResponse()) {
                                return new GuzzleResponse($exception->getResponse(), $url, $exception->getCode(), $exception->getMessage());
                        } else {
                                return new CurlResult($url, '', ['http_code' => $exception->getCode()], $exception->getCode(), $exception->getMessage());
index 49993085e63c938597415e509edce2784abb5056..3f9b7f27a132700d6dddadac5e0c3d2492a53c23 100644 (file)
@@ -75,7 +75,6 @@ interface IHTTPRequest
         *                           'nobody' => only return the header
         *                           'cookiejar' => path to cookie jar file
         *                           'header' => header array
-        *                           'content_length' => int maximum File content length
         *
         * @return IHTTPResult
         */
index 77ee86976bd044bc672fca9be1bdd5f78db511cb..5904bcfa386c8df8ab221645d07a46967c210a81 100644 (file)
@@ -82,6 +82,11 @@ interface IHTTPResult
         */
        public function getBody();
 
+       /**
+        * @return array
+        */
+       public function getInfo();
+
        /**
         * @return boolean
         */
index cfd03684397c9afb023dfdd55c139696c65310a9..3fe035286f3bed729a11b947d06ac3eb551d063b 100644 (file)
@@ -423,11 +423,16 @@ class Probe
         */
        private static function getHideStatus($url)
        {
-               $curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]);
+               $curlResult = DI::httpRequest()->get($url);
                if (!$curlResult->isSuccess()) {
                        return false;
                }
 
+               // If the file is too large then exit
+               if (($curlResult->getInfo()['download_content_length'] ?? 0) > 1000000) {
+                       return false;
+               }
+
                // If it isn't a HTML file then exit
                if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
                        return false;
index 1a81a256ca36ae5a82a92c5b72f5ce334a25c28f..c3cbda70e3f2f483522ba43fd11de251f8f10648 100644 (file)
@@ -160,11 +160,16 @@ class ParseUrl
                        return $siteinfo;
                }
 
-               $curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]);
+               $curlResult = DI::httpRequest()->get($url);
                if (!$curlResult->isSuccess()) {
                        return $siteinfo;
                }
 
+               // If the file is too large then exit
+               if (($curlResult->getInfo()['download_content_length'] ?? 0) > 1000000) {
+                       return $siteinfo;
+               }
+
                // If it isn't a HTML file then exit
                if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
                        return $siteinfo;