Framework Update
This commit is contained in:
+22
-16
@@ -14,8 +14,10 @@
|
||||
|
||||
namespace Webman\Http;
|
||||
|
||||
use Webman\App;
|
||||
use Throwable;
|
||||
use Webman\App;
|
||||
use function filemtime;
|
||||
use function gmdate;
|
||||
|
||||
/**
|
||||
* Class Response
|
||||
@@ -26,13 +28,14 @@ class Response extends \Workerman\Protocols\Http\Response
|
||||
/**
|
||||
* @var Throwable
|
||||
*/
|
||||
protected $_exception = null;
|
||||
protected $exception = null;
|
||||
|
||||
/**
|
||||
* File
|
||||
* @param string $file
|
||||
* @return $this
|
||||
*/
|
||||
public function file(string $file)
|
||||
public function file(string $file): Response
|
||||
{
|
||||
if ($this->notModifiedSince($file)) {
|
||||
return $this->withStatus(304);
|
||||
@@ -41,41 +44,44 @@ class Response extends \Workerman\Protocols\Http\Response
|
||||
}
|
||||
|
||||
/**
|
||||
* Download
|
||||
* @param string $file
|
||||
* @param string $download_name
|
||||
* @param string $downloadName
|
||||
* @return $this
|
||||
*/
|
||||
public function download(string $file, string $download_name = '')
|
||||
public function download(string $file, string $downloadName = ''): Response
|
||||
{
|
||||
$this->withFile($file);
|
||||
if ($download_name) {
|
||||
$this->header('Content-Disposition', "attachment; filename=\"$download_name\"");
|
||||
if ($downloadName) {
|
||||
$this->header('Content-Disposition', "attachment; filename=\"$downloadName\"");
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* NotModifiedSince
|
||||
* @param string $file
|
||||
* @return bool
|
||||
*/
|
||||
protected function notModifiedSince(string $file)
|
||||
protected function notModifiedSince(string $file): bool
|
||||
{
|
||||
$if_modified_since = App::request()->header('if-modified-since');
|
||||
if ($if_modified_since === null || !($mtime = \filemtime($file))) {
|
||||
$ifModifiedSince = App::request()->header('if-modified-since');
|
||||
if ($ifModifiedSince === null || !is_file($file) || !($mtime = filemtime($file))) {
|
||||
return false;
|
||||
}
|
||||
return $if_modified_since === \gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
|
||||
return $ifModifiedSince === gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Throwable $exception
|
||||
* @return Throwable
|
||||
* Exception
|
||||
* @param Throwable|null $exception
|
||||
* @return Throwable|null
|
||||
*/
|
||||
public function exception($exception = null)
|
||||
public function exception(Throwable $exception = null): ?Throwable
|
||||
{
|
||||
if ($exception) {
|
||||
$this->_exception = $exception;
|
||||
$this->exception = $exception;
|
||||
}
|
||||
return $this->_exception;
|
||||
return $this->exception;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user