Skip to content

Commit 90fde4a

Browse files
author
FreedomKnight
committed
新增 response header 的可選參數
1 parent 30eb4c3 commit 90fde4a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ You can write a routing rules to get it. it will response file content and use h
6565
return $entry->response($filename);
6666
});
6767

68+
and it can add headers array by optional
69+
70+
return $entry->response($filename, ['Content-Disposition', 'attachement']);
71+
6872
### Work with Laravel Storage
6973

7074
* Get file content

src/FileEntry.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function fullpath($filename)
5353
return $this->basepath . $filename;
5454
}
5555

56-
public function response($filename)
56+
public function response($filename, $headers = [])
5757
{
5858
try {
5959
$path = $this->basepath . $filename;
@@ -65,14 +65,14 @@ public function response($filename)
6565
if (trim(\Request::header('If-None-Match'), '\'\"') != $etag ||
6666
new \DateTime(\Request::header('If-Modified-Since')) != new \DateTime($time)
6767
) {
68-
return response($file, 200)->header('Content-Type', \Storage::mimeType($path))
68+
return response($file, 200, $headers)->header('Content-Type', \Storage::mimeType($path))
6969
->setEtag($etag)
7070
->setLastModified(new \DateTime($time))
7171
->setExpires(new \DateTime($expires))
7272
->setPublic();
7373
}
7474

75-
return response(null, 304)
75+
return response(null, 304, $headers)
7676
->setEtag($etag)
7777
->setLastModified(new \DateTime($time))
7878
->setExpires(new \DateTime($expires))

0 commit comments

Comments
 (0)