17139: do not send default cache header for 301 redirects
This commit is contained in:
parent
83ebf97df3
commit
cf253a917d
@ -41,6 +41,10 @@ class RedirectResponse extends Response
|
|||||||
if (!$this->isRedirect()) {
|
if (!$this->isRedirect()) {
|
||||||
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
|
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (301 == $status && !array_key_exists('cache-control', $headers)) {
|
||||||
|
$this->headers->remove('cache-control');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,4 +80,17 @@ class RedirectResponseTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
|
||||||
$this->assertEquals(301, $response->getStatusCode());
|
$this->assertEquals(301, $response->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCacheHeaders()
|
||||||
|
{
|
||||||
|
$response = new RedirectResponse('foo.bar', 301);
|
||||||
|
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
|
||||||
|
|
||||||
|
$response = new RedirectResponse('foo.bar', 301, array('cache-control' => 'max-age=86400'));
|
||||||
|
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
|
||||||
|
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));
|
||||||
|
|
||||||
|
$response = new RedirectResponse('foo.bar', 302);
|
||||||
|
$this->assertTrue($response->headers->hasCacheControlDirective('no-cache'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user