Skip to content

Commit 3965eaf

Browse files
author
Florian
committed
- fixed duplicate cookies
- updated shared libraries
1 parent d724121 commit 3965eaf

11 files changed

+61
-19
lines changed

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ Example 1 - Preset:
1414
import tls_client
1515

1616
# You can also use the following as `client_identifier`:
17-
# Chrome --> chrome_103, chrome_104, chrome_105, chrome_106, chrome_107, chrome_108
18-
# Firefox --> firefox_102, firefox_104
17+
# Chrome --> chrome_103, chrome_104, chrome_105, chrome_106, chrome_107, chrome_108, chrome109, Chrome110
18+
# Firefox --> firefox_102, firefox_104, firefox108, Firefox110
1919
# Opera --> opera_89, opera_90
2020
# Safari --> safari_15_3, safari_15_6_1, safari_16_0
2121
# iOS --> safari_ios_15_5, safari_ios_15_6, safari_ios_16_0
2222
# iPadOS --> safari_ios_15_6
23+
# Android --> okhttp4_android_7, okhttp4_android_8, okhttp4_android_9, okhttp4_android_10, okhttp4_android_11,
24+
# okhttp4_android_12, okhttp4_android_13
2325

2426
session = tls_client.Session(
25-
client_identifier="chrome_105"
27+
client_identifier="chrome110",
28+
random_tls_extension_order=True
2629
)
2730

