Created
August 14, 2017 13:52
-
-
Save edrdesigner/34ab98da0b4adb8259bc6566effd3f9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @overright = app/code/core/Mage/Core/Controller/Response/Http.php | |
public function sendHeaders() | |
{ | |
if (!$this->canSendHeaders()) { | |
Mage::log('HEADERS ALREADY SENT: '.mageDebugBacktrace(true, true, true)); | |
return $this; | |
} | |
if (in_array(substr(php_sapi_name(), 0, 3), array('cgi', 'fpm'))) | |
{ | |
// remove duplicate headers | |
$remove = array('status', 'content-type'); | |
// already sent headers | |
$sent = array(); | |
foreach (headers_list() as $header) | |
{ | |
// parse name | |
if (!$pos = strpos($header, ':')) | |
continue; | |
$sent[strtolower(substr($header, 0, $pos))] = true; | |
} | |
// raw headers | |
$headersRaw = array(); | |
foreach ($this->_headersRaw as $i=>$header) | |
{ | |
// parse name | |
if (!$pos = strpos($header, ':')) | |
continue; | |
$name = strtolower(substr($header, 0, $pos)); | |
if (in_array($name, $remove)) | |
{ | |
// check sent headers | |
if ($sent[$name]) | |
{ | |
unset($this->_headersRaw[$i]); | |
continue; | |
} | |
// check header | |
if (!is_null($existing = $headers[$name])) | |
{ | |
$this->_headersRaw[$existing] = $header; | |
unset($this->_headersRaw[$i]); | |
} | |
else | |
$headersRaw[$name] = $i; | |
} | |
} | |
// object headers | |
$headers = array(); | |
foreach ($this->_headers as $i=>$header) | |
{ | |
$name = strtolower($header['name']); | |
if (in_array($name, $remove)) | |
{ | |
// check sent headers | |
if ($sent[$name]) | |
{ | |
unset($this->_headers[$i]); | |
continue; | |
} | |
// check header | |
if (!is_null($existing = $headers[$name])) | |
{ | |
$this->_headers[$existing] = $header; | |
unset($this->_headers[$i]); | |
} | |
else | |
$headers[$name] = $i; | |
// check raw headers | |
if (!is_null($existing = $headersRaw[$name])) | |
unset($this->_headersRaw[$existing]); | |
} | |
} | |
} | |
parent::sendHeaders(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment