Skip to content

Commit 3509e61

Browse files
authored
feat: json content type (#737)
* feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client
1 parent 33363be commit 3509e61

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

twilio/http/http_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ def __init__(
2727
):
2828
"""
2929
Constructor for the TwilioHttpClient
30-
3130
:param pool_connections
3231
:param request_hooks
3332
:param timeout: Timeout for the requests.
34-
Timeout should never be zero (0) or less.
33+
Timeout should never be zero (0) or less
3534
:param logger
3635
:param proxy: Http proxy for the requests session
3736
:param max_retries: Maximum number of retries each request should attempt
@@ -65,10 +64,10 @@ def request(
6564
:param headers: HTTP Headers to send with the request
6665
:param auth: Basic Auth arguments
6766
:param timeout: Socket/Read timeout for the request
68-
:param allow_redirects: Whether or not to allow redirects
67+
:param allow_redirects: Whether to allow redirects
6968
See the requests documentation for explanation of all these parameters
7069
71-
:return: An http response
70+
:return: An HTTP response
7271
"""
7372
if timeout is None:
7473
timeout = self.timeout
@@ -79,12 +78,14 @@ def request(
7978
"method": method.upper(),
8079
"url": url,
8180
"params": params,
82-
"data": data,
8381
"headers": headers,
8482
"auth": auth,
8583
"hooks": self.request_hooks,
8684
}
87-
85+
if headers and headers.get("Content-Type") == "application/json":
86+
kwargs["json"] = data
87+
else:
88+
kwargs["data"] = data
8889
self.log_request(kwargs)
8990

9091
self._test_only_last_response = None

0 commit comments

Comments
 (0)