aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-01 13:15:33 +0100
committerAymeric Augustin2013-11-01 13:15:33 +0100
commit842ed8a0e9d4e4ccadd6114147f8e2805b0a251c (patch)
treeaf63355537002c1137b9baa37106611bc195cfdd
parent6c88b70d95c094c22e13e656e29fd7cddf40df64 (diff)
downloaddjango-debug-toolbar-842ed8a0e9d4e4ccadd6114147f8e2805b0a251c.tar.bz2
Show all HTTP headers in the headers panel.
Show a relevant subset of the WSGI environ separately. Fix #62.
-rw-r--r--debug_toolbar/panels/headers.py47
-rw-r--r--debug_toolbar/templates/debug_toolbar/panels/headers.html24
2 files changed, 52 insertions, 19 deletions
diff --git a/debug_toolbar/panels/headers.py b/debug_toolbar/panels/headers.py
index 4a10b5f..de47c0e 100644
--- a/debug_toolbar/panels/headers.py
+++ b/debug_toolbar/panels/headers.py
@@ -1,5 +1,9 @@
from __future__ import unicode_literals
+try:
+ from collections import OrderedDict
+except ImportError:
+ from django.utils.datastructures import SortedDict as OrderedDict
from django.utils.translation import ugettext_lazy as _
from debug_toolbar.panels import DebugPanel
@@ -11,20 +15,15 @@ class HeaderDebugPanel(DebugPanel):
name = 'Header'
template = 'debug_toolbar/panels/headers.html'
has_content = True
- # List of headers we want to display
- header_filter = (
+ # List of environment variables we want to display
+ environ_filter = set((
+ 'CONTENT_LENGTH',
'CONTENT_TYPE',
- 'HTTP_ACCEPT',
- 'HTTP_ACCEPT_CHARSET',
- 'HTTP_ACCEPT_ENCODING',
- 'HTTP_ACCEPT_LANGUAGE',
- 'HTTP_CACHE_CONTROL',
- 'HTTP_CONNECTION',
- 'HTTP_HOST',
- 'HTTP_KEEP_ALIVE',
- 'HTTP_REFERER',
- 'HTTP_USER_AGENT',
+ 'DJANGO_SETTINGS_MODULE',
+ 'GATEWAY_INTERFACE',
'QUERY_STRING',
+ 'PATH_INFO',
+ 'PYTHONPATH',
'REMOTE_ADDR',
'REMOTE_HOST',
'REQUEST_METHOD',
@@ -33,23 +32,33 @@ class HeaderDebugPanel(DebugPanel):
'SERVER_PORT',
'SERVER_PROTOCOL',
'SERVER_SOFTWARE',
- )
+ 'TZ',
+ ))
def nav_title(self):
- return _('HTTP Headers')
+ return _('Headers')
def title(self):
- return _('HTTP Headers')
+ return _('Headers')
def url(self):
return ''
def process_request(self, request):
- self.headers = dict(
- [(k, request.META[k]) for k in self.header_filter if k in request.META]
- )
+ wsgi_env = list(sorted(request.META.items()))
+ self.headers = OrderedDict(
+ (unmangle(k), v) for (k, v) in wsgi_env if k.startswith('HTTP_'))
+ if 'Cookie' in self.headers:
+ self.headers['Cookie'] = '<< see Request Vars panel >>'
+ self.environ = OrderedDict(
+ (k, v) for (k, v) in wsgi_env if k in self.environ_filter)
def process_response(self, request, response):
self.record_stats({
- 'headers': self.headers
+ 'headers': self.headers,
+ 'environ': self.environ,
})
+
+
+def unmangle(wsgi_key):
+ return wsgi_key[5:].replace('_', '-').title()
diff --git a/debug_toolbar/templates/debug_toolbar/panels/headers.html b/debug_toolbar/templates/debug_toolbar/panels/headers.html
index 981b847..6b057e9 100644
--- a/debug_toolbar/templates/debug_toolbar/panels/headers.html
+++ b/debug_toolbar/templates/debug_toolbar/panels/headers.html
@@ -1,4 +1,7 @@
{% load i18n %}
+
+<h4>{% trans "HTTP Headers" %}</h4>
+
<table>
<thead>
<tr>
@@ -15,3 +18,24 @@
{% endfor %}
</tbody>
</table>
+
+<h4>{% trans "WSGI environ" %}</h4>
+
+<p>{% trans "Since the WSGI environ inherits the environment of the server, only a subset is shown below." %}</p>
+
+<table>
+ <thead>
+ <tr>
+ <th>{% trans "Key" %}</th>
+ <th>{% trans "Value" %}</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for key, value in environ.items %}
+ <tr class="{% cycle 'djDebugOdd' 'djDebugEven' %}">
+ <td>{{ key|escape }}</td>
+ <td>{{ value|escape }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+</table>