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)
                        ->setConfig(array('timeout' => 5))

                $headers = $response->getHeaders();

                    ->setHeader('Content-type', $headers['Content-type'])

$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?

  • I've added a answer based on latest Magento, by adding more information about headers and Magento version you could get a better or more specific answer – Jeroen Jan 16 '16 at 13:27

Yes, adding a rewrite that does pass true as the third parameter to the setHeader() method would fix this.

Setting the third parameter $replace to true will make the setHeader() method to search the array of headers (already set before) and unset() 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: ..."

| improve this answer | |

I've looked up. Default Magento will just add one header. So therefore not giving errors of any kind.

I'm guessing you have a 3rd party module to optimize Magento or serverside Apache/Nginx/PHP setting which also add these headers.

You could look which is set first to make it a little easier to lookup.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.