mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +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() {
|
public function init() {
|
||||||
parent::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);
|
$this->redirect($link, 301);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
class RedirectorPageTest extends FunctionalTest {
|
class RedirectorPageTest extends FunctionalTest {
|
||||||
protected static $fixture_file = 'RedirectorPageTest.yml';
|
protected static $fixture_file = 'RedirectorPageTest.yml';
|
||||||
protected static $use_draft_site = true;
|
protected static $use_draft_site = true;
|
||||||
|
protected $autoFollowRedirection = false;
|
||||||
|
|
||||||
public function testGoodRedirectors() {
|
public function testGoodRedirectors() {
|
||||||
/* For good redirectors, the final destination URL will be returned */
|
/* For good redirectors, the final destination URL will be returned */
|
||||||
@ -50,4 +51,26 @@ class RedirectorPageTest extends FunctionalTest {
|
|||||||
$page->write();
|
$page->write();
|
||||||
$this->assertEquals($page->ExternalURL, 'http://google.com', 'onBeforeWrite will not double prefix if written again!');
|
$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