I'm getting an apache error saying that I have duplicate headers for 'Content-Type'. I see that the tunnelAction
function correctly adds the header Content-Type:image/png
, but instead of passing in the parameter to replace the original header, it just appends it to the list. Here is the current code below:
$response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)
->setParameterGet($params)
->setConfig(array('timeout' => 5))
->request('GET');
$headers = $response->getHeaders();
$this->getResponse()
->setHeader('Content-type', $headers['Content-type'])
->setBody($response->getBody());
$headers['Content-type']
is "image/png"
, but it's not passing in a 3rd boolean parameter to replace the existing header "text/html". I'm wondering if adding my own route to handle this request would be the right fix?
Best Answer
Yes, adding a rewrite that does pass
true
as the third parameter to thesetHeader()
method would fix this.Setting the third parameter
$replace
totrue
will make thesetHeader()
method to search the array of headers (already set before) andunset()
any header with the same name, making the "Content-type" header that you are setting the only one.By the way, note that the official header name is "Content-Type" with a capital 'T'. The replace function of the
setHeader()
method is case sensitive. So you might still end up with two headers, one "Content-type: ..." and another "Content-Type: ..."