mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1231 from kinglozzer/pulls/redirectorpage-finished-response
FIX: RedirectorPage_Controller shouldn't attempt redirection if the response is finished (fixes #1230)
This commit is contained in:
commit
284a0f0e13
@ -161,7 +161,8 @@ class RedirectorPage_Controller extends Page_Controller {
|
||||
public function init() {
|
||||
parent::init();
|
||||
|
||||
if($link = $this->redirectionLink()) {
|
||||
// Check we don't already have a redirect code set
|
||||
if(!$this->getResponse()->isFinished() && $link = $this->redirectionLink()) {
|
||||
$this->redirect($link, 301);
|
||||
return;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
class RedirectorPageTest extends FunctionalTest {
|
||||
protected static $fixture_file = 'RedirectorPageTest.yml';
|
||||
protected static $use_draft_site = true;
|
||||
protected $autoFollowRedirection = false;
|
||||
|
||||
public function testGoodRedirectors() {
|
||||
/* For good redirectors, the final destination URL will be returned */
|
||||
@ -50,4 +51,26 @@ class RedirectorPageTest extends FunctionalTest {
|
||||
$page->write();
|
||||
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we can trigger a redirection before RedirectorPage_Controller::init() is called
|
||||
*/
|
||||
public function testRedirectRespectsFinishedResponse() {
|
||||
$page = $this->objFromFixture('RedirectorPage', 'goodinternal');
|
||||
RedirectorPage_Controller::add_extension('RedirectorPageTest_RedirectExtension');
|
||||
|
||||
$response = $this->get($page->regularLink());
|
||||
$this->assertEquals(302, $response->getStatusCode());
|
||||
$this->assertEquals('/foo', $response->getHeader('Location'));
|
||||
|
||||
RedirectorPage_Controller::remove_extension('RedirectorPageTest_RedirectExtension');
|
||||
}
|
||||
}
|
||||
|
||||
class RedirectorPageTest_RedirectExtension extends Extension implements TestOnly {
|
||||
|
||||
public function onBeforeInit() {
|
||||
$this->owner->redirect('/foo');
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user