mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Resolve #887
This commit is contained in:
parent
71eaaf007e
commit
76ae57b481
1 changed files with 19 additions and 15 deletions
|
|
@ -320,21 +320,25 @@ class ServiceActions
|
||||||
$HTTP->max_redirects = 2;
|
$HTTP->max_redirects = 2;
|
||||||
$HTTP->streamBodyTo($tmp);
|
$HTTP->streamBodyTo($tmp);
|
||||||
$oResponse = $HTTP->doRequest('GET', $sUrl);
|
$oResponse = $HTTP->doRequest('GET', $sUrl);
|
||||||
if ($oResponse && 200 === $oResponse->status
|
if ($oResponse) {
|
||||||
&& \str_starts_with($oResponse->getHeader('content-type'), 'image/')
|
$sContentType = \SnappyMail\File\MimeType::fromStream($tmp) ?: $oResponse->getHeader('content-type');
|
||||||
) try {
|
if (200 === $oResponse->status && \str_starts_with($sContentType, 'image/')) {
|
||||||
$this->oActions->cacheByKey($sData);
|
try {
|
||||||
\header('Content-Type: ' . $oResponse->getHeader('content-type'));
|
$this->oActions->cacheByKey($sData);
|
||||||
\header('Cache-Control: public');
|
\header('Content-Type: ' . $sContentType);
|
||||||
\header('Expires: '.\gmdate('D, j M Y H:i:s', 2592000 + \time()).' UTC');
|
\header('Cache-Control: public');
|
||||||
\header('X-Content-Redirect-Location: '.$oResponse->final_uri);
|
\header('Expires: '.\gmdate('D, j M Y H:i:s', 2592000 + \time()).' UTC');
|
||||||
\rewind($tmp);
|
\header('X-Content-Redirect-Location: '.$oResponse->final_uri);
|
||||||
\fpassthru($tmp);
|
\rewind($tmp);
|
||||||
exit;
|
\fpassthru($tmp);
|
||||||
} catch (\Throwable $e) {
|
exit;
|
||||||
$msg = \get_class($HTTP) . ': ' . $e->getMessage();
|
} catch (\Throwable $e) {
|
||||||
\SnappyMail\Log::error('Proxy', $msg);
|
\header("X-Content-Error: {$e->getMessage()}");
|
||||||
// \error_log(\get_class($HTTP) . ': ' . $e->getMessage());
|
\SnappyMail\Log::error('Proxy', \get_class($HTTP) . ': ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
\header("X-Content-Error: {$oResponse->status} {$sContentType}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue