aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-25 09:48:47 +0100
committerAymeric Augustin2013-11-25 09:48:47 +0100
commit6f4f72988bddf1ff73b89dd6abc55602671d1d55 (patch)
treef45ebaa2bcdd3c3c32cd6d26bd8c04e8fbf8cc7f
parent837efabd5457e5bbce04780785e172da21a6c3db (diff)
downloaddjango-debug-toolbar-6f4f72988bddf1ff73b89dd6abc55602671d1d55.tar.bz2
Support non-str keys in request.META.
Fix #482.
-rw-r--r--debug_toolbar/panels/headers.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/debug_toolbar/panels/headers.py b/debug_toolbar/panels/headers.py
index 0138299..265ec6b 100644
--- a/debug_toolbar/panels/headers.py
+++ b/debug_toolbar/panels/headers.py
@@ -39,7 +39,7 @@ class HeadersPanel(Panel):
def process_request(self, request):
wsgi_env = list(sorted(request.META.items()))
self.request_headers = OrderedDict(
- (unmangle(k), v) for (k, v) in wsgi_env if k.startswith('HTTP_'))
+ (unmangle(k), v) for (k, v) in wsgi_env if is_http_header(k))
if 'Cookie' in self.request_headers:
self.request_headers['Cookie'] = '=> see Request panel'
self.environ = OrderedDict(
@@ -56,5 +56,11 @@ class HeadersPanel(Panel):
})
+def is_http_header(wsgi_key):
+ # The WSGI spec says that keys should be str objects in the environ dict,
+ # but this isn't true in practice. See issues #449 and #482.
+ return isinstance(wsgi_key, str) and wsgi_key.startswith('HTTP_')
+
+
def unmangle(wsgi_key):
return wsgi_key[5:].replace('_', '-').title()