Cloudflare.php
1 year ago
Fastly.php
1 year ago
LiteSpeed.php
1 year ago
NestifyCDN.php
1 year ago
NginxFastCgi.php
1 year ago
Sucuri.php
1 year ago
Fastly.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Server; |
| 4 | |
| 5 | class Fastly { |
| 6 | const STAGE = "very_early"; |
| 7 | |
| 8 | public static function detect() { |
| 9 | return !empty($_SERVER["HTTP_SURROGATE_CONTROL"]); |
| 10 | } |
| 11 | |
| 12 | public static function isCacheEnabled() { |
| 13 | return self::detect() && !empty($_SERVER["HTTP_SEC_CH_UA_MOBILE"]); |
| 14 | } |
| 15 | |
| 16 | public function init($stage) { |
| 17 | if (self::detect()) { |
| 18 | nitropack_header("Accept-CH: Sec-CH-UA-Mobile"); |
| 19 | |
| 20 | if (self::isCacheEnabled()) { |
| 21 | add_action('nitropack_early_cache_headers', [$this, 'allowProxyCache']); |
| 22 | } else { |
| 23 | add_action('nitropack_early_cache_headers', [$this, 'preventProxyCache']); |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | public function allowProxyCache() { |
| 29 | nitropack_header("Vary: sec-ch-ua-mobile"); |
| 30 | nitropack_header("Surrogate-Control: max-age=5, stale-while-revalidate=3600"); |
| 31 | } |
| 32 | |
| 33 | public function preventProxyCache() { |
| 34 | nitropack_header("Surrogate-Control: max-age=0, must-revalidate"); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 |