Commit 64e11a68 authored by Łukasz Langa's avatar Łukasz Langa
Browse files

Fixed #13285: populate_xheaders breaks caching

parent 63a9555d
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
from django.conf import settings
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import get_current_site
from django.core.xheaders import populate_xheaders
from django.http import Http404, HttpResponse, HttpResponsePermanentRedirect
from django.shortcuts import get_object_or_404
from django.template import loader, RequestContext
@@ -70,5 +69,4 @@ def render_flatpage(request, f):
        'flatpage': f,
    })
    response = HttpResponse(t.render(c))
    populate_xheaders(request, response, FlatPage, f.id)
    return response

django/core/xheaders.py

deleted100644 → 0
+0 −24
Original line number Diff line number Diff line
"""
Pages in Django can are served up with custom HTTP headers containing useful
information about those pages -- namely, the content type and object ID.

This module contains utility functions for retrieving and doing interesting
things with these special "X-Headers" (so called because the HTTP spec demands
that custom headers are prefixed with "X-").

Next time you're at slashdot.org, watch out for X-Fry and X-Bender. :)
"""

def populate_xheaders(request, response, model, object_id):
    """
    Adds the "X-Object-Type" and "X-Object-Id" headers to the given
    HttpResponse according to the given model and object_id -- but only if the
    given HttpRequest object has an IP address within the INTERNAL_IPS setting
    or if the request is from a logged in staff member.
    """
    from django.conf import settings
    if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
            or (hasattr(request, 'user') and request.user.is_active
                and request.user.is_staff)):
        response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.model_name)
        response['X-Object-Id'] = str(object_id)
+5 −0
Original line number Diff line number Diff line
@@ -491,6 +491,11 @@ Miscellaneous
  memcache backend no longer uses the default timeout, and now will
  set-and-expire-immediately the value.

* The ``django.contrib.flatpages`` app used to set custom HTTP headers for
  debugging purposes. This functionality was not documented and made caching
  ineffective so it has been removed, along with its generic implementation,
  previously available in ``django.core.xheaders``.

Features deprecated in 1.6
==========================

tests/special_headers/__init__.py

deleted100644 → 0
+0 −0

Empty file deleted.

+0 −20
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
    <object pk="100" model="auth.user">
        <field type="CharField" name="username">super</field>
        <field type="CharField" name="first_name">Super</field>
        <field type="CharField" name="last_name">User</field>
        <field type="CharField" name="email">super@example.com</field>
        <field type="CharField" name="password">sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158</field>
        <field type="BooleanField" name="is_staff">True</field>
        <field type="BooleanField" name="is_active">True</field>
        <field type="BooleanField" name="is_superuser">True</field>
        <field type="DateTimeField" name="last_login">2007-05-30 13:20:10</field>
        <field type="DateTimeField" name="date_joined">2007-05-30 13:20:10</field>
        <field to="auth.group" name="groups" rel="ManyToManyRel"></field>
        <field to="auth.permission" name="user_permissions" rel="ManyToManyRel"></field>
    </object>
    <object pk="1" model="special_headers.article">
        <field type="TextField" name="text">text</field>
    </object>
</django-objects>
Loading