Additional support needed when using orjson
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
import binascii
|
||||
import hashlib
|
||||
import hmac
|
||||
from time import time
|
||||
|
||||
try:
|
||||
import orjson as json
|
||||
except ImportError:
|
||||
import json
|
||||
from time import time
|
||||
|
||||
def _to_b64url(data):
|
||||
return (
|
||||
|
||||
@@ -578,9 +578,9 @@ class Response:
|
||||
self.headers = NoCaseDict(headers or {})
|
||||
self.reason = reason
|
||||
if isinstance(body, (dict, list)):
|
||||
self.body = json.dumps(body).encode()
|
||||
body = json.dumps(body)
|
||||
self.headers['Content-Type'] = 'application/json; charset=UTF-8'
|
||||
elif isinstance(body, str):
|
||||
if isinstance(body, str):
|
||||
self.body = body.encode()
|
||||
else:
|
||||
# this applies to bytes, file-like objects or generators
|
||||
|
||||
@@ -29,8 +29,8 @@ class SSE:
|
||||
given, it must be a string.
|
||||
"""
|
||||
if isinstance(data, (dict, list)):
|
||||
data = json.dumps(data).encode()
|
||||
elif isinstance(data, str):
|
||||
data = json.dumps(data)
|
||||
if isinstance(data, str):
|
||||
data = data.encode()
|
||||
elif not isinstance(data, bytes):
|
||||
data = str(data).encode()
|
||||
|
||||
@@ -105,10 +105,10 @@ class TestClient:
|
||||
if body is None:
|
||||
body = b''
|
||||
elif isinstance(body, (dict, list)):
|
||||
body = json.dumps(body).encode()
|
||||
body = json.dumps(body)
|
||||
if 'Content-Type' not in headers: # pragma: no cover
|
||||
headers['Content-Type'] = 'application/json'
|
||||
elif isinstance(body, str):
|
||||
if isinstance(body, str):
|
||||
body = body.encode()
|
||||
if body and 'Content-Length' not in headers:
|
||||
headers['Content-Length'] = str(len(body))
|
||||
|
||||
Reference in New Issue
Block a user