Skip to content

Commit

Permalink
Resolve #887
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Jan 31, 2023
1 parent 71eaaf0 commit 76ae57b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,25 @@ public function ServiceProxyExternal() : string
$HTTP->max_redirects = 2;
$HTTP->streamBodyTo($tmp);
$oResponse = $HTTP->doRequest('GET', $sUrl);
if ($oResponse && 200 === $oResponse->status
&& \str_starts_with($oResponse->getHeader('content-type'), 'image/')
) try {
$this->oActions->cacheByKey($sData);
\header('Content-Type: ' . $oResponse->getHeader('content-type'));
\header('Cache-Control: public');
\header('Expires: '.\gmdate('D, j M Y H:i:s', 2592000 + \time()).' UTC');
\header('X-Content-Redirect-Location: '.$oResponse->final_uri);
\rewind($tmp);
\fpassthru($tmp);
exit;
} catch (\Throwable $e) {
$msg = \get_class($HTTP) . ': ' . $e->getMessage();
\SnappyMail\Log::error('Proxy', $msg);
// \error_log(\get_class($HTTP) . ': ' . $e->getMessage());
if ($oResponse) {
$sContentType = \SnappyMail\File\MimeType::fromStream($tmp) ?: $oResponse->getHeader('content-type');
if (200 === $oResponse->status && \str_starts_with($sContentType, 'image/')) {
try {
$this->oActions->cacheByKey($sData);
\header('Content-Type: ' . $sContentType);
\header('Cache-Control: public');
\header('Expires: '.\gmdate('D, j M Y H:i:s', 2592000 + \time()).' UTC');
\header('X-Content-Redirect-Location: '.$oResponse->final_uri);
\rewind($tmp);
\fpassthru($tmp);
exit;
} catch (\Throwable $e) {
\header("X-Content-Error: {$e->getMessage()}");
\SnappyMail\Log::error('Proxy', \get_class($HTTP) . ': ' . $e->getMessage());
}
} else {
\header("X-Content-Error: {$oResponse->status} {$sContentType}");
}
}
}
}
Expand Down

0 comments on commit 76ae57b

Please sign in to comment.