Skip to content

Commit

Permalink
Support Django Channels' AsgiRequest (#272)
Browse files Browse the repository at this point in the history
* Use request.META to extract Django request headers.  This makes rollbar compatible with Django Channels' AsgiRequest in addition to the standard WSGIRequest.

* Fix incompatibility with Python 3.x
  • Loading branch information
svvitale authored and rokob committed Jun 20, 2018
1 parent b015f4a commit 9d75f59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions rollbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,10 +1126,10 @@ def _build_django_request_data(request):
'method': request.method,
'GET': dict(request.GET),
'POST': dict(request.POST),
'user_ip': _wsgi_extract_user_ip(request.environ),
'user_ip': _wsgi_extract_user_ip(request.META),
}

request_data['headers'] = _extract_wsgi_headers(request.environ.items())
request_data['headers'] = _extract_wsgi_headers(request.META.items())

return request_data

Expand Down
3 changes: 2 additions & 1 deletion rollbar/contrib/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def get_payload_data(self, request, exc):
from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
from django.http import Http404
from six import reraise

try:
from django.urls import resolve
Expand Down Expand Up @@ -292,7 +293,7 @@ def process_response(self, request, response):
try:
if hasattr(request, '_rollbar_notifier_original_http404_exc_info'):
exc_type, exc_value, exc_traceback = request._rollbar_notifier_original_http404_exc_info
raise exc_type, exc_value, exc_traceback
reraise(exc_type, exc_value, exc_traceback)
else:
raise Http404()
except Exception as exc:
Expand Down

0 comments on commit 9d75f59

Please sign in to comment.