summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-05-04 12:08:15 +0200
committerClaude Paroz <claude@2xlibre.net>2013-05-04 12:08:15 +0200
commit66c83dce074b48342dbfd0d9039c76b8949f0833 (patch)
tree3766052c71f92a52625efc9c6132471ec4453395
parentac9daa0cbdd82a6b3bcaf0cd5874bd7cdb94fc60 (diff)
Fixed #18351 -- Added X-Robots-Tag header to sitemaps
Thanks Michael Lissner for the report and initial patch, and Tom Mortimer-Jones for working on the patch.
-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):