From 4b27a503b5c784900e14c9c1cf2da8820422e51d Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 9 May 2016 23:07:29 +0900 Subject: [PATCH] Fix incorrect server push detection when using CloudFlare --- .../FrontEndFileHandler.class.php | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/classes/frontendfile/FrontEndFileHandler.class.php b/classes/frontendfile/FrontEndFileHandler.class.php index 2f2c27408..18a5ebbc7 100644 --- a/classes/frontendfile/FrontEndFileHandler.class.php +++ b/classes/frontendfile/FrontEndFileHandler.class.php @@ -442,7 +442,7 @@ class FrontEndFileHandler extends Handler } // Enable HTTP/2 server push for CSS resources. - if ($finalize && config('view.server_push') && strncmp($_SERVER['SERVER_PROTOCOL'], 'HTTP/2', 6) === 0) + if ($finalize && $this->_isServerPushEnabled()) { foreach ($result as $resource) { @@ -546,7 +546,7 @@ class FrontEndFileHandler extends Handler } // Enable HTTP/2 server push for JS resources. - if ($type === 'head' && $finalize && config('view.server_push') && strncmp($_SERVER['SERVER_PROTOCOL'], 'HTTP/2', 6) === 0) + if ($type === 'head' && $finalize && $this->_isServerPushEnabled()) { foreach ($result as $resource) { @@ -667,6 +667,31 @@ class FrontEndFileHandler extends Handler $cssSortList = array('common' => -100000, 'layouts' => -90000, 'modules' => -80000, 'widgets' => -70000, 'addons' => -60000); $file->index = $cssSortList[$tmp[0]]; } + + /** + * Check if server push is enabled. + * + * @return bool + */ + protected function _isServerPushEnabled() + { + if (!config('view.server_push')) + { + return false; + } + elseif (strncmp($_SERVER['SERVER_PROTOCOL'], 'HTTP/2', 6) === 0) + { + return true; + } + elseif (isset($_SERVER['HTTP_CF_VISITOR']) && \RX_SSL) + { + return true; + } + else + { + return false; + } + } } /* End of file FrontEndFileHandler.class.php */ /* Location: ./classes/frontendfile/FrontEndFileHandler.class.php */