Skip to content

Commit d0b85b3

Browse files
committed
Set correct Content-Type header for ajax responses in the Magento_UI module.
1 parent 45896ba commit d0b85b3

File tree

1 file changed

+24
-0
lines changed
  • app/code/Magento/Ui/Controller/Adminhtml/Index

1 file changed

+24
-0
lines changed

app/code/Magento/Ui/Controller/Adminhtml/Index/Render.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Ui\Controller\Adminhtml\AbstractAction;
1010
use Magento\Framework\View\Element\UiComponentFactory;
1111
use Magento\Framework\View\Element\UiComponentInterface;
12+
use Magento\Framework\View\Element\UiComponent\ContentType;
1213

1314
/**
1415
* Class Render
@@ -30,6 +31,7 @@ public function execute()
3031
$component = $this->factory->create($this->_request->getParam('namespace'));
3132
$this->prepareComponent($component);
3233
$this->_response->appendBody((string) $component->render());
34+
$this->setResponseContentTypeHeader($component);
3335
}
3436

3537
/**
@@ -45,4 +47,26 @@ protected function prepareComponent(UiComponentInterface $component)
4547
}
4648
$component->prepare();
4749
}
50+
51+
/**
52+
* Set the response 'Content-Type' header based on the component's render engine
53+
*
54+
* @param UiComponentInterface $component
55+
* @return void
56+
*/
57+
private function setResponseContentTypeHeader(UiComponentInterface $component)
58+
{
59+
$contentType = 'text/html';
60+
61+
if ($component->getContext()) {
62+
$renderEngine = $component->getContext()->getRenderEngine();
63+
if ($renderEngine instanceof ContentType\Json) {
64+
$contentType = 'application/json';
65+
} elseif ($renderEngine instanceof ContentType\Xml) {
66+
$contentType = 'application/xml';
67+
}
68+
}
69+
70+
$this->_response->setHeader('Content-Type', $contentType, true);
71+
}
4872
}

0 commit comments

Comments
 (0)