I was getting this error when sending response to the get type ajax controller.

the code was like below.



namespace Vendor\Module\Controller\Index;

use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\Response\Http;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Result\PageFactory;
use Psr\Log\LoggerInterface;

class Download implements HttpGetActionInterface

    protected $resultPageFactory;

    protected $serializer;

    protected $logger;

    protected $http;

    public function __construct(
        PageFactory $resultPageFactory,
        Json $json,
        LoggerInterface $logger,
        Http $http
    ) {
        $this->resultPageFactory = $resultPageFactory;
        $this->serializer = $json;
        $this->logger = $logger;
        $this->http = $http;

    public function execute()
        try {
            return $this->jsonResponse('your response');
        } catch (LocalizedException $e) {
            return $this->jsonResponse($e->getMessage());
        } catch (\Exception $e) {
            return $this->jsonResponse($e->getMessage());

    public function jsonResponse($response = '')
        $this->http->setHeader('Content-Type', 'application/json');
        return $this->http->setBody(

1 Answer 1


The solution is simple if you look at the Kernel.php line : 134,

you'll find a condition like $response->getHeader('Cache-Control')->getFieldValue() .

So you can set it manually like below,in the response code and the error will be resolved.

$this->http->setHeader('Cache-Control', '');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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