Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the max-age key of the header cache-control configurable #181

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Aws/AwsStorageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laravel\VaporCli\ConsoleVaporClient;
use Laravel\VaporCli\Exceptions\CopyRequestFailedException;
use Laravel\VaporCli\Helpers;
use Laravel\VaporCli\Manifest;
use Symfony\Component\Console\Helper\ProgressBar;

class AwsStorageProvider
Expand Down Expand Up @@ -92,14 +93,15 @@ public function request($method, $url, array $headers = [])
*/
public function executeCopyRequests($requests)
{
$requests = function () use ($requests) {
$assetsMaxAge = Manifest::assetsMaxAge();
$requests = function () use ($requests, $assetsMaxAge) {
foreach ($requests as $request) {
yield new Request(
'PUT',
$request['url'],
array_merge(
$request['headers'],
['Cache-Control' => 'public, max-age=2628000']
['Cache-Control' => "public, max-age={$assetsMaxAge}"]
)
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ public static function dotFilesAsAssets()
return static::current()['dot-files-as-assets'] ?? false;
}

/**
* Let the possibility set the max-age for assets. 30 days by default.
*
* @return int
*/
public static function assetsMaxAge()
{
return static::current()['assets-max-age'] ?? 2628000;
}

/**
* Write a fresh manifest file for the given project.
*
Expand Down
3 changes: 2 additions & 1 deletion src/ServeAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public function __invoke(ConsoleVaporClient $vapor, array $artifact, $fresh)
protected function executeStoreAssetRequests($requests, $assetPath)
{
$storage = Helpers::app(AwsStorageProvider::class);
$assetsMaxAge = Manifest::assetsMaxAge();

foreach ($requests as $request) {
Helpers::step('<comment>Uploading Asset:</comment> '.$request['path'].' ('.Helpers::kilobytes($assetPath.'/'.$request['path']).')');

$storage->store(
$request['url'],
array_merge($request['headers'], ['Cache-Control' => 'public, max-age=2628000']),
array_merge($request['headers'], ['Cache-Control' => "public, max-age={$assetsMaxAge}"]),
$assetPath.'/'.$request['path']
);
}
Expand Down