diff options
| author | 2019-09-16 10:57:18 +0100 | |
|---|---|---|
| committer | 2019-09-16 10:57:18 +0100 | |
| commit | 47735421b806f18ca07cba0a03c6e7077869fa97 (patch) | |
| tree | 6e3ba8512c5335c23ad5a78f5a16934ca8b83b6a /src | |
| parent | PKCS1v15 is a function (diff) | |
| signature | ||
add `json_body` arg to Request to json-encode body, only return from `body` if
not null
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/http.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/utils/http.py b/src/utils/http.py index 73780a58..ca27fc91 100644 --- a/src/utils/http.py +++ b/src/utils/http.py @@ -57,7 +57,7 @@ class Request(object): get_params: typing.Dict[str, str]={}, post_data: typing.Any=None, 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, detect_encoding: bool=True, @@ -72,6 +72,7 @@ class Request(object): self.headers = headers self.json = json + self.json_body = json_body self.allow_redirects = allow_redirects self.check_content_type = check_content_type self.parse = parse @@ -105,10 +106,13 @@ class Request(object): return headers def get_body(self) -> typing.Any: - if self.content_type == "application/json": - return _json.dumps(self.post_data) + if not self.post_data == None: + if self.content_type == "application/json" or self.json_body: + return _json.dumps(self.post_data) + else: + return self.post_data else: - return self.post_data + return None class Response(object): def __init__(self, code: int, data: typing.Any, |
