]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Proxy.php
Some more API functions moved
[friendica.git] / src / Module / Proxy.php
index 04fe00db1248a8ed07e726c525b256f9b75986a7..86b8a95cbb607a03183856a378bacbeebeaef2c3 100644 (file)
@@ -24,6 +24,8 @@ namespace Friendica\Module;
 use Friendica\BaseModule;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
+use Friendica\DI;
+use Friendica\Network\HTTPException\NotModifiedException;
 use Friendica\Object\Image;
 use Friendica\Util\HTTPSignature;
 use Friendica\Util\Images;
@@ -44,8 +46,14 @@ class Proxy extends BaseModule
         */
        public static function rawContent(array $parameters = [])
        {
+               $request = self::getRequestInfo($parameters);
+
+               if (!DI::config()->get('system', 'proxify_content')) {
+                       Logger::notice('Proxy access is forbidden', ['request' => $request, 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', 'accept' => $_SERVER['HTTP_ACCEPT'] ?? '']);
+                       throw new \Friendica\Network\HTTPException\NotFoundException();
+               }
+
                if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
-                       header("HTTP/1.1 304 Not Modified");
                        header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
                        if (!empty($_SERVER["HTTP_IF_NONE_MATCH"])) {
                                header("Etag: " . $_SERVER["HTTP_IF_NONE_MATCH"]);
@@ -57,11 +65,9 @@ class Proxy extends BaseModule
                                header_remove("Expires");
                                header_remove("Cache-Control");
                        }
-                       exit;
+                       throw new NotModifiedException();
                }
 
-               $request = self::getRequestInfo($parameters);
-
                if (empty($request['url'])) {
                        throw new \Friendica\Network\HTTPException\BadRequestException();
                }
@@ -75,7 +81,7 @@ class Proxy extends BaseModule
                $request['url'] = str_replace(' ', '+', $request['url']);
 
                // Fetch the content with the local user
-               $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['accept_content' => '', 'timeout' => 10]);
+               $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['accept_content' => [], 'timeout' => 10]);
                $img_str = $fetchResult->getBody();
 
                if (!$fetchResult->isSuccess() || empty($img_str)) {