archive
/
lantern
Archived
1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
lantern/lantern/request.py

21 lines
449 B
Python

from sanic.exceptions import InvalidUsage
SERIALIZE_ATTRS = [
'args',
'form',
'url',
'ip',
'query_string'
]
def serialize_request(request):
serialized = {key: getattr(request, key) for key in SERIALIZE_ATTRS}
try:
serialized['json'] = request.json
except InvalidUsage: # if there's no body, we cant add it
pass
serialized['user_agent'] = request['user_agent'].to_dict()
return serialized