make method instead of property for alternative json decoding of request
This commit is contained in:
parent
1d719252cb
commit
a8f764c161
|
@ -69,10 +69,10 @@ class Request(dict):
|
|||
self.stream = None
|
||||
|
||||
@property
|
||||
def json(self, loads=json_loads):
|
||||
def json(self):
|
||||
if self.parsed_json is None:
|
||||
try:
|
||||
self.parsed_json = loads(self.body)
|
||||
self.parsed_json = json_loads(self.body)
|
||||
except Exception:
|
||||
if not self.body:
|
||||
return None
|
||||
|
@ -80,6 +80,16 @@ class Request(dict):
|
|||
|
||||
return self.parsed_json
|
||||
|
||||
def load_json(self, loads=json_loads):
|
||||
try:
|
||||
self.parsed_json = loads(self.body)
|
||||
except Exception:
|
||||
if not self.body:
|
||||
return None
|
||||
raise InvalidUsage("Failed when parsing body as json")
|
||||
|
||||
return self.parsed_json
|
||||
|
||||
@property
|
||||
def token(self):
|
||||
"""Attempt to return the auth header token.
|
||||
|
|
Loading…
Reference in New Issue
Block a user