Fix incorrect server push detection when using CloudFlare

This commit is contained in:
Kijin Sung 2016-05-09 23:07:29 +09:00
parent 9e78c66f7c
commit 4b27a503b5

View file

@ -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 */