add json_body
arg to Request to json-encode body, only return from body
if
not null
This commit is contained in:
parent
9d17710d6d
commit
47735421b8
1 changed files with 8 additions and 4 deletions
|
@ -57,7 +57,7 @@ class Request(object):
|
||||||
get_params: typing.Dict[str, str]={}, post_data: typing.Any=None,
|
get_params: typing.Dict[str, str]={}, post_data: typing.Any=None,
|
||||||
headers: typing.Dict[str, str]={},
|
headers: typing.Dict[str, str]={},
|
||||||
|
|
||||||
json: bool=False, allow_redirects: bool=True,
|
json: bool=False, json_body: bool=False, allow_redirects: bool=True,
|
||||||
check_content_type: bool=True, parse: bool=False,
|
check_content_type: bool=True, parse: bool=False,
|
||||||
detect_encoding: bool=True,
|
detect_encoding: bool=True,
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ class Request(object):
|
||||||
self.headers = headers
|
self.headers = headers
|
||||||
|
|
||||||
self.json = json
|
self.json = json
|
||||||
|
self.json_body = json_body
|
||||||
self.allow_redirects = allow_redirects
|
self.allow_redirects = allow_redirects
|
||||||
self.check_content_type = check_content_type
|
self.check_content_type = check_content_type
|
||||||
self.parse = parse
|
self.parse = parse
|
||||||
|
@ -105,10 +106,13 @@ class Request(object):
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
def get_body(self) -> typing.Any:
|
def get_body(self) -> typing.Any:
|
||||||
if self.content_type == "application/json":
|
if not self.post_data == None:
|
||||||
return _json.dumps(self.post_data)
|
if self.content_type == "application/json" or self.json_body:
|
||||||
|
return _json.dumps(self.post_data)
|
||||||
|
else:
|
||||||
|
return self.post_data
|
||||||
else:
|
else:
|
||||||
return self.post_data
|
return None
|
||||||
|
|
||||||
class Response(object):
|
class Response(object):
|
||||||
def __init__(self, code: int, data: typing.Any,
|
def __init__(self, code: int, data: typing.Any,
|
||||||
|
|
Loading…
Reference in a new issue