How to set up custom response HTTP header from a controller in Magento 2
To set up custom response HTTP header from a controller in Magento 2, use the following code:

1 2 3 4 5 |
** @var \Magento\Framework\App\ObjectManager $om */ $om = \Magento\Framework\App\ObjectManager::getInstance(); /** @var \Magento\Framework\App\ResponseInterface|\Magento\Framework\App\Response\Http $response */ $response = $om->get('Magento\Framework\App\ResponseInterface'); $response->setHeader('<header name>', '<header value>', $overwriteExisting = true); |
For instance:
1 |
$response->setHeader('Content-Transfer-Encoding', 'binary', true); |
