Skip to content

Commit 4326cbb

Browse files
committed
Factor headers data out of HeaderDebugPanel.
1 parent edf74be commit 4326cbb

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

debug_toolbar/debug/headers.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class DebugHeaders(object):
2+
3+
# List of headers we want to display
4+
header_filter = (
5+
'CONTENT_TYPE',
6+
'HTTP_ACCEPT',
7+
'HTTP_ACCEPT_CHARSET',
8+
'HTTP_ACCEPT_ENCODING',
9+
'HTTP_ACCEPT_LANGUAGE',
10+
'HTTP_CACHE_CONTROL',
11+
'HTTP_CONNECTION',
12+
'HTTP_HOST',
13+
'HTTP_KEEP_ALIVE',
14+
'HTTP_REFERER',
15+
'HTTP_USER_AGENT',
16+
'QUERY_STRING',
17+
'REMOTE_ADDR',
18+
'REMOTE_HOST',
19+
'REQUEST_METHOD',
20+
'SCRIPT_NAME',
21+
'SERVER_NAME',
22+
'SERVER_PORT',
23+
'SERVER_PROTOCOL',
24+
'SERVER_SOFTWARE',
25+
)
26+
27+
def available_headers(self, request):
28+
return dict(
29+
[(k, request.META[k]) for k in self.header_filter if k in request.META]
30+
)

debug_toolbar/panels/headers.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
11
from django.template.loader import render_to_string
22
from django.utils.translation import ugettext_lazy as _
33
from debug_toolbar.panels import DebugPanel
4+
from debug_toolbar.debug.headers import DebugHeaders
45

56
class HeaderDebugPanel(DebugPanel):
67
"""
78
A panel to display HTTP headers.
89
"""
910
name = 'Header'
1011
has_content = True
11-
# List of headers we want to display
12-
header_filter = (
13-
'CONTENT_TYPE',
14-
'HTTP_ACCEPT',
15-
'HTTP_ACCEPT_CHARSET',
16-
'HTTP_ACCEPT_ENCODING',
17-
'HTTP_ACCEPT_LANGUAGE',
18-
'HTTP_CACHE_CONTROL',
19-
'HTTP_CONNECTION',
20-
'HTTP_HOST',
21-
'HTTP_KEEP_ALIVE',
22-
'HTTP_REFERER',
23-
'HTTP_USER_AGENT',
24-
'QUERY_STRING',
25-
'REMOTE_ADDR',
26-
'REMOTE_HOST',
27-
'REQUEST_METHOD',
28-
'SCRIPT_NAME',
29-
'SERVER_NAME',
30-
'SERVER_PORT',
31-
'SERVER_PROTOCOL',
32-
'SERVER_SOFTWARE',
33-
)
12+
13+
def __init__(self, context={}):
14+
super(HeaderDebugPanel, self).__init__(context)
15+
self.debug_headers = DebugHeaders()
3416

3517
def nav_title(self):
3618
return _('HTTP Headers')
@@ -41,14 +23,13 @@ def title(self):
4123
def url(self):
4224
return ''
4325

44-
def process_request(self, request):
45-
self.headers = dict(
46-
[(k, request.META[k]) for k in self.header_filter if k in request.META]
47-
)
48-
4926
def content(self):
5027
context = self.context.copy()
5128
context.update({
5229
'headers': self.headers
5330
})
5431
return render_to_string('debug_toolbar/panels/headers.html', context)
32+
33+
def process_request(self, request):
34+
self.headers = self.debug_headers.available_headers(request)
35+

0 commit comments

Comments
 (0)