2005-07-13 09:25:57 +08:00
|
|
|
from django.conf import settings
|
2006-05-02 09:31:56 +08:00
|
|
|
from django import http
|
2005-07-13 09:25:57 +08:00
|
|
|
|
2006-06-08 13:00:13 +08:00
|
|
|
class XViewMiddleware(object):
|
2005-07-13 09:25:57 +08:00
|
|
|
"""
|
|
|
|
Adds an X-View header to internal HEAD requests -- used by the documentation system.
|
|
|
|
"""
|
2005-11-28 06:08:51 +08:00
|
|
|
def process_view(self, request, view_func, view_args, view_kwargs):
|
2005-07-13 09:25:57 +08:00
|
|
|
"""
|
2006-09-22 11:17:28 +08:00
|
|
|
If the request method is HEAD and either the IP is internal or the
|
|
|
|
user is a logged-in staff member, quickly return with an x-header
|
|
|
|
indicating the view function. This is used by the documentation module
|
|
|
|
to lookup the view function for an arbitrary page.
|
2005-07-13 09:25:57 +08:00
|
|
|
"""
|
2010-01-10 04:11:01 +08:00
|
|
|
if request.method == 'HEAD' and (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or request.user.is_staff):
|
2006-05-02 09:31:56 +08:00
|
|
|
response = http.HttpResponse()
|
2005-07-13 09:25:57 +08:00
|
|
|
response['X-View'] = "%s.%s" % (view_func.__module__, view_func.__name__)
|
|
|
|
return response
|