Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Maxime Alves LIRMM | 998350cd89 |
|
@ -56,11 +56,24 @@ def args_check(fct):
|
||||||
data_ = dict(req.query_params)
|
data_ = dict(req.query_params)
|
||||||
|
|
||||||
elif req.method in ['POST', 'PATCH', 'PUT', 'DELETE']:
|
elif req.method in ['POST', 'PATCH', 'PUT', 'DELETE']:
|
||||||
try:
|
if req.scope.get('headers'):
|
||||||
data_ = await req.json()
|
if b'content-type' not in dict(req.scope.get('headers')):
|
||||||
except JSONDecodeError as exc:
|
data_ = {}
|
||||||
logger.debug('Posted data was not JSON')
|
else:
|
||||||
pass
|
content_type = dict(req.scope.get('headers')).get(b'content-type').decode().split(';')[0]
|
||||||
|
|
||||||
|
if content_type == 'application/json':
|
||||||
|
try:
|
||||||
|
data_ = await req.json()
|
||||||
|
except JSONDecodeError as exc:
|
||||||
|
logger.debug('Posted data was not JSON')
|
||||||
|
pass
|
||||||
|
elif content_type in [
|
||||||
|
'multipart/form-data', 'application/x-www-form-urlencoded']:
|
||||||
|
data_ = await req.form()
|
||||||
|
else:
|
||||||
|
data_ = await req.body()
|
||||||
|
|
||||||
|
|
||||||
def plural(array: list) -> str:
|
def plural(array: list) -> str:
|
||||||
return 's' if len(array) > 1 else ''
|
return 's' if len(array) > 1 else ''
|
||||||
|
@ -69,7 +82,7 @@ def args_check(fct):
|
||||||
|
|
||||||
|
|
||||||
args_d = req.scope.get('args')
|
args_d = req.scope.get('args')
|
||||||
if args_d is not None:
|
if args_d is not None and isinstance(data_, dict):
|
||||||
required = args_d.get('required', set())
|
required = args_d.get('required', set())
|
||||||
|
|
||||||
missing = []
|
missing = []
|
||||||
|
@ -90,7 +103,7 @@ def args_check(fct):
|
||||||
if key in data_:
|
if key in data_:
|
||||||
data[key] = data_[key]
|
data[key] = data_[key]
|
||||||
else:
|
else:
|
||||||
""" Unsafe mode, without specified arguments
|
""" Unsafe mode, without specified arguments, or plain text mode
|
||||||
"""
|
"""
|
||||||
data = data_
|
data = data_
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue