Skip to content

Commit 3f33f20

Browse files
author
Florian
committed
Merge remote-tracking branch 'origin/master'
2 parents ae7c8a8 + be33f6b commit 3f33f20

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

tls_client/sessions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Any, Optional, Union
99
from json import dumps, loads
1010
import urllib.parse
11+
import base64
1112
import ctypes
1213
import uuid
1314

@@ -31,7 +32,6 @@ def __init__(
3132
header_priority: Optional[dict] = None, # Optional[list[str]]
3233
random_tls_extension_order: Optional = False,
3334
force_http1: Optional = False,
34-
is_byte_request: Optional = False
3535
) -> None:
3636
self._session_id = str(uuid.uuid4())
3737
# --- Standard Settings ----------------------------------------------------------------------------------------
@@ -225,9 +225,6 @@ def __init__(
225225
# force HTTP1
226226
self.force_http1 = force_http1
227227

228-
# true - to be able to provide a base64 encoded request body which is an array of bytes
229-
self.is_byte_request = is_byte_request
230-
231228
def execute_request(
232229
self,
233230
method: str,
@@ -299,18 +296,19 @@ def execute_request(
299296
proxy = ""
300297

301298
# --- Request --------------------------------------------------------------------------------------------------
299+
is_byte_request = isinstance(request_body, (bytes, bytearray))
302300
request_payload = {
303301
"sessionId": self._session_id,
304302
"followRedirects": allow_redirects,
305303
"forceHttp1": self.force_http1,
306304
"headers": dict(headers),
307305
"headerOrder": self.header_order,
308306
"insecureSkipVerify": insecure_skip_verify,
309-
"isByteRequest": self.is_byte_request,
307+
"isByteRequest": is_byte_request,
310308
"proxyUrl": proxy,
311309
"requestUrl": url,
312310
"requestMethod": method,
313-
"requestBody": request_body,
311+
"requestBody": base64.b64encode(request_body).decode() if is_byte_request else request_body,
314312
"requestCookies": [], # Empty because it's handled in python
315313
"timeoutSeconds": timeout_seconds,
316314
}

0 commit comments

Comments
 (0)