-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
307 redirect for POST/PUT requests #26171
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
Comments
I think the RedirectController can just automatically use 307 when the current scheme is not GET and permanent = false or 308 when permanent = true |
@Tobion I don't think that it will work as I have met a lot of projects where e.g. resource save (POST) action at the end does redirect to show saved resource (GET) - with 307/308 redirect it will stop working. I think that it should be rather additional parameter for the redirect action which will say if it should be 301/302 or 307/308 |
@ZipoKing you wouldn't use the RedirectController for this. That would be strange. |
Yes, I won't but as I said I have seen a lot of crazy code over my career. So therefore I'd rather go with extra bool param saying if we should use 301/302 (as default so backward compability will be kept) or 307/308. I'll try to make some PR later today about that. |
@ZipoKing In this case, maybe put an option for 307/308 redirect with a deprecation message telling it will be the default on next major? |
Pull request created: symfony/framework-bundle#22 |
(One minute, will create proper one for symfony/symfony) |
…odes in RedirectController (ZipoKing) This PR was squashed before being merged into the 4.1-dev branch (closes #26213). Discussion ---------- [FrameworkBundle] Add support to 307/308 HTTP status codes in RedirectController | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26171 | License | MIT | Doc PR | With this PR `RedirectController` will allow to create redirections with use of 307/308 HTTP status codes together with 301/302. Related RFC documents: * https://tools.ietf.org/html/rfc7231 * https://tools.ietf.org/html/rfc7538 Commits ------- 64fb5a5 [FrameworkBundle] Add support to 307/308 HTTP status codes in RedirectController
Thanks for adding it to 4.0. |
As this is a new feature, it's only available in upcoming versions. |
@Tobion Thanks for your reply. However I believe it is more of a requirement not satisfied, and not a feature only , as there are definitely people, using 2.8 + or 3.+, who would use POST/PUT requests in the route. So it does have a problem with backward compatibility too. |
I confirm this is a new feature: that's how the redirect controller behaved for now. If you need the new behavior right now, you can copy/paste the new code in a controller of your own. |
Alright @nicolas-grekas , Thanks for your reply :) |
Is it possible to send POST parameters to a URL via a RedirectResponse 307 where the "name" of an HTML field is the name of a parameter of the array in the RedirectResponse (for example : "NOM" is the "name" of an HTML field)? I tried this but the server doesn't seem to receive my params :
|
Uh oh!
There was an error while loading. Please reload this page.
I have a version v2 of an API which has majority routes going back to V1, except for a few .
For v2
For V1
The GET requests get redirected with 302 code successfully, while the post requests see an error like this
No route found for "GET /api/v1/addresses": Method Not Allowed (Allow: POST)
The class that does the routing has handling only for parameters 301 and 302.
This is the reason that a request that is post and that should be redirected with 307 status code is not redirected at all, leading to even POST requests getting transferred as GET.
I just changed line
return new RedirectResponse($this->container->get('router')->generate($route, $attributes, UrlGeneratorInterface::ABSOLUTE_URL), $permanent ? 301 : 302);
To
return new RedirectResponse($this->container->get('router')->generate($route, $attributes, UrlGeneratorInterface::ABSOLUTE_URL), 307);
And this works well ( of course not completely correct). I think this needs an enhancement to even allow POST requests to be redirected.
Proposed solution : (Since I have not learned the pull process completely)
And in routing use this for POST```
v2_rest_save_adresses:
pattern: api/v2/addresses
defaults:
_controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
route: rest_save_adresses
postOrPut: true
The text was updated successfully, but these errors were encountered: