@@ -155,3 +155,76 @@ action:
155
155
Because you are redirecting to a route instead of a path, the required
156
156
option is called ``route `` in the ``redirect() `` action, instead of ``path ``
157
157
in the ``urlRedirect() `` action.
158
+
159
+ Redirecting POST/PUT calls
160
+ --------------------------
161
+
162
+ As default behaviour of both methods mentioned above results in sending
163
+ response with ``301 `` or ``302 `` HTTP status codes, the following call will
164
+ be made with use of HTTP request method. But it some scenarios it is
165
+ expected or required that following call will be made with the same HTTP
166
+ method, i.e. when initial call was ``POST `` one, then following one should
167
+ be also ``POST `` not ``GET ``. In order to achieve this both
168
+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ RedirectController::urlRedirectAction `
169
+ and
170
+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ RedirectController::redirectAction `
171
+ are accepting aditional switch called ``keepRequestMethod ``:
172
+
173
+ .. configuration-block ::
174
+
175
+ .. code-block :: yaml
176
+
177
+ # config/routes.yaml
178
+
179
+ # ...
180
+
181
+ admin :
182
+ path : /webhooks/foo
183
+ controller : Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
184
+ defaults :
185
+ route : foo_webhook_handler
186
+ permanent : true
187
+ keepRequestMethod : true
188
+
189
+ .. code-block :: xml
190
+
191
+ <!-- config/routes.xml -->
192
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
193
+ <routes xmlns =" http://symfony.com/schema/routing"
194
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
195
+ xsi : schemaLocation =" http://symfony.com/schema/routing
196
+ http://symfony.com/schema/routing/routing-1.0.xsd" >
197
+
198
+ <!-- ... -->
199
+
200
+ <route id =" admin" path =" /webhooks/foo" > ``
201
+ <default key =" _controller" >Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction</default >
202
+ <default key =" route" >foo_webhook_handler</default >
203
+ <default key =" permanent" >true</default >
204
+ <default key =" keepRequestMethod" >true</default >
205
+ </route >
206
+ </routes >
207
+
208
+ .. code-block :: php
209
+
210
+ // config/routes.php
211
+ use Symfony\Component\Routing\RouteCollection;
212
+ use Symfony\Component\Routing\Route;
213
+
214
+ $collection = new RouteCollection();
215
+ // ...
216
+
217
+ $collection->add('admin', new Route('/webhooks/foo', array(
218
+ '_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction',
219
+ 'route' => 'foo_webhook_handler',
220
+ 'permanent' => true,
221
+ 'keepRequestMethod' => true
222
+ )));
223
+
224
+ return $collection;
225
+
226
+ Switching ``keepRequestMethod `` switch to ``true `` will result in sending
227
+ response with either ``307 `` (when ``permament `` switch is set to false) or
228
+ ``308 `` (with ``permament `` being true) HTTP status code which will tell that
229
+ HTTP request should be repeated with both request method and body being
230
+ unchanged.
0 commit comments