Skip to content

[Routing] refactored to support 405 Method Not Allowed responses #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 22, 2011
Merged

[Routing] refactored to support 405 Method Not Allowed responses #128

merged 4 commits into from
Mar 22, 2011

Conversation

kriswallsmith
Copy link
Contributor

This patch includes some refactoring to both the Routing and HttpKernel components...

Routing

  • the URL matcher interface now specifies a mismatch throw one of two exceptions:
    • NotFoundException (404)
    • MethodNotAllowedException (405) - this exception includes a method for accessing the methods that are allowed
  • in order to support the response Allow header, the _method requirement has been reverted back to an array rather than a case-insensitive regular expression
  • does not include apache support (yet?)

HttpKernel

  • refactored exceptions to include explicit methods to access HTTP status code, message and headers

I also explored supporting the 406 Not Acceptable response code, but decided against it since we don't read the request Accept header.

@fabpot
Copy link
Member

fabpot commented Mar 5, 2011

Before merging this patch, we need two things:

  • fix the Apache dumper;
  • use regexes for the _method requirement (we can probably only support *|*|* as suggested on the mailing-list).

@schmittjoh
Copy link
Contributor

Another thought, can we get rid of the HttpException in favor of a NotFoundResponse class?

@kriswallsmith
Copy link
Contributor Author

Throwing an exception allows Routing to remain decoupled from HttpFoundation, a separation we should maintain.

@schmittjoh
Copy link
Contributor

I see, this makes sense, but instead of converting the NotFoundException to a NotFoundHttpException, we could directly return a NotFoundResponse at this point, no? This would save us the round trip to the exception controller and embrace the response concept we have chosen for Symfony2.

@kriswallsmith
Copy link
Contributor Author

I considered this when working on this patch, but having an event and default controller for any >= 400 response is a nice feature I'd rather not get rid of. It should be easy for users to render custom error pages.

@schmittjoh
Copy link
Contributor

What if someone returns a response with a >= 400 status code from the controller? That wouldn't go to the exception controller.

I think you can still accomplish custom error pages using a core.response listener. That seems to be more in line with the Symfony2 credo: "If you want to change the response, listen to core.response."

Now, that we have finally decided on this credo, we should be consistent and embrace it.

@kriswallsmith
Copy link
Contributor Author

I could see us going either way under the credo "as soon as we have a response we're done." I think it's better that we throw an exception so the user has only one integration point when customizing error pages (the controller behind core.exception) rather than one for 5xx errors and another for 4xx errors.

@schmittjoh
Copy link
Contributor

Hehe ;) can we ensure somehow that users cannot return 4xx responses from their controllers? Because otherwise some users will create their own NotFoundResponse class while others will throw an exception, I think it's better and less confusing if we only have one way to achieve this.

@kriswallsmith
Copy link
Contributor Author

I don't see any issue with a controller returning a >= 400 response, it just won't trigger core.exception, obviously.

@avalanche123
Copy link
Contributor

One thing that concerns me with redirect exceptions is that you could throw them from your model or any deepest level of code and affect routing, seems weird to me

@kriswallsmith
Copy link
Contributor Author

There's no such thing as a redirect exception... is there?

@avalanche123
Copy link
Contributor

sorry, I mean NotFoundException et al. Any exception affecting response, that seems weird

@lsmith77
Copy link
Contributor

lsmith77 commented Mar 7, 2011

I also think thats its more important to try and funnel all such "exceptional" cases through the exception controller if the user isnt explicit (aka doesnt create a Response instance manually).

@fabpot
Copy link
Member

fabpot commented Mar 9, 2011

Johannes has a valid point (not really related to this pull request). The current behavior of the framework is different if you just return a 404 response or if you throw and exception.

Kris: Besides two obvious changes I made to the last commit, can I merge this pull request or do you still need to work on the Apache dumper?

@kriswallsmith
Copy link
Contributor Author

I've fixed those two things, but the Apache dumper is not ready yet.

@lsmith77
Copy link
Contributor

In this context I would also like to mention: http://webmachine.basho.com/diagram.html
Would be quite cool if we could try to sensibly implement as much as possible in core and then work on the RestBundle idea to implement the remaining stuff easily inside the user code.

@kriswallsmith
Copy link
Contributor Author

This is ready to be merged now. Please note I've changed Routing's ApacheMatcherDumper to use %{REQUEST_URI} rather than %{PATH_INFO}, simply because I wasn't able to get the latter to work reliably. This also fixes an issue with the mechanism that redirects to append a trailing slash, which we redirecting with %{PATH_INFO} rather than %{REQUEST_URI}. This adds a new base_uri option to the dumper and dump command.

@kriswallsmith
Copy link
Contributor Author

I've updated the fixture. All tests are passing.

@fabpot fabpot merged commit 66cbad3 into symfony:master Mar 22, 2011
SofHad pushed a commit to SofHad/symfony that referenced this pull request Oct 12, 2015
This PR was merged into the master branch.

Discussion
----------

Add missing uk/ru translations

According to symfony/demo@2c9a153

Commits
-------

78b4a88 Add missing uk/ru translations
jderusse pushed a commit to jderusse/symfony that referenced this pull request Mar 30, 2020
This PR was squashed before being merged into the master branch (closes symfony#128).

Discussion
----------

Check any Composer repository

This is an attempt to implement symfony#127 (and would allow symfony#126 to pass). I haven't used the `ComposerRepository` class before, but couldn't see a simple way to consistently find out if a repository knew a particular package name, so it's doing a search then cycling through the results.

Commits
-------

0cfad5a Check any Composer repository
chalasr pushed a commit to chalasr/symfony that referenced this pull request Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants