X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FProxy.php;h=419289c39f6e2927b57871c20abec77e89d39880;hb=38fbe281f9f774e8c0c9df1f5d36a8ecee08f34f;hp=6ccc38f60d7000829bafe7307378aeb72eb485f7;hpb=e519b782fd2180d326ffbd9fc8f1d6fca111ce98;p=friendica.git diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index 6ccc38f60d..419289c39f 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -1,6 +1,6 @@ getRequestInfo(); + + 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"]); @@ -60,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(); } @@ -78,11 +81,10 @@ class Proxy extends BaseModule $request['url'] = str_replace(' ', '+', $request['url']); // Fetch the content with the local user - $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['timeout' => 10]); + $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['accept_content' => [], 'timeout' => 10]); $img_str = $fetchResult->getBody(); - // If there is an error then return an error - if ((substr($fetchResult->getReturnCode(), 0, 1) == '4') || empty($img_str)) { + if (!$fetchResult->isSuccess() || empty($img_str)) { Logger::info('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]); self::responseError(); // stop. @@ -117,13 +119,13 @@ class Proxy extends BaseModule * ] * @throws \Exception */ - private static function getRequestInfo(array $parameters) + private function getRequestInfo() { $size = ProxyUtils::PIXEL_LARGE; $sizetype = ''; - if (!empty($parameters['url']) && empty($_REQUEST['url'])) { - $url = $parameters['url']; + if (!empty($this->parameters['url']) && empty($_REQUEST['url'])) { + $url = $this->parameters['url']; // thumb, small, medium and large. if (substr($url, -6) == ':micro') {