-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcookiejar.patch
40 lines (36 loc) · 1.54 KB
/
cookiejar.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
diff --git a/rest.py b/restpatch.py
index b8da0751..3702266e 100644
--- a/rest.py
+++ b/restpatch.py
@@ -61,6 +61,10 @@ class RESTClientObject(object):
else:
cert_reqs = ssl.CERT_NONE
+ # VRChatAPI: Init global cookie storage
+ from http.cookiejar import CookieJar
+ self.cookie_jar = CookieJar()
+
addition_pool_args = {}
if configuration.assert_hostname is not None:
addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
@@ -134,6 +138,13 @@ class RESTClientObject(object):
post_params = post_params or {}
headers = headers or {}
+ # VRChatAPI: Build a mock Request object to work with
+ from urllib.request import Request
+ mock_request_object = Request(url=url, method=method, headers=headers)
+ self.cookie_jar.add_cookie_header(mock_request_object)
+ if "Cookie" in mock_request_object.unredirected_hdrs:
+ headers["Cookie"] = mock_request_object.unredirected_hdrs["Cookie"]
+
timeout = None
if _request_timeout:
if isinstance(_request_timeout, six.integer_types + (float, )): # noqa: E501,F821
@@ -209,6 +220,10 @@ class RESTClientObject(object):
msg = "{0}\n{1}".format(type(e).__name__, str(e))
raise ApiException(status=0, reason=msg)
+
+ # VRChatAPI: Extract and save cookies for global storage
+ self.cookie_jar.extract_cookies(r, mock_request_object)
+
if _preload_content:
r = RESTResponse(r)