X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FProxy.php;h=4d1e1c304b082e912ef54abe6d70756e5b96ceb6;hb=fd5914011cb5c67b827886a5db0e7760a307ad1d;hp=751b4a29846dbf3fe17348f9aedf305fd49f20ad;hpb=db60557a4f1066639e1af0650f1e5f13e576bcb1;p=friendica.git diff --git a/src/Module/Proxy.php b/src/Module/Proxy.php index 751b4a2984..4d1e1c304b 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']); } @@ -83,22 +83,27 @@ class Proxy extends BaseModule $request['url'] = str_replace(' ', '+', $request['url']); // Fetch the content with the local user - $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClient::ACCEPT_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)]); + try { + $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::notice('Error fetching image', ['image' => $request['url'], 'return' => $fetchResult->getReturnCode(), 'empty' => empty($img_str)]); + self::responseError(); + // stop. + } + } catch (\Exception $exception) { + Logger::notice('Error fetching image', ['image' => $request['url'], 'exception' => $exception]); self::responseError(); - // stop. } - Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => local_user(), 'image' => $request['url']]); + 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. } @@ -123,7 +128,7 @@ class Proxy extends BaseModule * ] * @throws \Exception */ - private function getRequestInfo() + private function getRequestInfo(): array { $size = ProxyUtils::PIXEL_LARGE; $sizetype = ''; @@ -187,12 +192,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. } @@ -202,6 +208,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(); } }