[FrameworkBundle] non-permanent redirect should be status code 404 according to spec

This commit is contained in:
Tobias Schultze 2012-08-28 08:03:23 +02:00
parent a1e6cfbe15
commit 4c5bfab058
2 changed files with 12 additions and 7 deletions

View File

@ -39,7 +39,7 @@ class RedirectController extends ContainerAware
public function redirectAction($route, $permanent = false)
{
if (!$route) {
return new Response(null, 410);
return new Response(null, $permanent ? 410 : 404);
}
$attributes = $this->container->get('request')->attributes->get('_route_params');
@ -67,7 +67,7 @@ class RedirectController extends ContainerAware
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
{
if (!$path) {
return new Response(null, 410);
return new Response(null, $permanent ? 410 : 404);
}
$statusCode = $permanent ? 301 : 302;

View File

@ -29,11 +29,13 @@ class RedirectControllerTest extends TestCase
$controller = new RedirectController();
$controller->setContainer($container);
$returnResponse = $controller->redirectAction('');
$returnResponse = $controller->redirectAction('', true);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
$this->assertEquals(410, $returnResponse->getStatusCode());
$returnResponse = $controller->redirectAction('', false);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
$this->assertEquals(404, $returnResponse->getStatusCode());
}
/**
@ -102,11 +104,14 @@ class RedirectControllerTest extends TestCase
public function testEmptyPath()
{
$controller = new RedirectController();
$returnResponse = $controller->urlRedirectAction('');
$returnResponse = $controller->urlRedirectAction('', true);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
$this->assertEquals(410, $returnResponse->getStatusCode());
$returnResponse = $controller->urlRedirectAction('', false);
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $returnResponse);
$this->assertEquals(404, $returnResponse->getStatusCode());
}
public function testFullURL()