Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13285: populate_xheaders breaks caching

  • Loading branch information...
commit 64e11a68f19793d11915e83574b1bb693da3980e 1 parent 63a9555
Łukasz Langa authored May 18, 2013
2  django/contrib/flatpages/views.py
... ...
@@ -1,7 +1,6 @@
1 1
 from django.conf import settings
2 2
 from django.contrib.flatpages.models import FlatPage
3 3
 from django.contrib.sites.models import get_current_site
4  
-from django.core.xheaders import populate_xheaders
5 4
 from django.http import Http404, HttpResponse, HttpResponsePermanentRedirect
6 5
 from django.shortcuts import get_object_or_404
7 6
 from django.template import loader, RequestContext
@@ -70,5 +69,4 @@ def render_flatpage(request, f):
70 69
         'flatpage': f,
71 70
     })
72 71
     response = HttpResponse(t.render(c))
73  
-    populate_xheaders(request, response, FlatPage, f.id)
74 72
     return response
24  django/core/xheaders.py
... ...
@@ -1,24 +0,0 @@
1  
-"""
2  
-Pages in Django can are served up with custom HTTP headers containing useful
3  
-information about those pages -- namely, the content type and object ID.
4  
-
5  
-This module contains utility functions for retrieving and doing interesting
6  
-things with these special "X-Headers" (so called because the HTTP spec demands
7  
-that custom headers are prefixed with "X-").
8  
-
9  
-Next time you're at slashdot.org, watch out for X-Fry and X-Bender. :)
10  
-"""
11  
-
12  
-def populate_xheaders(request, response, model, object_id):
13  
-    """
14  
-    Adds the "X-Object-Type" and "X-Object-Id" headers to the given
15  
-    HttpResponse according to the given model and object_id -- but only if the
16  
-    given HttpRequest object has an IP address within the INTERNAL_IPS setting
17  
-    or if the request is from a logged in staff member.
18  
-    """
19  
-    from django.conf import settings
20  
-    if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
21  
-            or (hasattr(request, 'user') and request.user.is_active
22  
-                and request.user.is_staff)):
23  
-        response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.model_name)
24  
-        response['X-Object-Id'] = str(object_id)
5  docs/releases/1.6.txt
@@ -491,6 +491,11 @@ Miscellaneous
491 491
   memcache backend no longer uses the default timeout, and now will
492 492
   set-and-expire-immediately the value.
493 493
 
  494
+* The ``django.contrib.flatpages`` app used to set custom HTTP headers for
  495
+  debugging purposes. This functionality was not documented and made caching
  496
+  ineffective so it has been removed, along with its generic implementation,
  497
+  previously available in ``django.core.xheaders``.
  498
+
494 499
 Features deprecated in 1.6
495 500
 ==========================
496 501
 
