Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer response headers processing to a finished callback #310

Merged
merged 4 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
unreleased
----------
- Headers panel defers its processing to a finished callback. This is best
effort of displaying actual headers, since they could be modified by
a response callback or another finished callback.
See https://github.com/Pylons/pyramid_debugtoolbar/pull/310

- Debug squashed exceptions! If you register an exception view for an exception
it will render a response. The toolbar will see the squashed exception and
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ Contributors
- Kashif Iftikhar, 2016-07-01
- Dan Clark, 2017-05-22
- Jens Carl, 2017-05-22
- Andrey Tretyakov, 2017-05-27
17 changes: 15 additions & 2 deletions pyramid_debugtoolbar/panels/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@ class HeaderDebugPanel(DebugPanel):
nav_title = title

def __init__(self, request):
self.request = request
self.request_headers = [
(text_(k), text_(v)) for k, v in sorted(request.headers.items())
]

def process_response(self, response):
def finished_callback(request):
self.process_response_deferred(response)

def prepare_finished_callback(request):
""" Best effort to be the last in case there are other callbacks
mutating the response """
self.request.add_finished_callback(finished_callback)

self.request.add_finished_callback(prepare_finished_callback)
self.data = {'request_headers': self.request_headers,
'response_headers': []}

def process_response_deferred(self, response):
response_headers = [
(text_(k), text_(v)) for k, v in sorted(response.headerlist)
]
self.data = {'request_headers': self.request_headers,
'response_headers': response_headers}
self.data['response_headers'] = response_headers

def includeme(config):
config.add_debugtoolbar_panel(HeaderDebugPanel)