Skip to content

Commit

Permalink
Removed redundant POST request exclusion info
Browse files Browse the repository at this point in the history
The default ``ExceptionListener::setTargetPath()`` already excludes POSTs/PUTs, so suggesting that people who implement their own listener to do this is a bit misleading.

However, doing this to prevent XMLHttpRequest URIs from being saved is still valuable.
  • Loading branch information
ryancastle committed May 28, 2014
1 parent 080a769 commit 556365b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cookbook/security/target_path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ the name of the firewall, defined in ``security.yml``). Upon a successful
login, the user is redirected to this path, as to help them continue from the
last known page they visited.

On some occasions, this is unexpected. For example when the last request
URI was an HTTP POST against a route which is configured to allow only a POST
method, the user is redirected to this route only to get a 404 error.
On some occasions, this is unexpected. For example when the last request before logout
was an XMLHttpRequest route, the user may be redirected back to an invalid
route.

To get around this behavior, you would simply need to extend the ``ExceptionListener``
class and override the default method named ``setTargetPath()``.
Expand Down Expand Up @@ -56,9 +56,10 @@ Next, create your own ``ExceptionListener``::
{
protected function setTargetPath(Request $request)
{
// Do not save target path for XHR and non-GET requests
// Do not save target path for XHR requests
// You can add any more logic here you want
if ($request->isXmlHttpRequest() || 'GET' !== $request->getMethod()) {
// Note that non-GET requests are already ignored
if ($request->isXmlHttpRequest()) {
return;
}

Expand Down

0 comments on commit 556365b

Please sign in to comment.