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.
This commit is contained in:
parent
ac9daa0cbd
commit
66c83dce07
|
@ -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')
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue