Closte.php
4 years ago
Cloudways.php
4 years ago
DreamHost.php
4 years ago
Flywheel.php
4 years ago
GoDaddyWPaaS.php
4 years ago
GridPane.php
4 years ago
Hosting.php
4 years ago
Kinsta.php
4 years ago
Pagely.php
4 years ago
PagelyCachePurge.php
4 years ago
Pressable.php
3 years ago
RocketNet.php
4 years ago
Savvii.php
4 years ago
SiteGround.php
4 years ago
Vimexx.php
4 years ago
WPEngine.php
4 years ago
WPX.php
3 years ago
Savvii.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Hosting; |
| 4 | |
| 5 | class Savvii extends Hosting |
| 6 | { |
| 7 | const STAGE = "very_early"; |
| 8 | |
| 9 | public static function detect() |
| 10 | { |
| 11 | return isset($_SERVER['WARPDRIVE_API']) && $_SERVER['WARPDRIVE_API'] == 'https://api.savvii.services'; |
| 12 | } |
| 13 | |
| 14 | public function init($stage) |
| 15 | { |
| 16 | if ($this->getHosting() == "savvii") { |
| 17 | add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']); |
| 18 | add_action('nitropack_execute_purge_all', [$this, 'purgeAll']); |
| 19 | add_action('nitropack_early_cache_headers', [$this, 'setCacheControl']); |
| 20 | add_action('nitropack_cacheable_cache_headers', [$this, 'setCacheControl']); |
| 21 | add_action('nitropack_cachehit_cache_headers', [$this, 'setCacheControl']); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | public function purgeUrl($url) |
| 26 | { |
| 27 | try { |
| 28 | $siteConfig = nitropack_get_site_config(); |
| 29 | if ($siteConfig && !empty($siteConfig['home_url'])) { |
| 30 | $urlObject = new \NitroPack\Url($url); |
| 31 | |
| 32 | $http = new \NitroPack\HttpClient(nitropack_trailingslashit($siteConfig['home_url']) . 'purge'); |
| 33 | $http->setHeader('X-PURGE-HOST', $urlObject->getHost()); |
| 34 | $http->setHeader('X-PURGE-PATH-REGEX', $urlObject->getPath() . '.*'); |
| 35 | $http->fetch(false, "PURGE"); |
| 36 | } |
| 37 | } catch (\Exception $e) { |
| 38 | // Breeze exception |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | public function purgeAll() { |
| 43 | try { |
| 44 | $siteConfig = nitropack_get_site_config(); |
| 45 | if ($siteConfig && !empty($siteConfig['home_url'])) { |
| 46 | $url = new \NitroPack\Url($siteConfig['home_url']); |
| 47 | |
| 48 | $http = new \NitroPack\HttpClient($url->getNormalized() . 'purge'); |
| 49 | $http->setHeader('X-PURGE-HOST', $url->getHost()); |
| 50 | $http->fetch(false, "PURGE"); |
| 51 | } |
| 52 | } catch (\Exception $e) { |
| 53 | // Exception |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public function setCacheControl() { |
| 58 | nitropack_header("Vary: sec-ch-ua-mobile"); |
| 59 | if (isset($_SERVER["HTTP_SEC_CH_UA_MOBILE"])) { |
| 60 | nitropack_header("Cache-Control: public, max-age=0, s-maxage=3600"); // needs to be like that instead of Cache-Control: no-cache in order to allow caching in the provided reverse proxy, but prevent the browsers from doing so |
| 61 | } else { |
| 62 | return; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 |