Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor WebSocket support into separate sync/async implementations #206

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Pass session cookies directly
  • Loading branch information
dolfies committed Jan 4, 2024
commit 4b1cede9f67d14bae5b7ac478194791ad03776ca
4 changes: 1 addition & 3 deletions curl_cffi/requests/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ def _merge_curl_options(
headers = Headers(self.headers)
headers.update(headers)

cookies = Cookies(self.cookies)
cookies.update(cookies)

if proxy and proxies:
raise TypeError("Cannot specify both 'proxy' and 'proxies'")
if proxy:
Expand All @@ -183,6 +180,7 @@ def _merge_curl_options(
method,
url,
headers=headers,
session_cookies=self.cookies,
cookies=cookies,
auth=auth or self.auth,
timeout=self.timeout if timeout is not_set else timeout,
Expand Down
7 changes: 6 additions & 1 deletion curl_cffi/requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..const import CurlHttpVersion
from .cookies import CookieTypes
from .headers import HeaderTypes
from .session import BrowserType
from .session import BrowserType, ProxySpec

not_set: Any = object()

Expand Down Expand Up @@ -87,6 +87,7 @@ def _set_curl_options(
data: Optional[Union[Dict[str, str], str, BytesIO, bytes]] = None,
json: Optional[dict] = None,
headers: Optional[HeaderTypes] = None,
session_cookies: Optional[Cookies] = None,
cookies: Optional[CookieTypes] = None,
files: Optional[Dict] = None,
auth: Optional[Tuple[str, str]] = None,
Expand Down Expand Up @@ -178,6 +179,10 @@ def _set_curl_options(
c.setopt(CurlOpt.COOKIEFILE, b"") # always enable the curl cookie engine first
c.setopt(CurlOpt.COOKIELIST, "ALL") # remove all the old cookies first.

if session_cookies:
for morsel in session_cookies.get_cookies_for_curl(req):
# print("Setting", morsel.to_curl_format())
curl.setopt(CurlOpt.COOKIELIST, morsel.to_curl_format())
if cookies:
temp_cookies = Cookies(cookies)
for morsel in temp_cookies.get_cookies_for_curl(req):
Expand Down
Loading