mirror of
https://github.com/pallets-eco/flask-debugtoolbar.git
synced 2026-01-07 22:19:47 -06:00
Add the headers panel
This commit is contained in:
56
flaskext/debugtoolbar/panels/headers.py
Normal file
56
flaskext/debugtoolbar/panels/headers.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from flaskext.debugtoolbar.panels import DebugPanel
|
||||
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
class HeaderDebugPanel(DebugPanel):
|
||||
"""
|
||||
A panel to display HTTP headers.
|
||||
"""
|
||||
name = 'Header'
|
||||
has_content = True
|
||||
# List of headers we want to display
|
||||
header_filter = (
|
||||
'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',
|
||||
'QUERY_STRING',
|
||||
'REMOTE_ADDR',
|
||||
'REMOTE_HOST',
|
||||
'REQUEST_METHOD',
|
||||
'SCRIPT_NAME',
|
||||
'SERVER_NAME',
|
||||
'SERVER_PORT',
|
||||
'SERVER_PROTOCOL',
|
||||
'SERVER_SOFTWARE',
|
||||
)
|
||||
|
||||
def nav_title(self):
|
||||
return _('HTTP Headers')
|
||||
|
||||
def title(self):
|
||||
return _('HTTP Headers')
|
||||
|
||||
def url(self):
|
||||
return ''
|
||||
|
||||
def process_request(self, request):
|
||||
self.headers = dict(
|
||||
[(k, request.environ[k])
|
||||
for k in self.header_filter if k in request.environ]
|
||||
)
|
||||
|
||||
def content(self):
|
||||
context = self.context.copy()
|
||||
context.update({
|
||||
'headers': self.headers
|
||||
})
|
||||
return self.render('panels/headers.html', context)
|
||||
16
flaskext/debugtoolbar/templates/panels/headers.html
Normal file
16
flaskext/debugtoolbar/templates/panels/headers.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for key, value in headers.iteritems() %}
|
||||
<tr class="{{ loop.cycle('djDebugOdd' 'djDebugEven') }}">
|
||||
<td>{{ key|escape }}</td>
|
||||
<td>{{ value|escape }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -12,6 +12,7 @@ class DebugToolbar(object):
|
||||
|
||||
self.default_panels = [
|
||||
'flaskext.debugtoolbar.panels.timer.TimerDebugPanel',
|
||||
'flaskext.debugtoolbar.panels.headers.HeaderDebugPanel',
|
||||
'flaskext.debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
|
||||
'flaskext.debugtoolbar.panels.logger.LoggingPanel',
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user