2831
res = session.get(
@@ -121,6 +124,4 @@ Windows:
121124

122125
# Acknowledgements
123126
Big shout out to [Bogdanfinn](https://github.com/bogdanfinn) for open sourcing his [tls-client](https://github.com/bogdanfinn/tls-client) in Golang.
124-
Also to [requests](https://github.com/psf/requests), as most of the cookie handling is copied from it. :'D
125-
<br/>
126-
I wanted to keep the syntax as similar as possible to requests, as most people use it and are familiar with it!
127+
Also I wanted to keep the syntax as similar as possible to [requests](https://github.com/psf/requests), as most people use it and are familiar with it!

examples/example1 - preset.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import tls_client
22

33
# You can also use the following as `client_identifier`:
4-
# Chrome --> chrome_103, chrome_104, chrome_105, chrome_106, chrome_107, chrome_108
5-
# Firefox --> firefox_102, firefox_104
4+
# Chrome --> chrome_103, chrome_104, chrome_105, chrome_106, chrome_107, chrome_108, chrome109, Chrome110
5+
# Firefox --> firefox_102, firefox_104, firefox108, Firefox110
66
# Opera --> opera_89, opera_90
77
# Safari --> safari_15_3, safari_15_6_1, safari_16_0
88
# iOS --> safari_ios_15_5, safari_ios_15_6, safari_ios_16_0
99
# iPadOS --> safari_ios_15_6
10+
# Android --> okhttp4_android_7, okhttp4_android_8, okhttp4_android_9, okhttp4_android_10, okhttp4_android_11,
11+
# okhttp4_android_12, okhttp4_android_13
1012

1113
session = tls_client.Session(
12-
client_identifier="chrome_108",
14+
client_identifier="chrome109",
1315
random_tls_extension_order=True
1416
)
1517

tls_client/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
__title__ = "tls_client"
88
__description__ = "Advanced Python HTTP Client."
9-
__version__ = "0.1.8"
9+
__version__ = "0.1.9"
1010
__author__ = "Florian Zager"
1111
__license__ = "MIT"
140 KB
Binary file not shown.
158 KB
Binary file not shown.
107 KB
Binary file not shown.
73.4 KB
Binary file not shown.
107 KB
Binary file not shown.
88.8 KB
Binary file not shown.
107 KB
Binary file not shown.

tls_client/sessions.py

+48-9
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ def __init__(
2222
h2_settings: Optional[dict] = None, # Optional[dict[str, int]]
2323
h2_settings_order: Optional[list] = None, # Optional[list[str]]
2424
supported_signature_algorithms: Optional[list] = None, # Optional[list[str]]
25+
supported_delegated_credentials_algorithms: Optional[list] = None, # Optional[list[str]]
2526
supported_versions: Optional[list] = None, # Optional[list[str]]
2627
key_share_curves: Optional[list] = None, # Optional[list[str]]
2728
cert_compression_algo: str = None,
29+
additionalDecode: str = None,
2830
pseudo_header_order: Optional[list] = None, # Optional[list[str]
2931
connection_flow: Optional[int] = None,
3032
priority_frames: Optional[list] = None,
3133
header_order: Optional[list] = None, # Optional[list[str]]
3234
header_priority: Optional[dict] = None, # Optional[list[str]]
3335
random_tls_extension_order: Optional = False,
3436
force_http1: Optional = False,
37+
catch_panics: Optional = False,
3538
) -> None:
3639
self._session_id = str(uuid.uuid4())
3740
# --- Standard Settings ----------------------------------------------------------------------------------------
@@ -131,6 +134,33 @@ def __init__(
131134
# ]
132135
self.supported_signature_algorithms = supported_signature_algorithms
133136

137+
# Supported Delegated Credentials Algorithms
138+
# Possible Settings:
139+
# PKCS1WithSHA256
140+
# PKCS1WithSHA384
141+
# PKCS1WithSHA512
142+
# PSSWithSHA256
143+
# PSSWithSHA384
144+
# PSSWithSHA512
145+
# ECDSAWithP256AndSHA256
146+
# ECDSAWithP384AndSHA384
147+
# ECDSAWithP521AndSHA512
148+
# PKCS1WithSHA1
149+
# ECDSAWithSHA1
150+
#
151+
# Example:
152+
# [
153+
# "ECDSAWithP256AndSHA256",
154+
# "PSSWithSHA256",
155+
# "PKCS1WithSHA256",
156+
# "ECDSAWithP384AndSHA384",
157+
# "PSSWithSHA384",
158+
# "PKCS1WithSHA384",
159+
# "PSSWithSHA512",
160+
# "PKCS1WithSHA512",
161+
# ]
162+
self.supported_delegated_credentials_algorithms = supported_delegated_credentials_algorithms
163+
134164
# Supported Versions
135165
# Possible Settings:
136166
# GREASE
@@ -166,6 +196,11 @@ def __init__(
166196
# Examples: "zlib", "brotli", "zstd"
167197
self.cert_compression_algo = cert_compression_algo
168198

199+
# Additional Decode
200+
# Make sure the go code decodes the response body once explicit by provided algorithm.
201+
# Examples: null, "gzip", "br", "deflate"
202+
self.additionalDecode = additionalDecode
203+
169204
# Pseudo Header Order (:authority, :method, :path, :scheme)
170205
# Example:
171206
# [
@@ -225,6 +260,10 @@ def __init__(
225260
# force HTTP1
226261
self.force_http1 = force_http1
227262

263+
# catch panics
264+
# avoid the tls client to print the whole stacktrace when a panic (critical go error) happens
265+
self.catch_panics = catch_panics
266+
228267
def execute_request(
229268
self,
230269
method: str,
@@ -277,14 +316,11 @@ def execute_request(
277316
cookies = cookies or {}
278317
# Merge with session cookies
279318
cookies = merge_cookies(self.cookies, cookies)
280-
281-
cookie_header = get_cookie_header(
282-
request_url=url,
283-
request_headers=headers,
284-
cookie_jar=cookies
285-
)
286-
if cookie_header is not None:
287-
headers["Cookie"] = cookie_header
319+
# turn cookie jar into dict
320+
request_cookies = [
321+
{'domain': c.domain, 'expires': c.expires, 'name': c.name, 'path': c.path, 'value': c.value}
322+
for c in cookies
323+
]
288324

289325
# --- Proxy ----------------------------------------------------------------------------------------------------
290326
proxy = proxy or self.proxies
@@ -302,15 +338,17 @@ def execute_request(
302338
"sessionId": self._session_id,
303339
"followRedirects": allow_redirects,
304340
"forceHttp1": self.force_http1,
341+
"catchPanics": self.catch_panics,
305342
"headers": dict(headers),
306343
"headerOrder": self.header_order,
307344
"insecureSkipVerify": insecure_skip_verify,
308345
"isByteRequest": is_byte_request,
346+
"additionalDecode": self.additionalDecode,
309347
"proxyUrl": proxy,
310348
"requestUrl": url,
311349
"requestMethod": method,
312350
"requestBody": base64.b64encode(request_body).decode() if is_byte_request else request_body,
313-
"requestCookies": [], # Empty because it's handled in python
351+
"requestCookies": request_cookies,
314352
"timeoutSeconds": timeout_seconds,
315353
}
316354
if self.client_identifier is None:
@@ -325,6 +363,7 @@ def execute_request(
325363
"certCompressionAlgo": self.cert_compression_algo,
326364
"supportedVersions": self.supported_versions,
327365
"supportedSignatureAlgorithms": self.supported_signature_algorithms,
366+
"supportedDelegatedCredentialsAlgorithms": self.supported_delegated_credentials_algorithms ,
328367
"keyShareCurves": self.key_share_curves,
329368
}
330369
else:

0 commit comments

Comments
 (0)