koon 1.2.0__tar.gz → 1.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {koon-1.2.0 → koon-1.2.2}/Cargo.lock +4 -4
- {koon-1.2.0 → koon-1.2.2}/Cargo.toml +1 -1
- {koon-1.2.0 → koon-1.2.2}/PKG-INFO +14 -7
- {koon-1.2.0 → koon-1.2.2}/README.md +12 -6
- {koon-1.2.0 → koon-1.2.2}/crates/python/src/lib.rs +13 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/conftest.py +8 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_adapter_httpx.py +10 -1
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_adapter_requests.py +9 -1
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_offline.py +30 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_stub.py +10 -6
- {koon-1.2.0 → koon-1.2.2}/pyproject.toml +2 -1
- {koon-1.2.0 → koon-1.2.2}/python/koon/__init__.py +15 -0
- {koon-1.2.0 → koon-1.2.2}/python/koon/__init__.pyi +23 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/Cargo.toml +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/alt_svc.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/blink_header_map.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/blocked.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/body.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/client_hints.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/connection.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/cookies.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/execute.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/h1.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/h2.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/h3.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/fetch_metadata.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/order.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/order_tables.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/tests/basic.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/tests/client_hints.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/tests/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/tests/safari.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/tests/subresource.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/tests/support.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/util.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/headers/websocket.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/options.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/request_body.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/response.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/client/ws.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/cookie.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/dns/cache.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/dns/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/dns/native.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/dns/resolver.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/error.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/http1.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/http2/config.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/http2/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/lib.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/multipart.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/pool.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/accept_language/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/accept_language/tables.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/accept_language/tests.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/brave.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/chrome/client_hints.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/chrome/headers.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/chrome/http2.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/chrome/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/chrome/quic.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/chrome/tls.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/edge.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/firefox.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/okhttp.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/opera.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/opera_mobile.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/safari/headers.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/safari/http2.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/safari/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/safari/quic.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/safari/tls.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/profile/samsung.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/proxy/ca.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/proxy/config.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/proxy/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/proxy/server.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/quic/config.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/quic/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/quic/transport.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/streaming.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/cert_compression.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/config.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/connector.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/ech_grease.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/keylog.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/root_store/chrome_root_store.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/root_store/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/session_cache.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/tls/sigalgs.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/util.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/verify.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/src/websocket.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/chrome_root_store.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/client_hints.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/clienthello.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/common/h3.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/common/mod.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/cookies.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/fingerprint.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/h2_frames.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/h3_local.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/http_plain.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/https_proxy.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/https_rr.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/keylog.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/local_tls.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_browser_ua.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_doh.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_google_client_hints.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_http.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_pool.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_redirects.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_root_store.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_sessions.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_streaming.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/network_websocket.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/profile_roundtrip.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/proxy_server.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/quic_initial.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/transport.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/core/tests/websocket_h2.rs +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/Cargo.toml +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_cookies.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_https_proxy.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_network.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_proxy.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_streaming.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/crates/python/tests/test_sync.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/python/koon/_adapter.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/python/koon/httpx.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/python/koon/httpx.pyi +0 -0
- {koon-1.2.0 → koon-1.2.2}/python/koon/py.typed +0 -0
- {koon-1.2.0 → koon-1.2.2}/python/koon/requests.py +0 -0
- {koon-1.2.0 → koon-1.2.2}/python/koon/requests.pyi +0 -0
|
@@ -1028,7 +1028,7 @@ dependencies = [
|
|
|
1028
1028
|
|
|
1029
1029
|
[[package]]
|
|
1030
1030
|
name = "koon-cli"
|
|
1031
|
-
version = "1.2.
|
|
1031
|
+
version = "1.2.2"
|
|
1032
1032
|
dependencies = [
|
|
1033
1033
|
"bytes",
|
|
1034
1034
|
"clap",
|
|
@@ -1042,7 +1042,7 @@ dependencies = [
|
|
|
1042
1042
|
|
|
1043
1043
|
[[package]]
|
|
1044
1044
|
name = "koon-core"
|
|
1045
|
-
version = "1.2.
|
|
1045
|
+
version = "1.2.2"
|
|
1046
1046
|
dependencies = [
|
|
1047
1047
|
"base64",
|
|
1048
1048
|
"brotli",
|
|
@@ -1080,7 +1080,7 @@ dependencies = [
|
|
|
1080
1080
|
|
|
1081
1081
|
[[package]]
|
|
1082
1082
|
name = "koon-node"
|
|
1083
|
-
version = "1.2.
|
|
1083
|
+
version = "1.2.2"
|
|
1084
1084
|
dependencies = [
|
|
1085
1085
|
"http",
|
|
1086
1086
|
"indexmap",
|
|
@@ -1093,7 +1093,7 @@ dependencies = [
|
|
|
1093
1093
|
|
|
1094
1094
|
[[package]]
|
|
1095
1095
|
name = "koon-python"
|
|
1096
|
-
version = "1.2.
|
|
1096
|
+
version = "1.2.2"
|
|
1097
1097
|
dependencies = [
|
|
1098
1098
|
"koon-core",
|
|
1099
1099
|
"pyo3",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koon
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.2
|
|
4
4
|
Classifier: Development Status :: 5 - Production/Stable
|
|
5
5
|
Classifier: Programming Language :: Rust
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
@@ -11,6 +11,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.12
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.13
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
14
15
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
15
16
|
Classifier: Topic :: Internet :: WWW/HTTP :: Session
|
|
16
17
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
@@ -67,8 +68,8 @@ pip install "koon[requests]" # with the requests adapter's dependency
|
|
|
67
68
|
**R**
|
|
68
69
|
```r
|
|
69
70
|
# Windows, or macOS on Apple silicon, with R 4.6: the prebuilt package of the release
|
|
70
|
-
install.packages("https://github.com/scrape-hub/koon/releases/download/v1.2.
|
|
71
|
-
install.packages("https://github.com/scrape-hub/koon/releases/download/v1.2.
|
|
71
|
+
install.packages("https://github.com/scrape-hub/koon/releases/download/v1.2.2/koon_1.2.2.zip", repos = NULL) # Windows
|
|
72
|
+
install.packages("https://github.com/scrape-hub/koon/releases/download/v1.2.2/koon_1.2.2.tgz", repos = NULL) # macOS
|
|
72
73
|
|
|
73
74
|
# Other platforms and R versions build from source: Rust 1.85+ and CMake, on
|
|
74
75
|
# Windows also Rtools, LLVM and `rustup target add x86_64-pc-windows-gnu`
|
|
@@ -216,7 +217,7 @@ Chrome Mobile and Firefox Mobile send their desktop counterpart's fingerprint wi
|
|
|
216
217
|
- **Per-request options**: headers, timeout, proxy and redirect following without touching the client
|
|
217
218
|
- **Response body cap**: 100 MiB by default, decompression bombs included
|
|
218
219
|
- **Request headers on every response**: exactly what was sent, HTTP/2 and HTTP/3 pseudo-headers included
|
|
219
|
-
- **Bot protection named**: `blockedBy` (`blocked_by` in Python, R and Rust) names the bot protection that answered instead of the page (Cloudflare, Akamai, DataDome, ...), which the status code alone does not tell
|
|
220
|
+
- **Bot protection named**: `blockedBy` (`blocked_by` in Python, R and Rust) names the bot protection that answered instead of the page (Cloudflare, Akamai, DataDome, ...), which the status code alone does not tell; as a function also for fetch(), streamed and httpx/requests responses
|
|
220
221
|
- **Plain HTTP**: `http://` with the header set browsers use for insecure origins
|
|
221
222
|
- **Network options**: local address binding, IPv4 or IPv6 only, host pinning like curl's `--resolve`, `locale` for an Accept-Language that matches the proxy's country
|
|
222
223
|
- **Key logging**: `SSLKEYLOGFILE` writes the TLS secrets (TCP, QUIC and DoH) for Wireshark
|
|
@@ -321,7 +322,8 @@ console.log(stream.status);
|
|
|
321
322
|
for await (const chunk of stream) process.stdout.write(chunk); // or nextChunk() / collect()
|
|
322
323
|
// The body arrives decoded (gzip, br, ...); { decode: false } in the options
|
|
323
324
|
// gives the bytes as sent. cancel() drops the rest of the body; leaving for
|
|
324
|
-
// await early does too.
|
|
325
|
+
// await early does too. blockedBy(stream, body) names a bot protection page
|
|
326
|
+
// from the body read (its first 400 KB suffice).
|
|
325
327
|
|
|
326
328
|
// Multipart upload
|
|
327
329
|
await client.postMultipart('https://httpbin.org/post', [
|
|
@@ -355,7 +357,7 @@ client and resolves to a standard `Response`, so fetch-based code only swaps
|
|
|
355
357
|
the function:
|
|
356
358
|
|
|
357
359
|
```javascript
|
|
358
|
-
import { koonFetch } from 'koonjs';
|
|
360
|
+
import { koonFetch, blockedBy } from 'koonjs';
|
|
359
361
|
|
|
360
362
|
const fetch = koonFetch({ browser: 'chrome', proxy: 'http://user:pass@proxy:8080' });
|
|
361
363
|
const resp = await fetch('https://httpbin.org/post', {
|
|
@@ -365,6 +367,8 @@ const resp = await fetch('https://httpbin.org/post', {
|
|
|
365
367
|
});
|
|
366
368
|
console.log(resp.status, await resp.json());
|
|
367
369
|
for await (const chunk of (await fetch('https://example.com/large')).body) {} // streamed
|
|
370
|
+
const page = await fetch('https://example.com/');
|
|
371
|
+
console.log(blockedBy(page, await page.text())); // null, or e.g. 'cloudflare'
|
|
368
372
|
```
|
|
369
373
|
|
|
370
374
|
Only the headers you set are added to the browser's, where the browser puts
|
|
@@ -444,6 +448,8 @@ with KoonSync("chrome", # latest Chrome on Windows
|
|
|
444
448
|
with client.request_streaming("GET", "https://example.com/large") as stream:
|
|
445
449
|
for chunk in stream: # or next_chunk() / collect()
|
|
446
450
|
...
|
|
451
|
+
# koon.blocked_by(stream, body) names a bot protection page from the body
|
|
452
|
+
# read (its first 400 KB suffice)
|
|
447
453
|
|
|
448
454
|
# An exception a hook raises is what the request raises; a raising
|
|
449
455
|
# on_request stops the request before it is sent.
|
|
@@ -520,7 +526,8 @@ koon's client options, the proxy included, to the transport or adapter, and
|
|
|
520
526
|
`verify=False` to skip certificate checks. Unsupported options raise instead
|
|
521
527
|
of being ignored, and errors are the library's (`httpx.ConnectError`,
|
|
522
528
|
`requests.exceptions.SSLError` and the like) with the `KoonError` as
|
|
523
|
-
`__cause__`.
|
|
529
|
+
`__cause__`. `koon.blocked_by(r, r.content)` names a bot protection page.
|
|
530
|
+
The full rules are in `koon/httpx.pyi` and `koon/requests.pyi`.
|
|
524
531
|
|
|
525
532
|
### R
|
|
526
533
|
|
|
@@ -28,8 +28,8 @@ pip install "koon[requests]" # with the requests adapter's dependency
|
|
|
28
28
|
**R**
|
|
29
29
|
```r
|
|
30
30
|
# Windows, or macOS on Apple silicon, with R 4.6: the prebuilt package of the release
|
|
31
|
-
install.packages("https://github.com/scrape-hub/koon/releases/download/v1.2.
|
|
32
|
-
install.packages("https://github.com/scrape-hub/koon/releases/download/v1.2.
|
|
31
|
+
install.packages("https://github.com/scrape-hub/koon/releases/download/v1.2.2/koon_1.2.2.zip", repos = NULL) # Windows
|
|
32
|
+
install.packages("https://github.com/scrape-hub/koon/releases/download/v1.2.2/koon_1.2.2.tgz", repos = NULL) # macOS
|
|
33
33
|
|
|
34
34
|
# Other platforms and R versions build from source: Rust 1.85+ and CMake, on
|
|
35
35
|
# Windows also Rtools, LLVM and `rustup target add x86_64-pc-windows-gnu`
|
|
@@ -177,7 +177,7 @@ Chrome Mobile and Firefox Mobile send their desktop counterpart's fingerprint wi
|
|
|
177
177
|
- **Per-request options**: headers, timeout, proxy and redirect following without touching the client
|
|
178
178
|
- **Response body cap**: 100 MiB by default, decompression bombs included
|
|
179
179
|
- **Request headers on every response**: exactly what was sent, HTTP/2 and HTTP/3 pseudo-headers included
|
|
180
|
-
- **Bot protection named**: `blockedBy` (`blocked_by` in Python, R and Rust) names the bot protection that answered instead of the page (Cloudflare, Akamai, DataDome, ...), which the status code alone does not tell
|
|
180
|
+
- **Bot protection named**: `blockedBy` (`blocked_by` in Python, R and Rust) names the bot protection that answered instead of the page (Cloudflare, Akamai, DataDome, ...), which the status code alone does not tell; as a function also for fetch(), streamed and httpx/requests responses
|
|
181
181
|
- **Plain HTTP**: `http://` with the header set browsers use for insecure origins
|
|
182
182
|
- **Network options**: local address binding, IPv4 or IPv6 only, host pinning like curl's `--resolve`, `locale` for an Accept-Language that matches the proxy's country
|
|
183
183
|
- **Key logging**: `SSLKEYLOGFILE` writes the TLS secrets (TCP, QUIC and DoH) for Wireshark
|
|
@@ -282,7 +282,8 @@ console.log(stream.status);
|
|
|
282
282
|
for await (const chunk of stream) process.stdout.write(chunk); // or nextChunk() / collect()
|
|
283
283
|
// The body arrives decoded (gzip, br, ...); { decode: false } in the options
|
|
284
284
|
// gives the bytes as sent. cancel() drops the rest of the body; leaving for
|
|
285
|
-
// await early does too.
|
|
285
|
+
// await early does too. blockedBy(stream, body) names a bot protection page
|
|
286
|
+
// from the body read (its first 400 KB suffice).
|
|
286
287
|
|
|
287
288
|
// Multipart upload
|
|
288
289
|
await client.postMultipart('https://httpbin.org/post', [
|
|
@@ -316,7 +317,7 @@ client and resolves to a standard `Response`, so fetch-based code only swaps
|
|
|
316
317
|
the function:
|
|
317
318
|
|
|
318
319
|
```javascript
|
|
319
|
-
import { koonFetch } from 'koonjs';
|
|
320
|
+
import { koonFetch, blockedBy } from 'koonjs';
|
|
320
321
|
|
|
321
322
|
const fetch = koonFetch({ browser: 'chrome', proxy: 'http://user:pass@proxy:8080' });
|
|
322
323
|
const resp = await fetch('https://httpbin.org/post', {
|
|
@@ -326,6 +327,8 @@ const resp = await fetch('https://httpbin.org/post', {
|
|
|
326
327
|
});
|
|
327
328
|
console.log(resp.status, await resp.json());
|
|
328
329
|
for await (const chunk of (await fetch('https://example.com/large')).body) {} // streamed
|
|
330
|
+
const page = await fetch('https://example.com/');
|
|
331
|
+
console.log(blockedBy(page, await page.text())); // null, or e.g. 'cloudflare'
|
|
329
332
|
```
|
|
330
333
|
|
|
331
334
|
Only the headers you set are added to the browser's, where the browser puts
|
|
@@ -405,6 +408,8 @@ with KoonSync("chrome", # latest Chrome on Windows
|
|
|
405
408
|
with client.request_streaming("GET", "https://example.com/large") as stream:
|
|
406
409
|
for chunk in stream: # or next_chunk() / collect()
|
|
407
410
|
...
|
|
411
|
+
# koon.blocked_by(stream, body) names a bot protection page from the body
|
|
412
|
+
# read (its first 400 KB suffice)
|
|
408
413
|
|
|
409
414
|
# An exception a hook raises is what the request raises; a raising
|
|
410
415
|
# on_request stops the request before it is sent.
|
|
@@ -481,7 +486,8 @@ koon's client options, the proxy included, to the transport or adapter, and
|
|
|
481
486
|
`verify=False` to skip certificate checks. Unsupported options raise instead
|
|
482
487
|
of being ignored, and errors are the library's (`httpx.ConnectError`,
|
|
483
488
|
`requests.exceptions.SSLError` and the like) with the `KoonError` as
|
|
484
|
-
`__cause__`.
|
|
489
|
+
`__cause__`. `koon.blocked_by(r, r.content)` names a bot protection page.
|
|
490
|
+
The full rules are in `koon/httpx.pyi` and `koon/requests.pyi`.
|
|
485
491
|
|
|
486
492
|
### R
|
|
487
493
|
|
|
@@ -1544,11 +1544,24 @@ fn _verify(py: Python<'_>, browser: &str, proxy: Option<&str>) -> PyResult<Strin
|
|
|
1544
1544
|
.map_err(to_koon_err)
|
|
1545
1545
|
}
|
|
1546
1546
|
|
|
1547
|
+
/// `koon_core::blocked_by` for `koon.blocked_by`, which takes the status,
|
|
1548
|
+
/// headers and URL from the response it is given.
|
|
1549
|
+
#[pyfunction]
|
|
1550
|
+
fn _blocked_by(
|
|
1551
|
+
status: u16,
|
|
1552
|
+
headers: Vec<(String, String)>,
|
|
1553
|
+
body: &[u8],
|
|
1554
|
+
url: &str,
|
|
1555
|
+
) -> Option<&'static str> {
|
|
1556
|
+
koon_core::blocked_by(status, &headers, body, url)
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1547
1559
|
#[pymodule]
|
|
1548
1560
|
fn _native(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
1549
1561
|
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
|
|
1550
1562
|
m.add_function(wrap_pyfunction!(browsers, m)?)?;
|
|
1551
1563
|
m.add_function(wrap_pyfunction!(_verify, m)?)?;
|
|
1564
|
+
m.add_function(wrap_pyfunction!(_blocked_by, m)?)?;
|
|
1552
1565
|
m.add_class::<NativeClient>()?;
|
|
1553
1566
|
m.add_class::<Mode>()?;
|
|
1554
1567
|
m.add_class::<KoonResponse>()?;
|
|
@@ -95,6 +95,14 @@ class EchoHandler(http.server.BaseHTTPRequestHandler):
|
|
|
95
95
|
self.send_header("Content-Length", str(len(page)))
|
|
96
96
|
self.end_headers()
|
|
97
97
|
self.wfile.write(page)
|
|
98
|
+
elif path == "/challenge-page":
|
|
99
|
+
# A challenge known by its body alone
|
|
100
|
+
page = b"<html><script>window._cf_chl_opt={}</script></html>"
|
|
101
|
+
self.send_response(403)
|
|
102
|
+
self.send_header("Content-Type", "text/html")
|
|
103
|
+
self.send_header("Content-Length", str(len(page)))
|
|
104
|
+
self.end_headers()
|
|
105
|
+
self.wfile.write(page)
|
|
98
106
|
else:
|
|
99
107
|
self.send_response(404)
|
|
100
108
|
self.send_header("Content-Length", "0")
|
|
@@ -13,7 +13,7 @@ httpx = pytest.importorskip("httpx")
|
|
|
13
13
|
|
|
14
14
|
from conftest import GZIP_TEXT, dropped, free_port # noqa: E402
|
|
15
15
|
|
|
16
|
-
from koon import KoonError, KoonSync # noqa: E402
|
|
16
|
+
from koon import KoonError, KoonSync, blocked_by # noqa: E402
|
|
17
17
|
from koon.httpx import AsyncKoonTransport, KoonTransport # noqa: E402
|
|
18
18
|
|
|
19
19
|
|
|
@@ -124,6 +124,15 @@ def test_a_compressed_body_is_decoded_once(client, adapter_server, coding):
|
|
|
124
124
|
assert "content-encoding" not in r.headers and "content-length" not in r.headers
|
|
125
125
|
|
|
126
126
|
|
|
127
|
+
|
|
128
|
+
def test_blocked_by_reads_an_httpx_response(client, adapter_server):
|
|
129
|
+
r = client.get(adapter_server.url + "/challenge-page")
|
|
130
|
+
assert blocked_by(r, r.content) == "cloudflare"
|
|
131
|
+
assert blocked_by(r, r.text) == "cloudflare"
|
|
132
|
+
assert blocked_by(client.get(adapter_server.url + "/challenge"), b"") == "cloudflare"
|
|
133
|
+
r = client.get(adapter_server.url + "/echo")
|
|
134
|
+
assert blocked_by(r, r.content) is None
|
|
135
|
+
|
|
127
136
|
def test_stream_reads_the_body_as_it_arrives(client, adapter_server):
|
|
128
137
|
adapter_server.gate.clear()
|
|
129
138
|
with client.stream("GET", adapter_server.url + "/gated") as r:
|
|
@@ -12,7 +12,7 @@ requests = pytest.importorskip("requests")
|
|
|
12
12
|
|
|
13
13
|
from conftest import GZIP_TEXT, dropped, free_port # noqa: E402
|
|
14
14
|
|
|
15
|
-
from koon import KoonError, KoonSync # noqa: E402
|
|
15
|
+
from koon import KoonError, KoonSync, blocked_by # noqa: E402
|
|
16
16
|
from koon.requests import KoonAdapter, Session # noqa: E402
|
|
17
17
|
|
|
18
18
|
|
|
@@ -129,6 +129,14 @@ def test_a_compressed_body_is_decoded_once(session, adapter_server, coding):
|
|
|
129
129
|
assert r.raw.read() == GZIP_TEXT
|
|
130
130
|
|
|
131
131
|
|
|
132
|
+
|
|
133
|
+
def test_blocked_by_reads_a_requests_response(session, adapter_server):
|
|
134
|
+
r = session.get(adapter_server.url + "/challenge-page")
|
|
135
|
+
assert blocked_by(r, r.content) == "cloudflare"
|
|
136
|
+
assert blocked_by(session.get(adapter_server.url + "/challenge"), b"") == "cloudflare"
|
|
137
|
+
r = session.get(adapter_server.url + "/echo")
|
|
138
|
+
assert blocked_by(r, r.content) is None
|
|
139
|
+
|
|
132
140
|
def test_stream_reads_the_body_as_it_arrives(session, adapter_server):
|
|
133
141
|
adapter_server.gate.clear()
|
|
134
142
|
r = session.get(adapter_server.url + "/gated", stream=True)
|
|
@@ -961,3 +961,33 @@ def test_blocked_by_names_the_bot_protection(base_url):
|
|
|
961
961
|
with koon.KoonSync("chrome") as client:
|
|
962
962
|
assert client.get(f"{base_url}/challenge").blocked_by == "cloudflare"
|
|
963
963
|
assert client.get(f"{base_url}/echo").blocked_by is None
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
def test_blocked_by_reads_a_streamed_body(base_url):
|
|
967
|
+
with KoonSync("chrome") as client:
|
|
968
|
+
with client.request_streaming("GET", f"{base_url}/challenge-page") as stream:
|
|
969
|
+
body = stream.collect()
|
|
970
|
+
assert koon.blocked_by(stream, body) == "cloudflare"
|
|
971
|
+
assert koon.blocked_by(stream, body.decode()) == "cloudflare"
|
|
972
|
+
assert koon.blocked_by(stream, bytearray(body)) == "cloudflare"
|
|
973
|
+
assert koon.blocked_by(stream, b"") is None
|
|
974
|
+
whole = client.get(f"{base_url}/challenge-page")
|
|
975
|
+
assert koon.blocked_by(whole, whole.body) == whole.blocked_by == "cloudflare"
|
|
976
|
+
|
|
977
|
+
async def streamed():
|
|
978
|
+
async with Koon("chrome") as client:
|
|
979
|
+
async with await client.request_streaming("GET", f"{base_url}/challenge-page") as s:
|
|
980
|
+
return koon.blocked_by(s, await s.collect())
|
|
981
|
+
|
|
982
|
+
assert run(streamed()) == "cloudflare"
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
def test_blocked_by_takes_headers_as_a_mapping_or_pairs():
|
|
986
|
+
def head(headers, url="https://example.com/"):
|
|
987
|
+
return types.SimpleNamespace(status_code=403, headers=headers, url=url)
|
|
988
|
+
|
|
989
|
+
assert koon.blocked_by(head({"CF-Mitigated": "challenge"}), b"") == "cloudflare"
|
|
990
|
+
assert koon.blocked_by(head([("cf-mitigated", "challenge")]), b"") == "cloudflare"
|
|
991
|
+
assert koon.blocked_by(head([], "https://consent.google.com/ml?x=1"), b"") == "consent"
|
|
992
|
+
with pytest.raises(TypeError):
|
|
993
|
+
koon.blocked_by(head([]), 42)
|
|
@@ -14,8 +14,8 @@ import koon
|
|
|
14
14
|
STUB = ast.parse(Path(koon.__file__).with_suffix(".pyi").read_text(encoding="utf-8"))
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def
|
|
18
|
-
return any(isinstance(b, ast.Name) and b.id ==
|
|
17
|
+
def has_base(node, name):
|
|
18
|
+
return any(isinstance(b, ast.Name) and b.id == name for b in node.bases)
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def typed_dict_keys(node):
|
|
@@ -23,11 +23,15 @@ def typed_dict_keys(node):
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
ALL_STUB_CLASSES = {node.name: node for node in STUB.body if isinstance(node, ast.ClassDef)}
|
|
26
|
-
# TypedDicts describe `**options` shapes
|
|
27
|
-
# they are not expected in `koon.__all__`.
|
|
28
|
-
STUB_TYPEDDICTS = {
|
|
26
|
+
# TypedDicts describe `**options` shapes and Protocols argument shapes, not
|
|
27
|
+
# runtime classes: kept apart so they are not expected in `koon.__all__`.
|
|
28
|
+
STUB_TYPEDDICTS = {
|
|
29
|
+
name: node for name, node in ALL_STUB_CLASSES.items() if has_base(node, "TypedDict")
|
|
30
|
+
}
|
|
29
31
|
STUB_CLASSES = {
|
|
30
|
-
name: node
|
|
32
|
+
name: node
|
|
33
|
+
for name, node in ALL_STUB_CLASSES.items()
|
|
34
|
+
if name not in STUB_TYPEDDICTS and not has_base(node, "Protocol")
|
|
31
35
|
}
|
|
32
36
|
FUNCTIONS = (ast.FunctionDef, ast.AsyncFunctionDef)
|
|
33
37
|
STUB_FUNCTIONS = {node.name for node in STUB.body if isinstance(node, FUNCTIONS)}
|
|
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "koon"
|
|
7
|
-
version = "1.2.
|
|
7
|
+
version = "1.2.2"
|
|
8
8
|
description = "Browser-impersonating HTTP client: TLS, HTTP/2 and HTTP/3 fingerprints of Chrome, Firefox, Safari, Edge, Opera, Brave, Samsung Internet and OkHttp, checked against the real browsers."
|
|
9
9
|
requires-python = ">=3.9"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -38,6 +38,7 @@ classifiers = [
|
|
|
38
38
|
"Programming Language :: Python :: 3.12",
|
|
39
39
|
"Programming Language :: Python :: 3.13",
|
|
40
40
|
"Programming Language :: Python :: 3.14",
|
|
41
|
+
"Programming Language :: Python :: 3.15",
|
|
41
42
|
"Topic :: Internet :: WWW/HTTP",
|
|
42
43
|
"Topic :: Internet :: WWW/HTTP :: Session",
|
|
43
44
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
@@ -16,6 +16,7 @@ from koon._native import (
|
|
|
16
16
|
KoonWebSocket,
|
|
17
17
|
_Client,
|
|
18
18
|
_Mode,
|
|
19
|
+
_blocked_by,
|
|
19
20
|
_verify,
|
|
20
21
|
__version__,
|
|
21
22
|
browsers,
|
|
@@ -31,6 +32,7 @@ __all__ = [
|
|
|
31
32
|
"KoonProxy",
|
|
32
33
|
"KoonError",
|
|
33
34
|
"KoonInvalidArgument",
|
|
35
|
+
"blocked_by",
|
|
34
36
|
"browsers",
|
|
35
37
|
"verify",
|
|
36
38
|
]
|
|
@@ -47,6 +49,19 @@ def verify(browser="chrome", proxy=None):
|
|
|
47
49
|
return _json.loads(_verify(browser, proxy))
|
|
48
50
|
|
|
49
51
|
|
|
52
|
+
def blocked_by(response, body):
|
|
53
|
+
"""``KoonResponse.blocked_by`` for a response whose body the caller
|
|
54
|
+
reads: a streaming response, or one of the httpx and requests
|
|
55
|
+
transports. ``body`` is the decoded body or its first 400 KB."""
|
|
56
|
+
headers = response.headers
|
|
57
|
+
pairs = list(headers.items() if hasattr(headers, "items") else headers)
|
|
58
|
+
if isinstance(body, str):
|
|
59
|
+
body = body.encode()
|
|
60
|
+
elif not isinstance(body, bytes):
|
|
61
|
+
body = bytes(memoryview(body))
|
|
62
|
+
return _blocked_by(response.status_code, pairs, body, str(response.url))
|
|
63
|
+
|
|
64
|
+
|
|
50
65
|
# The verbs forward their keyword arguments to `_request`, whose
|
|
51
66
|
# mode/method/url/body/form are positional-only: passing one of those, or
|
|
52
67
|
# anything else that is not a request option, by keyword is a TypeError.
|
|
@@ -10,6 +10,7 @@ from typing import (
|
|
|
10
10
|
Literal,
|
|
11
11
|
Mapping,
|
|
12
12
|
Optional,
|
|
13
|
+
Protocol,
|
|
13
14
|
Sequence,
|
|
14
15
|
Tuple,
|
|
15
16
|
Type,
|
|
@@ -127,6 +128,28 @@ def verify(browser: str = "chrome", proxy: Optional[str] = None) -> Dict[str, An
|
|
|
127
128
|
``KoonInvalidArgument``; unreachable services are part of the report."""
|
|
128
129
|
...
|
|
129
130
|
|
|
131
|
+
class ResponseHead(Protocol):
|
|
132
|
+
"""What ``blocked_by`` reads from a response: koon's own responses and
|
|
133
|
+
those of httpx and requests have it."""
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def status_code(self) -> int: ...
|
|
137
|
+
@property
|
|
138
|
+
def headers(self) -> HeaderInput: ...
|
|
139
|
+
@property
|
|
140
|
+
def url(self) -> object: ...
|
|
141
|
+
|
|
142
|
+
def blocked_by(
|
|
143
|
+
response: ResponseHead, body: Union[str, bytes, bytearray, memoryview]
|
|
144
|
+
) -> Optional[BlockedBy]:
|
|
145
|
+
"""``KoonResponse.blocked_by`` for a response whose body the caller
|
|
146
|
+
reads: a streaming response (``collect()``, the chunks read), or one of
|
|
147
|
+
the ``koon.httpx`` and ``koon.requests`` transports (``content``,
|
|
148
|
+
``text``). ``body`` is the decoded body or its first 400 KB, which are
|
|
149
|
+
all that is looked at; with an empty one only the headers and the URL
|
|
150
|
+
count."""
|
|
151
|
+
...
|
|
152
|
+
|
|
130
153
|
class Koon:
|
|
131
154
|
"""Browser impersonation HTTP client with TLS/HTTP2 fingerprint spoofing.
|
|
132
155
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|