File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ protected function getEnableAmp()
7171 \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
7272 }
7373
74+ /**
75+ * Get the Access-Control-Max-Age
76+ * @return string
77+ */
78+ protected function getMaxAge ()
79+ {
80+ return (int ) $ this ->scopeConfig ->getValue ('web/corsRequests/max_age ' ,
81+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
82+ }
83+
7484 /**
7585 * Triggers before original dispatch
7686 * This method triggers before original \Magento\Webapi\Controller\Rest::dispatch and set version
@@ -92,6 +102,9 @@ public function beforeDispatch(
92102 if ($ this ->getEnableAmp ()) {
93103 $ this ->response ->setHeader ('AMP-Access-Control-Allow-Source-Origin ' , rtrim ($ originUrl ,"/ " ), true );
94104 }
105+ if ((int )$ this ->getMaxAge () > 0 ) {
106+ $ this ->response ->setHeader ('Access-Control-Max-Age ' , $ this ->getMaxAge (), true );
107+ }
95108 }
96109 }
97110
Original file line number Diff line number Diff line change 2525 <source_model >Magento\Config\Model\Config\Source\Yesno</source_model >
2626 <comment >Enables AMP-Access-Control-Allow-Source-Origin response header for AMP CORS requests</comment >
2727 </field >
28+ <field id =" max_age" translate =" label" type =" text" sortOrder =" 40" showInDefault =" 1" showInWebsite =" 1"
29+ showInStore =" 1" >
30+ <label >CORS Control Max age</label >
31+ <comment >Enables Access-Control-Max-Age response header for AMP CORS requests (max age in seconds)</comment >
32+ </field >
2833 </group >
2934 </section >
3035 </system >
You can’t perform that action at this time.
0 commit comments