cancel
Showing results for 
Search instead for 
Did you mean: 

How can I include additional headers in every 401 Magento2 response?

How can I include additional headers in every 401 Magento2 response?

How can i include some additional headers every time server needs to send 401 responses? I tried adding it in Magento\Framework\Controller\Result\Json render() method like:
if ($response->getHttpResponseCode() == 401)
    $response->setHeader('WWW-Authenticate','/V1/integration/admin/token', true); 

But that did not worked.

 

So i tried adding it in Magento\Framework\App\Response\HTTP in setNoCacheHeaders(), setPrivateHeaders() and setPublicHeaders() like: 

 

 

if ($response->getHttpResponseCode() == 401)
   $response->setHeader('WWW-Authenticate','/V1/integration/admin/token', true);

 

But that did not worked as well. Any ideas?