diff --git a/src/Vinelab/Cdn/Providers/AwsS3Provider.php b/src/Vinelab/Cdn/Providers/AwsS3Provider.php index 80b0107..5ca4552 100755 --- a/src/Vinelab/Cdn/Providers/AwsS3Provider.php +++ b/src/Vinelab/Cdn/Providers/AwsS3Provider.php @@ -217,6 +217,10 @@ public function upload($assets) 'ACL' => $this->acl, // the permission of the file + 'CacheControl' => $this->default['providers']['aws']['s3']['cache-control'], + 'MetaData' => $this->default['providers']['aws']['s3']['metadata'], + "Expires" => $this->default['providers']['aws']['s3']['expires'] + ])); } catch(S3Exception $e) { $this->console->writeln("Error while uploading: ($file->getRealpath())"); diff --git a/src/config/cdn.php b/src/config/cdn.php index 0d35028..97cbbe8 100755 --- a/src/config/cdn.php +++ b/src/config/cdn.php @@ -125,6 +125,30 @@ 'version' => '', ], + /* + |-------------------------------------------------------------------------- + | Add metadata to each s3 file + |-------------------------------------------------------------------------- + | Add metadata to each s3 file + */ + 'metadata' => [], + + /* + |-------------------------------------------------------------------------- + | Add expiry data to file + |-------------------------------------------------------------------------- + | Add expiry data to file + */ + 'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), + + /* + |-------------------------------------------------------------------------- + | Add browser level cache + |-------------------------------------------------------------------------- + | Add browser level cache + */ + 'cache-control' => 'max-age=2628000', + ], ], diff --git a/tests/Vinelab/Cdn/CdnTest.php b/tests/Vinelab/Cdn/CdnTest.php index 30665e6..a868836 100755 --- a/tests/Vinelab/Cdn/CdnTest.php +++ b/tests/Vinelab/Cdn/CdnTest.php @@ -97,7 +97,12 @@ public function testPushCommand() 'use' => false, 'cdn_url' => '', 'version' => '', - ] + ], + 'metadata' => [], + + 'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), + + 'cache-control' => 'max-age=2628000', ], ], ], diff --git a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php index 5ff4b93..c3573ac 100755 --- a/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php +++ b/tests/Vinelab/Cdn/Providers/AwsS3ProviderTest.php @@ -87,6 +87,11 @@ public function testInitializingObject() 'cdn_url' => null, 'version' => null, ], + 'metadata' => [], + + 'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), + + 'cache-control' => 'max-age=2628000', ], ], ], @@ -119,6 +124,11 @@ public function testUploadingAssets() 'cdn_url' => null, 'version' => null, ], + 'metadata' => [], + + 'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), + + 'cache-control' => 'max-age=2628000', ], ], ], @@ -153,6 +163,11 @@ public function testUrlGenerator() 'cdn_url' => null, 'version' => null, ], + 'metadata' => [], + + 'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), + + 'cache-control' => 'max-age=2628000', ], ], ], @@ -187,6 +202,11 @@ public function testEmptyUrlGenerator() 'cdn_url' => null, 'version' => null, ], + 'metadata' => [], + + 'expires' => gmdate("D, d M Y H:i:s T", strtotime("+5 years")), + + 'cache-control' => 'max-age=2628000', ], ], ],