zend-mvc icon indicating copy to clipboard operation
zend-mvc copied to clipboard

Accept headers not satisfied in correct order by AcceptableViewModelSelector controller plugin

Open Wilt opened this issue 9 years ago • 3 comments

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.

Wilt avatar Jul 28 '15 15:07 Wilt

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);
    }

adamlundrigan avatar Aug 16 '16 12:08 adamlundrigan

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.

Wilt avatar Aug 16 '16 13:08 Wilt

This repository has been closed and moved to laminas/laminas-mvc; a new issue has been opened at https://github.com/laminas/laminas-mvc/issues/37.

michalbundyra avatar Jan 15 '20 19:01 michalbundyra