Issues

ZF-11686: Zend_Controller_Action_Helper_Json doesn't send 'Content-Type: application/json' header

Issue Type: Bug Created: 2011-08-19T10:01:20.000+0000 Last Updated: 2011-08-19T12:10:23.000+0000 Status: Resolved Fix version(s): Reporter: Marco (p0l0) Assignee: Ramon Henrique Ornelas (ramon) Tags: - Zend_Controller

Related issues: - ZF-10675

Attachments:

Description

The Action Helper returns Json encoded string but doesn't set the Content-Type Header.

Comments

Posted by Marco (p0l0) on 2011-08-19T10:35:04.000+0000

Here is a patch which would solve this issue:

<pre class="highlight">
Index: library/Zend/Controller/Action/Helper/Json.php
===================================================================
--- library/Zend/Controller/Action/Helper/Json.php  (revision 24388)
+++ library/Zend/Controller/Action/Helper/Json.php  (working copy)
@@ -99,6 +99,7 @@
     {
         $data = $this->encodeJson($data, $keepLayouts);
         $response = $this->getResponse();
+        $response->setHeader('Content-Type', 'application/json', true);
         $response->setBody($data);
 
         if (!$this->suppressExit) {

Posted by Ramon Henrique Ornelas (ramon) on 2011-08-19T11:19:14.000+0000

@Marco The helper action Json uses view helper json where the header is assigned (see Zend_View_Helper_Json line 77).

Greetings Ramon

Posted by Marco (p0l0) on 2011-08-19T12:00:00.000+0000

@Ramon: Thanks I see that it now works under 1.11.10. I had testet it with Zend Version 1.10.6 were the Header isn't overwritten in the view helper, thats because I only compared the Action Helper.

Bug can be closed

Posted by Ramon Henrique Ornelas (ramon) on 2011-08-19T12:09:14.000+0000

@Marco True this was fix in 1.11.1 with ZF-10675.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts