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

DOCS: Dont mention the inspection of the Accept HTTP Header #84

Merged
merged 4 commits into from
Mar 20, 2017
Merged

DOCS: Dont mention the inspection of the Accept HTTP Header #84

merged 4 commits into from
Mar 20, 2017

Conversation

MatthiasKuehneEllerhold
Copy link
Contributor

The View Strategies are mentioning (in the code and in the docs) that they are inspecting the "Accept" HTTP header and determine if they are going to inject their renderer and response.

But in fact, they dont do that. They just test if the View Model is an instanceof their ViewModel (JsonModel and FeedModel). I trusted the documentation on that and spent a lot of time wondering why it doesnt work... :(

I've removed every (wrong) mentioning of the inspection of the "Accept" header from the php-docs and the md docs. I've left in the (correct) sections in the quick-start on how to inspect the "Accept" header and set the correct strategy accordingly.

There should be no changes in behavior at all because only documentation was changed.

@adamlundrigan
Copy link
Contributor

That functionality was removed from both JsonStrategy and FeedStrategy ages ago (v2.0.4, IIRC) (PR) but the documentation was not updated to match. I believe it was replaced by the AcceptableViewModelSelector controller plugin, which requires you to define the allowable types and will juggle the ViewModel instance appropriately based on the Accept header.

@MatthiasKuehneEllerhold
Copy link
Contributor Author

@adamlundrigan Ok, one more reason to update the documentation then :)

Maybe the docs Zend-View Quickstart should also include the link to AcceptableViewModelSelector ?

@adamlundrigan
Copy link
Contributor

Yeah, that's a good idea...maybe a new blurb at the end of "Controllers and View Models" with an example of how to use the plugin. The example at the bottom of the page (AcceptStrategy class) should also be axed as it suffers from the same security problems the Accept handling in JsonRenderer/FeedRenderer had initially.

Could you add those two changes your PR as well?

@MatthiasKuehneEllerhold
Copy link
Contributor Author

Ive looked over the whole quick start again and found another flaw:

  1. "Creating and Registering Alternate Rendering and Response Strategies"
    This whole section is invalid or misleading at best. Just by injecting the JsonStrategy during the render event (rather than in the config?) there is no "ensurance that a JSON payload is created when requested".
    This whole section needs to be revised to say:
  2. register the strategy (preferable via the config so its cacheable)
  3. create a JsonModel (or FeedModel) in your controller and return it
  4. => a JSON (or Feed) payload will be returned.

I'll try my hand on that, but english isnt my mother tongue so you'll have to except some awkward language ;)

Offtopic: Why do we have to enable JSON in two steps: register the strategy and explicitly return a JSON-Model. Whats the downside of always registering the two other strategies? Security, Performance, RAM? It would be a huge ease-of-use improvement if we could just return a JsonModel (or FeedModel) from a controller and it would switch the output completly.

@MatthiasKuehneEllerhold
Copy link
Contributor Author

Using the acceptableViewModelSelector didnt work (correctly) either: zendframework/zend-mvc#194 :(

@MatthiasKuehneEllerhold
Copy link
Contributor Author

I've clarified the acceptableViewModelSelector documentation in zendframework/zend-mvc#195
Any news on this PR?

@weierophinney
Copy link
Member

Offtopic: Why do we have to enable JSON in two steps: register the strategy and explicitly return a JSON-Model. Whats the downside of always registering the two other strategies? Security, Performance, RAM?

Performance, flexibility, and consistency.

Performance, in that it reduces the number of view listeners required. Flexibility and consistency, in that the user is then required to register the strategy or a substitute at the priority required for their application; if we auto-register, there's a very real possibility that the "auto-magically" registered service might register at a priority that supercedes the user-registered service, which makes for hard-to-find error conditions. (As a real-world example, we have a separate JSON renderer in Apigility that renders HAL payloads; having ZF autoregister its own JSON strategy could lead to invalid response payloads.)


class AcceptStrategy implements ListenerAggregateInterface
class MyController extends \Zend\Mvc\Controller\AbstractActionController
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import the abstract controller, and reference the imported class name.

@MatthiasKuehneEllerhold
Copy link
Contributor Author

@weierophinney Any news on this?

@weierophinney weierophinney self-assigned this Mar 20, 2017
@weierophinney weierophinney added this to the 2.8.2 milestone Mar 20, 2017
@weierophinney weierophinney merged commit 6bc5f8a into zendframework:master Mar 20, 2017
weierophinney added a commit that referenced this pull request Mar 20, 2017
DOCS: Dont mention the inspection of the Accept HTTP Header
weierophinney added a commit that referenced this pull request Mar 20, 2017
weierophinney added a commit that referenced this pull request Mar 20, 2017
@weierophinney
Copy link
Member

Thanks, @MatthiasKuehneEllerhold

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

Successfully merging this pull request may close these issues.

3 participants