summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/contrib/sitemaps/tests/test_http.py7
-rw-r--r--django/contrib/sitemaps/views.py11
2 files changed, 18 insertions, 0 deletions
diff --git a/django/contrib/sitemaps/tests/test_http.py b/django/contrib/sitemaps/tests/test_http.py
index 1a91d970f3..a99025e6e2 100644
--- a/django/contrib/sitemaps/tests/test_http.py
+++ b/django/contrib/sitemaps/tests/test_http.py
@@ -144,3 +144,10 @@ class HTTPSitemapTests(SitemapTestsBase):
</sitemapindex>
""" % self.base_url
self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
+
+ def test_x_robots_sitemap(self):
+ response = self.client.get('/simple/index.xml')
+ self.assertEqual(response['X-Robots-Tag'], 'noindex, noodp, noarchive')
+
+ response = self.client.get('/simple/sitemap.xml')
+ self.assertEqual(response['X-Robots-Tag'], 'noindex, noodp, noarchive')
diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
index c8d2f4dfa0..a851f8088a 100644
--- a/django/contrib/sitemaps/views.py
+++ b/django/contrib/sitemaps/views.py
@@ -6,7 +6,17 @@ from django.core.paginator import EmptyPage, PageNotAnInteger
from django.http import Http404
from django.template.response import TemplateResponse
from django.utils import six
+from django.utils.functional import wraps
+def x_robots_tag(func):
+ @wraps(func)
+ def inner(request, *args, **kwargs):
+ response = func(request, *args, **kwargs)
+ response['X-Robots-Tag'] = 'noindex, noodp, noarchive'
+ return response
+ return inner
+
+@x_robots_tag
def index(request, sitemaps,
template_name='sitemap_index.xml', content_type='application/xml',
sitemap_url_name='django.contrib.sitemaps.views.sitemap',
@@ -35,6 +45,7 @@ def index(request, sitemaps,
return TemplateResponse(request, template_name, {'sitemaps': sites},
content_type=content_type)
+@x_robots_tag
def sitemap(request, sitemaps, section=None,
template_name='sitemap.xml', content_type='application/xml',
mimetype=None):