Do not send the header if it is not defined

This commit is contained in:
Robbie Averill 2017-01-11 08:26:04 +13:00
parent cb2dcc75f1
commit 2f6f5b5eff
2 changed files with 10 additions and 1 deletions

View File

@ -336,7 +336,9 @@ class Security extends Controller implements TemplateGlobalProvider {
$this->getResponse()->addHeader('X-Frame-Options', $this->config()->frame_options);
// Prevent search engines from indexing the login page
$this->getResponse()->addHeader('X-Robots-Tag', $this->config()->robots_tag);
if ($this->config()->robots_tag) {
$this->getResponse()->addHeader('X-Robots-Tag', $this->config()->robots_tag);
}
}
public function index() {

View File

@ -581,6 +581,13 @@ class SecurityTest extends FunctionalTest {
$this->assertContains('noindex', $robotsHeader);
}
public function testDoNotSendEmptyRobotsHeaderIfNotDefined() {
Config::inst()->update('Security', 'robots_tag', null);
$response = $this->get(Config::inst()->get('Security', 'login_url'));
$robotsHeader = $response->getHeader('X-Robots-Tag');
$this->assertNull($robotsHeader);
}
/**
* Execute a log-in form using Director::test().
* Helper method for the tests above