Cloudflare.php
2 years ago
Fastly.php
4 years ago
LiteSpeed.php
3 years ago
NginxFastCgi.php
2 years ago
Sucuri.php
4 years ago
Sucuri.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Server; |
| 4 | |
| 5 | // We need this to control Sucuri in addition to any other proxy potentially provided by the origin host company |
| 6 | class Sucuri { |
| 7 | const STAGE = "very_early"; |
| 8 | |
| 9 | public static function detect() { |
| 10 | return !empty($_SERVER["HTTP_X_SUCURI_CLIENTIP"]) || !empty($_SERVER["HTTP_X_SUCURI_COUNTRY"]); |
| 11 | } |
| 12 | |
| 13 | public static function isCacheEnabled() { |
| 14 | return self::detect() && !empty($_SERVER["HTTP_SEC_CH_UA_MOBILE"]); |
| 15 | } |
| 16 | |
| 17 | public function init($stage) { |
| 18 | if (self::detect()) { |
| 19 | nitropack_header("Accept-CH: Sec-CH-UA-Mobile"); |
| 20 | |
| 21 | if (self::isCacheEnabled()) { |
| 22 | add_action('nitropack_cacheable_cache_headers', [$this, 'allowProxyCache'], PHP_INT_MAX-1); |
| 23 | add_action('nitropack_cachehit_cache_headers', [$this, 'allowProxyCache'], PHP_INT_MAX-1); |
| 24 | } else { |
| 25 | add_action('nitropack_cacheable_cache_headers', [$this, 'preventProxyCache'], PHP_INT_MAX-1); |
| 26 | add_action('nitropack_cachehit_cache_headers', [$this, 'preventProxyCache'], PHP_INT_MAX-1); |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | public function allowProxyCache() { |
| 32 | nitropack_header("Vary: sec-ch-ua-mobile"); |
| 33 | nitropack_header("Cache-Control: public, max-age=0, s-maxage=15, stale-while-revalidate=3600"); |
| 34 | } |
| 35 | |
| 36 | public function preventProxyCache() { |
| 37 | nitropack_header("Cache-Control: no-cache"); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 |