Skip to content

[FrameworkBundle] PR #26213 Document redirections with 307/308 HTTP status codes #9298

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 3 commits into from
Mar 5, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions routing/redirect_in_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,76 @@ action:
Because you are redirecting to a route instead of a path, the required
option is called ``route`` in the ``redirect()`` action, instead of ``path``
in the ``urlRedirect()`` action.

Redirecting POST/PUT calls
--------------------------

As default behaviour of both methods mentioned above results in sending
Copy link
Contributor

Choose a reason for hiding this comment

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

As a

response with ``301`` or ``302`` HTTP status codes, the following call will
be made with use of HTTP request method. But it some scenarios it is
Copy link
Contributor

Choose a reason for hiding this comment

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

use of HTTP request method
WDYM ?

But it some scenarios
But in some scenarios it's either expected or required that the following call [...]

expected or required that following call will be made with the same HTTP
method, i.e. when initial call was ``POST`` one, then following one should
be also ``POST`` not ``GET``. In order to achieve this both
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction`
and
:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::redirectAction`
are accepting aditional switch called ``keepRequestMethod``:

.. configuration-block::

.. code-block:: yaml

# config/routes.yaml

# ...
Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove this


admin:
path: /webhooks/foo
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
defaults:
route: foo_webhook_handler
permanent: true
keepRequestMethod: true

.. code-block:: xml

<!-- config/routes.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<!-- ... -->
Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove this


<route id="admin" path="/webhooks/foo"> ``
<default key="_controller">Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction</default>
<default key="route">foo_webhook_handler</default>
<default key="permanent">true</default>
<default key="keepRequestMethod">true</default>
</route>
</routes>

.. code-block:: php

// config/routes.php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$collection = new RouteCollection();
// ...
Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove this


$collection->add('admin', new Route('/webhooks/foo', array(
'_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction',
'route' => 'foo_webhook_handler',
'permanent' => true,
'keepRequestMethod' => true
)));

return $collection;

Switching ``keepRequestMethod`` switch to ``true`` will result in sending
Copy link
Contributor

Choose a reason for hiding this comment

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

When keepRequestMethod is set to true with either permanent set to false which will lead to a 307 response or 308 with permanent being true. Theses codes will give information in the HTTP request that the method should be repeated without altering the body.

response with either ``307`` (when ``permament`` switch is set to false) or
``308`` (with ``permament`` being true) HTTP status code which will tell that
HTTP request should be repeated with both request method and body being
unchanged.