Skip to content

Commit

Permalink
Add support for Falcon framework requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rhcarvalho committed Feb 18, 2015
1 parent 2e9b8bb commit 84b04ca
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions rollbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
except ImportError:
BottleRequest = None

try:
from falcon import Request as FalconRequest
except ImportError:
FalconRequest = None

try:
from tornado.gen import coroutine as tornado_coroutine
from tornado.httpclient import AsyncHTTPClient as TornadoAsyncHTTPClient
Expand Down Expand Up @@ -796,6 +801,10 @@ def _build_request_data(request):
if BottleRequest and isinstance(request, BottleRequest):
return _build_bottle_request_data(request)

# falcon
if FalconRequest and isinstance(request, FalconRequest):
return _build_falcon_request_data(request)

return None


Expand Down Expand Up @@ -997,6 +1006,18 @@ def _build_bottle_request_data(request):

return request_data

def _build_falcon_request_data(request):
request_data = {
'url': request.url,
'user_ip': _wsgi_extract_user_ip(request.env),
'headers': dict(request.headers),
'method': request.method,
'GET': dict(request.params),
'context': dict(request.context),
}

return request_data

def _build_server_data():
"""
Returns a dictionary containing information about the server environment.
Expand Down Expand Up @@ -1137,13 +1158,17 @@ def _extract_user_ip(request):


def _django_extract_user_ip(request):
forwarded_for = request.environ.get('HTTP_X_FORWARDED_FOR')
return _wsgi_extract_user_ip(request.environ)


def _wsgi_extract_user_ip(wsgi_environment):
forwarded_for = wsgi_environment.get('HTTP_X_FORWARDED_FOR')
if forwarded_for:
return forwarded_for
real_ip = request.environ.get('HTTP_X_REAL_IP')
real_ip = wsgi_environment.get('HTTP_X_REAL_IP')
if real_ip:
return real_ip
return request.environ['REMOTE_ADDR']
return wsgi_environment['REMOTE_ADDR']


# http://www.xormedia.com/recursively-merge-dictionaries-in-python.html
Expand Down

0 comments on commit 84b04ca

Please sign in to comment.