-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #607 from getformwork/feature/improved-cache-control
Improved cache control
- Loading branch information
Showing
28 changed files
with
312 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Formwork\Controllers; | ||
|
||
use Formwork\Http\FileResponse; | ||
use Formwork\Router\RouteParams; | ||
use Formwork\Utils\Exceptions\FileNotFoundException; | ||
use Formwork\Utils\FileSystem; | ||
|
||
class AssetsController extends AbstractController | ||
{ | ||
public function asset(RouteParams $routeParams): FileResponse | ||
{ | ||
$path = FileSystem::joinPaths($this->config->get('system.images.processPath'), $routeParams->get('id'), $routeParams->get('name')); | ||
|
||
if (FileSystem::isFile($path)) { | ||
return new FileResponse($path, headers: ['Cache-Control' => 'private, max-age=31536000, immutable'], autoEtag: true, autoLastModified: true); | ||
} | ||
|
||
throw new FileNotFoundException('Cannot find asset'); | ||
} | ||
|
||
public function template(RouteParams $routeParams): FileResponse | ||
{ | ||
$path = FileSystem::joinPaths($this->config->get('system.templates.path'), 'assets', $routeParams->get('file')); | ||
|
||
if (FileSystem::isFile($path)) { | ||
$headers = $this->request->query()->has('v') | ||
? ['Cache-Control' => 'private, max-age=31536000, immutable'] | ||
: []; | ||
return new FileResponse($path, headers: $headers, autoEtag: true, autoLastModified: true); | ||
} | ||
|
||
throw new FileNotFoundException('Cannot find asset'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.