laminas-mvc
laminas-mvc copied to clipboard
Accept headers not satisfied in correct order by AcceptableViewModelSelector controller plugin
According to the WC3 Specifictations the Server should try to satisfy accept headers in order. Currently the order of the content-types in the Accept header is not respected.
So when I send a request with an Accept header like this: application/xml, application/json it should first try to return a xml and then a json model. When I do application/json, application/xml it should be the other way around.
The AcceptableViewModelSelector controller plugin does not seem to respect the order in which content types are requested.
I reported this issue here inside Apigility module but it turned out the behavior is caused by the Zend\Mvc\Controller\Plugin\AcceptableViewModelSelector controller plugin.
Originally posted by @Wilt at https://github.com/zendframework/zend-mvc/issues/16
Is this still an issue? I tried this test case and it passes:
public function testZendMvcIssue16()
{
$arr = [
'Zend\View\Model\JsonModel' => ['application/json'],
'Zend\View\Model\FeedModel' => ['application/rss+xml'],
];
$header = Accept::fromString('application/rss+xml, application/json');
$this->request->getHeaders()->addHeader($header);
$plugin = $this->plugin;
$result = $plugin($arr);
$this->assertEquals('Zend\View\Model\ViewModel', $this->plugin->getDefaultViewModelName());
$this->assertInstanceOf('Zend\View\Model\FeedModel', $result);
$this->assertNotInstanceOf('Zend\View\Model\JsonModel', $result);
}
Originally posted by @adamlundrigan at https://github.com/zendframework/zend-mvc/issues/16#issuecomment-240089443
Thanks for checking this. I am not sure since I haven't tested it for a long time. I can see if the issue still applies, will get back on this.
Originally posted by @Wilt at https://github.com/zendframework/zend-mvc/issues/16#issuecomment-240099191