]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix robots "noindex, nofollow" signals 21412/head
authorJoas Schilling <coding@schilljs.com>
Mon, 15 Jun 2020 11:50:30 +0000 (13:50 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 25 Jun 2020 06:29:43 +0000 (08:29 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/public/AppFramework/Http/Response.php
lib/public/AppFramework/Http/TemplateResponse.php
tests/lib/AppFramework/Controller/ControllerTest.php
tests/lib/AppFramework/Http/DataResponseTest.php
tests/lib/AppFramework/Http/ResponseTest.php

index 832e0b9624700a72fd149419a15940d910b18ef9..c26ea4ce400ae089c4293f76c2a7208adfd93d2b 100644 (file)
@@ -239,6 +239,7 @@ class Response {
 
                $this->headers['Content-Security-Policy'] = $this->getContentSecurityPolicy()->buildPolicy();
                $this->headers['Feature-Policy'] = $this->getFeaturePolicy()->buildPolicy();
+               $this->headers['X-Robots-Tag'] = 'none';
 
                if ($this->ETag) {
                        $mergeWith['ETag'] = '"' . $this->ETag . '"';
index d6c4006433cfccba250523b6c77caed712e20ab0..bc86c153b7592de606ed3f2ddd70b075bd15a2f5 100644 (file)
@@ -157,6 +157,7 @@ class TemplateResponse extends Response {
                // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
                $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs;
 
+               \OCP\Util::addHeader('meta', ['name' => 'robots', 'content' => 'noindex, nofollow']);
                $template = new \OCP\Template($this->appName, $this->templateName, $renderAs);
 
                foreach ($this->params as $key => $value) {
index e07089e0c82a0c61e0ac89415ae5b4c3044ae68b..7c5b19315123aa72a5d113a7f656622471698b68 100644 (file)
@@ -92,7 +92,7 @@ class ControllerTest extends \Test\TestCase {
                $this->controller = new ChildController($this->app, $request);
        }
 
-       
+
        public function testFormatResonseInvalidFormat() {
                $this->expectException(\DomainException::class);
 
@@ -114,6 +114,7 @@ class ControllerTest extends \Test\TestCase {
                        'Content-Type' => 'application/json; charset=utf-8',
                        'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self'",
                        'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
+                       'X-Robots-Tag' => 'none',
                ];
 
                $response = $this->controller->customDataResponse(['hi']);
index e7624c92d7e672f09654f255975630f4355f1546..a02cee67d317f09eae1f37c7ff55f5c5b71a222b 100644 (file)
@@ -67,6 +67,7 @@ class DataResponseTest extends \Test\TestCase {
                        'Cache-Control' => 'no-cache, no-store, must-revalidate',
                        'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self'",
                        'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
+                       'X-Robots-Tag' => 'none',
                ];
                $expectedHeaders = array_merge($expectedHeaders, $headers);
 
index dd82809dd851a29938017fff41046bcf4ede320f..7a064908869cb3e6ce8ba25d5df832cd94d4696a 100644 (file)
@@ -51,7 +51,8 @@ class ResponseTest extends \Test\TestCase {
                $expected = [
                        'Last-Modified' => 1,
                        'ETag' => 3,
-                       'Something-Else' => 'hi'
+                       'Something-Else' => 'hi',
+                       'X-Robots-Tag' => 'none',
                ];
 
                $this->childResponse->setHeaders($expected);
@@ -90,7 +91,7 @@ class ResponseTest extends \Test\TestCase {
        public function testAddHeaderValueNullDeletesIt() {
                $this->childResponse->addHeader('hello', 'world');
                $this->childResponse->addHeader('hello', null);
-               $this->assertEquals(3, count($this->childResponse->getHeaders()));
+               $this->assertEquals(4, count($this->childResponse->getHeaders()));
        }