0  tests/special_headers/__init__.py
No changes.
20  tests/special_headers/fixtures/data.xml
... ...
@@ -1,20 +0,0 @@
1  
-<?xml version="1.0" encoding="utf-8"?>
2  
-<django-objects version="1.0">
3  
-    <object pk="100" model="auth.user">
4  
-        <field type="CharField" name="username">super</field>
5  
-        <field type="CharField" name="first_name">Super</field>
6  
-        <field type="CharField" name="last_name">User</field>
7  
-        <field type="CharField" name="email">super@example.com</field>
8  
-        <field type="CharField" name="password">sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158</field>
9  
-        <field type="BooleanField" name="is_staff">True</field>
10  
-        <field type="BooleanField" name="is_active">True</field>
11  
-        <field type="BooleanField" name="is_superuser">True</field>
12  
-        <field type="DateTimeField" name="last_login">2007-05-30 13:20:10</field>
13  
-        <field type="DateTimeField" name="date_joined">2007-05-30 13:20:10</field>
14  
-        <field to="auth.group" name="groups" rel="ManyToManyRel"></field>
15  
-        <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
16  
-    </object>
17  
-    <object pk="1" model="special_headers.article">
18  
-        <field type="TextField" name="text">text</field>
19  
-    </object>
20  
-</django-objects>
5  tests/special_headers/models.py
... ...
@@ -1,5 +0,0 @@
1  
-from django.db import models
2  
-
3  
-
4  
-class Article(models.Model):
5  
-    text = models.TextField()
1  tests/special_headers/templates/special_headers/article_detail.html
... ...
@@ -1 +0,0 @@
1  
-{{ object }}
62  tests/special_headers/tests.py
... ...
@@ -1,62 +0,0 @@
1  
-from django.contrib.auth.models import User
2  
-from django.test import TestCase
3  
-from django.test.utils import override_settings
4  
-
5  
-
6  
-@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
7  
-class SpecialHeadersTest(TestCase):
8  
-    fixtures = ['data.xml']
9  
-    urls = 'special_headers.urls'
10  
-
11  
-    def test_xheaders(self):
12  
-        user = User.objects.get(username='super')
13  
-        response = self.client.get('/special_headers/article/1/')
14  
-        self.assertFalse('X-Object-Type' in response)
15  
-        self.client.login(username='super', password='secret')
16  
-        response = self.client.get('/special_headers/article/1/')
17  
-        self.assertTrue('X-Object-Type' in response)
18  
-        user.is_staff = False
19  
-        user.save()
20  
-        response = self.client.get('/special_headers/article/1/')
21  
-        self.assertFalse('X-Object-Type' in response)
22  
-        user.is_staff = True
23  
-        user.is_active = False
24  
-        user.save()
25  
-        response = self.client.get('/special_headers/article/1/')
26  
-        self.assertFalse('X-Object-Type' in response)
27  
-
28  
-    def test_xview_func(self):
29  
-        user = User.objects.get(username='super')
30  
-        response = self.client.head('/special_headers/xview/func/')
31  
-        self.assertFalse('X-View' in response)
32  
-        self.client.login(username='super', password='secret')
33  
-        response = self.client.head('/special_headers/xview/func/')
34  
-        self.assertTrue('X-View' in response)
35  
-        self.assertEqual(response['X-View'], 'special_headers.views.xview')
36  
-        user.is_staff = False
37  
-        user.save()
38  
-        response = self.client.head('/special_headers/xview/func/')
39  
-        self.assertFalse('X-View' in response)
40  
-        user.is_staff = True
41  
-        user.is_active = False
42  
-        user.save()
43  
-        response = self.client.head('/special_headers/xview/func/')
44  
-        self.assertFalse('X-View' in response)
45  
-
46  
-    def test_xview_class(self):
47  
-        user = User.objects.get(username='super')
48  
-        response = self.client.head('/special_headers/xview/class/')
49  
-        self.assertFalse('X-View' in response)
50  
-        self.client.login(username='super', password='secret')
51  
-        response = self.client.head('/special_headers/xview/class/')
52  
-        self.assertTrue('X-View' in response)
53  
-        self.assertEqual(response['X-View'], 'special_headers.views.XViewClass')
54  
-        user.is_staff = False
55  
-        user.save()
56  
-        response = self.client.head('/special_headers/xview/class/')
57  
-        self.assertFalse('X-View' in response)
58  
-        user.is_staff = True
59  
-        user.is_active = False
60  
-        user.save()
61  
-        response = self.client.head('/special_headers/xview/class/')
62  
-        self.assertFalse('X-View' in response)
13  tests/special_headers/urls.py
... ...
@@ -1,13 +0,0 @@
1  
-# coding: utf-8
2  
-from __future__ import absolute_import
3  
-
4  
-from django.conf.urls import patterns
5  
-
6  
-from . import views
7  
-from .models import Article
8  
-
9  
-urlpatterns = patterns('',
10  
-    (r'^special_headers/article/(?P<object_id>\d+)/$', views.xview_xheaders),
11  
-    (r'^special_headers/xview/func/$', views.xview_dec(views.xview)),
12  
-    (r'^special_headers/xview/class/$', views.xview_dec(views.XViewClass.as_view())),
13  
-)
21  tests/special_headers/views.py
... ...
@@ -1,21 +0,0 @@
1  
-from django.core.xheaders import populate_xheaders
2  
-from django.http import HttpResponse
3  
-from django.utils.decorators import decorator_from_middleware
4  
-from django.views.generic import View
5  
-from django.middleware.doc import XViewMiddleware
6  
-
7  
-from .models import Article
8  
-
9  
-xview_dec = decorator_from_middleware(XViewMiddleware)
10  
-
11  
-def xview(request):
12  
-    return HttpResponse()
13  
-
14  
-def xview_xheaders(request, object_id):
15  
-    response = HttpResponse()
16  
-    populate_xheaders(request, response, Article, 1)
17  
-    return response
18  
-
19  
-class XViewClass(View):
20  
-    def get(self, request):
21  
-        return HttpResponse()

0 notes on commit 64e11a6

Please sign in to comment.
Something went wrong with that request. Please try again.