X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FProxy.php;h=ab129a82c9243934d1a9b10222ab524d8bdc6a0f;hb=24c32cff0dcd38d5aa509208f5f17abb05a8b140;hp=c84564e0f85213d6318f3b747c1f470c1762cf8a;hpb=5aad46c7fb2b66d63ad93d92ee355fc522b57be1;p=friendica.git diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index c84564e0f8..ab129a82c9 100644 --- a/src/Module/Proxy.php +++ b/src/Module/Proxy.php @@ -1,6 +1,6 @@ $request['url']]); + if (!DI::userSession()->getLocalUserId()) { + Logger::debug('Redirecting not logged in user to original address', ['url' => $request['url']]); System::externalRedirect($request['url']); } @@ -81,20 +83,22 @@ 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'], DI::userSession()->getLocalUserId(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::IMAGE], 'timeout' => 10]); $img_str = $fetchResult->getBody(); if (!$fetchResult->isSuccess() || empty($img_str)) { - Logger::info('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]); + Logger::notice('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]); self::responseError(); // stop. } + Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => DI::userSession()->getLocalUserId(), 'image' => $request['url']]); + $mime = Images::getMimeTypeByData($img_str); $image = new Image($img_str, $mime); if (!$image->isValid()) { - Logger::info('The image is invalid', ['image' => $request['url'], 'mime' => $mime]); + Logger::notice('The image is invalid', ['image' => $request['url'], 'mime' => $mime]); self::responseError(); // stop. } @@ -119,7 +123,7 @@ class Proxy extends BaseModule * ] * @throws \Exception */ - private function getRequestInfo() + private function getRequestInfo(): array { $size = ProxyUtils::PIXEL_LARGE; $sizetype = ''; @@ -183,12 +187,13 @@ class Proxy extends BaseModule * Output the image with cache headers * * @param Image $img + * @return void * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ private static function responseImageHttpCache(Image $img) { if (is_null($img) || !$img->isValid()) { - Logger::info('The cached image is invalid'); + Logger::notice('The cached image is invalid'); self::responseError(); // stop. } @@ -198,6 +203,6 @@ class Proxy extends BaseModule header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT'); header('Cache-Control: max-age=31536000'); echo $img->asString(); - exit(); + System::exit(); } }