Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Accept headers not satisfied in correct order by AcceptableViewModelSelector controller plugin #16

Open
Wilt opened this issue Jul 28, 2015 · 3 comments

Comments

@Wilt
Copy link

Wilt commented Jul 28, 2015

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.

@adamlundrigan
Copy link
Contributor

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

@Wilt
Copy link
Author

Wilt commented Aug 16, 2016

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.

@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas/laminas-mvc; a new issue has been opened at laminas/laminas-mvc#37.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants