From 659f748dc94e3ec0593a4c5454be69dbc242d1c9 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Tue, 31 Jul 2018 10:44:06 +0200 Subject: [PATCH] Add cache headers to cron endpoints [MAILPOET-1464] --- lib/Cron/Daemon.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Cron/Daemon.php b/lib/Cron/Daemon.php index 7eb5d2d560..5f79b539d7 100644 --- a/lib/Cron/Daemon.php +++ b/lib/Cron/Daemon.php @@ -25,6 +25,7 @@ class Daemon { } function ping() { + $this->addCacheHeaders(); $this->terminateRequest(self::PING_SUCCESS_RESPONSE); } @@ -33,6 +34,7 @@ class Daemon { if(strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { set_time_limit(0); } + $this->addCacheHeaders(); if(!$this->request_data) { $error = __('Invalid or missing request data.', 'mailpoet'); } else { @@ -135,4 +137,16 @@ class Daemon { $daemon['token'] !== $this->token || (isset($daemon['status']) && $daemon['status'] !== CronHelper::DAEMON_STATUS_ACTIVE); } + + private function addCacheHeaders() { + if(headers_sent()) { + return; + } + // Common Cache Control header. Should be respected by cache proxies and CDNs. + header('Cache-Control: no-cache'); + // Mark as blacklisted for SG Optimizer for sites hosted on SiteGround. + header('X-Cache-Enabled: False'); + // Set caching header for LiteSpeed server. + header('X-LiteSpeed-Cache-Control: no-cache'); + } }