Skip to content

Commit

Permalink
Release 0.9: Add support for firefox impersonation and bring Windows …
Browse files Browse the repository at this point in the history
…back (#496)

* Bump to version 0.9

* Enable CI build for release/*

* Adapt to new directory structure for Windows

* Add all libs for Windows

* Add lib files as extra objects for Windows

* Use the same image for Windows build as curl-impersonate

* Test win64 only

* Add Windows SDK lib

* Use selector loop on Windows
  • Loading branch information
lexiforest authored Feb 5, 2025
1 parent e3a7cca commit f2c2a0f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- main
- bugfix/*
- feature/*
- release/*
tags:
- v*

Expand Down Expand Up @@ -56,8 +57,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# os: [ubuntu-22.04, macos-12, macos-14, windows-2019]
os: [ubuntu-22.04, macos-13, macos-14]
os: [ubuntu-22.04, macos-13, macos-14, windows-latest]
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SHELL := bash

# this is the upstream libcurl-impersonate version
VERSION := 0.8.2
VERSION := 0.9.0
CURL_VERSION := curl-8_7_1

$(CURL_VERSION):
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ to specify your own customized fingerprints. See the [docs on impersonatation](h
- safari17_2_ios <sup>[1]</sup>
- safari18_0 <sup>[4]</sup>
- safari18_0_ios <sup>[4]</sup>
- firefox133 <sup>[5]</sup>

Notes:
1. Added in version `0.6.0`.
2. Fixed in version `0.6.0`, previous http2 fingerprints were [not correct](https://github.com/lwthiker/curl-impersonate/issues/215).
3. Added in version `0.7.0`.
4. Added in version `0.8.0`.
5. Added in version `0.9.0`.

### asyncio

Expand Down
8 changes: 8 additions & 0 deletions curl_cffi/requests/impersonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
"safari17_2_ios",
"safari18_0",
"safari18_0_ios",
# Firefox
"firefox133",
# alias
"chrome",
"edge",
"safari",
"safari_ios",
"chrome_android",
"firefox",
# Canonical names
# "edge_99",
# "edge_101",
Expand All @@ -55,6 +58,7 @@
DEFAULT_SAFARI = "safari18_0"
DEFAULT_SAFARI_IOS = "safari18_0_ios"
DEFAULT_CHROME_ANDROID = "chrome131_android"
DEFAULT_FIREFOX = "firefox133"


REAL_TARGET_MAP = {
Expand All @@ -63,6 +67,7 @@
"safari": "safari17_0",
"safari_ios": "safari17_2_ios",
"chrome_android": "chrome131_android",
"firefox": "firefox133",
}


Expand All @@ -77,6 +82,8 @@ def normalize_browser_type(item):
return DEFAULT_SAFARI_IOS
elif item == "chrome_android":
return DEFAULT_CHROME_ANDROID
elif item == "firefox":
return DEFAULT_FIREFOX
else:
return item

Expand Down Expand Up @@ -104,6 +111,7 @@ class BrowserType(str, Enum): # todo: remove in version 1.x
safari17_2_ios = "safari17_2_ios"
safari18_0 = "safari18_0"
safari18_0_ios = "safari18_0_ios"
firefox133 = "firefox133"


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions curl_cffi/requests/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Union,
)

from ..aio import CURL_SOCKET_BAD
from ..aio import CURL_SOCKET_BAD, _get_selector
from ..const import CurlECode, CurlInfo, CurlOpt, CurlWsFlag
from ..curl import Curl, CurlError
from .exceptions import SessionClosed, Timeout
Expand Down Expand Up @@ -525,7 +525,7 @@ def __init__(
@property
def loop(self):
if self._loop is None:
self._loop = asyncio.get_running_loop()
self._loop = _get_selector(asyncio.get_running_loop())
return self._loop

def __aiter__(self) -> Self:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "curl_cffi"
version = "0.8.1b9"
version = "0.9.0b1"
authors = [{ name = "Lyonnet", email = "[email protected]" }]
description = "libcurl ffi bindings for Python, with impersonation support."
license = { file = "LICENSE" }
Expand Down
38 changes: 36 additions & 2 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import shutil
import struct
import tempfile
from glob import glob
from pathlib import Path
from urllib.request import urlretrieve

from cffi import FFI

# this is the upstream libcurl-impersonate version
__version__ = "0.8.2"
__version__ = "0.9.0"


def detect_arch():
Expand Down Expand Up @@ -72,6 +73,12 @@ def download_libcurl():
os.makedirs(arch["libdir"], exist_ok=True)
shutil.unpack_archive(file, arch["libdir"])

if arch["system"] == "Windows":
for file in glob(os.path.join(arch["libdir"], "lib/*.lib")):
shutil.move(file, arch["libdir"])
for file in glob(os.path.join(arch["libdir"], "bin/*.dll")):
shutil.move(file, arch["libdir"])

print("Files after unpacking")
print(os.listdir(arch["libdir"]))

Expand All @@ -93,13 +100,39 @@ def get_curl_archives():
f"{arch['libdir']}/libbrotlienc.a",
f"{arch['libdir']}/libbrotlicommon.a",
]
if arch["system"] == "Windows":
return [
f"{arch['libdir']}/libcurl.lib",
f"{arch['libdir']}/zstd.lib",
f"{arch['libdir']}/zlib.lib",
f"{arch['libdir']}/ssl.lib",
f"{arch['libdir']}/nghttp2.lib",
f"{arch['libdir']}/crypto.lib",
f"{arch['libdir']}/brotlidec.lib",
f"{arch['libdir']}/brotlienc.lib",
f"{arch['libdir']}/brotlicommon.lib",
]
else:
return []


def get_curl_libraries():
if arch["system"] == "Windows":
return ["libcurl"]
return [
"Crypt32",
"Secur32",
"wldap32",
"Normaliz",
"libcurl",
"zstd",
"zlib",
"ssl",
"nghttp2",
"crypto",
"brotlienc",
"brotlidec",
"brotlicommon",
]
elif arch["system"] == "Darwin" or (
arch["system"] == "Linux" and arch.get("link_type") == "dynamic"
):
Expand All @@ -125,6 +158,7 @@ def get_curl_libraries():
library_dirs=[arch["libdir"]],
source_extension=".c",
include_dirs=[
os.path.join(arch["libdir"], "include"), # for Windows
str(root_dir / "include"),
str(root_dir / "ffi"),
],
Expand Down

0 comments on commit f2c2a0f

Please sign in to comment.