use Friendica\BaseModule;
use Friendica\Core\Logger;
use Friendica\Core\System;
+use Friendica\DI;
use Friendica\Object\Image;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Images;
{
/**
- * Initializer method for this class.
- *
- * Sets application instance and checks if /proxy/ path is writable.
- *
+ * Fetch remote image content
*/
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");
exit;
}
- $request = self::getRequestInfo($parameters);
-
if (empty($request['url'])) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
$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.