-
Notifications
You must be signed in to change notification settings - Fork 196
NotFoundDelegate and NotFoundHandler #441
Comments
I guess you mean the most inner layer. A request goes from the outside to the inside. It first encounters the ErrorHandler (outermost layer), all other middleware and finally the NotFoundHandler (innermost layer) if none of the previous middleware returned a response. I'm not sure where you read that, but as I understand it, the NotFoundDelegate is something internally and you don't need to set it up. It's sort of a fail safe in case the NotFoundHandler is not working or missing. If you have a (custom) NotFoundHandler than Expressive should never get to the NotFoundDelegate. Somehow I agree that it doesn't make sense to have a NotFoundHandler AND a NotFoundDelegate. They basically do the same thing: return a 404 if no response is returned at that point. But than again, if the that delegate/handler doesn't do what it should be doing, the fail safe is gone and you don't get a 404 response. |
Yeah, sorry. Fixed it :D
Well, you can provide a custom
My point is that we don't need to pipe a |
I see the argument, however I think there's room for both, mainly because the Having both explicitly in the pipeline and default services makes it clear to new users that they are separate roles, and can each be customized to provide different behavior. I think that's powerful. |
Why not providing it as a middleware instead? I think
Yeah, in this case the
Again that could be implemented as a middleware. That's why I think there is no place for both here. Since middlewares can return the response without calling the delegate, there's no reason to have a default delegate after all, Zend\Expressive could simply throw an exception with a "no middleware returned a response" message. |
I agree, why not just have a custom middleware instead of NotFoundHandler. Why is it not recommended in docs instead of asking to create a custom Delegate. |
Version 3 will no longer have this feature, as of #543, which was merged yesterday. The assumption will be that the middleware pipeline returns a response, and if the queue is exhausted, it will raise an exception. In that patch, I kept the |
Because the `MiddlewarePipe` does not compose a "default handler", and because the `MiddlewarePipe` is what the request handler runner dispatches, there is no longer a concept of a "default delegate" (v2) or "default handler" (v3); there is only middleware. As such, this patch merges the `NotFoundHandler` into the `NotFoundMiddleware`. A key is kept for the `DefaultDelegate` service, but it will now resolve to the `NotFoundMiddleware`. Fixes zendframework#441.
Because the `MiddlewarePipe` does not compose a "default handler", and because the `MiddlewarePipe` is what the request handler runner dispatches, there is no longer a concept of a "default delegate" (v2) or "default handler" (v3); there is only middleware. As such, this patch merges the `NotFoundHandler` into the `NotFoundMiddleware`. A key is kept for the `DefaultDelegate` service, but it will now resolve to the `NotFoundMiddleware`. Fixes zendframework#441.
Because the `MiddlewarePipe` does not compose a "default handler", and because the `MiddlewarePipe` is what the request handler runner dispatches, there is no longer a concept of a "default delegate" (v2) or "default handler" (v3); there is only middleware. As such, this patch merges the `NotFoundHandler` into the `NotFoundMiddleware`. A key is kept for the `DefaultDelegate` service, but it will now resolve to the `NotFoundMiddleware`. Fixes zendframework#441.
While upgrading to Expressive 2 I found these new
NotFoundDelegate
andNotFoundHandler
a bit confusing. 😕The 2.0 docs suggests using
NotFoundDelegate
as default delegate and pipingNotFoundHandler
as theoutermost(EDIT: inner) middleware, which makes no sense for me sinceNotFoundHandler
usesNotFoundDelegate
internally andNotFoundDelegate
would be called anyway ifNotFoundHandler
was not piped.As such, to avoid confusion I'd suggest removing the "default delegate" concept and recommend usage of "catch-all" middlewares only.
Thoughts?
The text was updated successfully, but these errors were encountered: