koon 2.0.0__tar.gz → 2.1.0__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-2.0.0 → koon-2.1.0}/Cargo.lock +4 -4
- {koon-2.0.0 → koon-2.1.0}/Cargo.toml +1 -6
- {koon-2.0.0 → koon-2.1.0}/PKG-INFO +20 -18
- {koon-2.0.0 → koon-2.1.0}/README.md +19 -17
- koon-2.1.0/crates/core/Cargo.toml +78 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/alt_svc.rs +0 -92
- koon-2.1.0/crates/core/src/client/blink_header_map.rs +131 -0
- koon-2.1.0/crates/core/src/client/blocked.rs +163 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/body.rs +0 -48
- koon-2.1.0/crates/core/src/client/cf_header_dict.rs +204 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/client_hints.rs +0 -346
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/connection.rs +0 -196
- koon-2.1.0/crates/core/src/client/cookies.rs +93 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/execute.rs +209 -169
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/h1.rs +0 -15
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/h2.rs +0 -83
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/h3.rs +0 -171
- koon-2.1.0/crates/core/src/client/headers/context.rs +122 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/headers/fetch_metadata.rs +34 -53
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/headers/mod.rs +40 -92
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/headers/order.rs +64 -113
- koon-2.1.0/crates/core/src/client/headers/order_tables.rs +262 -0
- koon-2.1.0/crates/core/src/client/headers/safari_map.rs +460 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/headers/util.rs +1 -15
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/headers/websocket.rs +0 -26
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/mod.rs +9 -210
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/options.rs +0 -100
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/request_body.rs +0 -50
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/response.rs +5 -182
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/client/ws.rs +0 -27
- koon-2.1.0/crates/core/src/cookie.rs +1120 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/dns/cache.rs +0 -12
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/dns/mod.rs +0 -3
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/dns/native.rs +0 -141
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/dns/resolver.rs +0 -66
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/error.rs +0 -40
- koon-2.1.0/crates/core/src/http1.rs +523 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/lib.rs +2 -11
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/multipart.rs +0 -143
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/options/doc.rs +0 -45
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/options/mod.rs +1 -13
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/options/table.rs +0 -2
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/pool.rs +3 -128
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/accept_language/mod.rs +0 -42
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/accept_language/tables.rs +0 -7
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/brave.rs +0 -77
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/chrome/client_hints.rs +0 -74
- koon-2.1.0/crates/core/src/profile/chrome/headers.rs +139 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/chrome/http2.rs +0 -22
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/chrome/mod.rs +0 -7
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/chrome/quic.rs +0 -15
- koon-2.1.0/crates/core/src/profile/chrome/tls.rs +179 -0
- koon-2.1.0/crates/core/src/profile/edge.rs +115 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/firefox.rs +5 -217
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/mod.rs +0 -278
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/okhttp.rs +0 -70
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/opera.rs +0 -43
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/opera_mobile.rs +0 -49
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/releases.rs +8 -15
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/safari/headers.rs +2 -20
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/safari/http2.rs +0 -6
- koon-2.1.0/crates/core/src/profile/safari/mod.rs +600 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/safari/quic.rs +0 -6
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/safari/tls.rs +0 -12
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/safari/versions.rs +0 -2
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/profile/samsung.rs +0 -92
- koon-2.1.0/crates/core/src/proxy/ca.rs +268 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/proxy/config.rs +0 -54
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/proxy/mod.rs +0 -5
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/proxy/server.rs +5 -528
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/quic/config.rs +0 -51
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/quic/transport.rs +0 -288
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/streaming.rs +4 -7
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/tls/cert_compression.rs +0 -5
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/tls/config.rs +0 -149
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/tls/connector.rs +0 -289
- koon-2.1.0/crates/core/src/tls/ech_grease.rs +104 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/tls/keylog.rs +0 -11
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/tls/root_store/chrome_root_store.rs +127 -268
- koon-2.1.0/crates/core/src/tls/root_store/mod.rs +100 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/tls/session_cache.rs +0 -71
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/tls/sigalgs.rs +0 -46
- koon-2.1.0/crates/core/src/util.rs +57 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/verify/references.rs +10 -113
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/verify.rs +4 -603
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/websocket.rs +2 -188
- {koon-2.0.0 → koon-2.1.0}/crates/python/src/lib.rs +27 -49
- {koon-2.0.0 → koon-2.1.0}/pyproject.toml +1 -5
- {koon-2.0.0 → koon-2.1.0}/python/koon/__init__.py +0 -5
- {koon-2.0.0 → koon-2.1.0}/python/koon/__init__.pyi +0 -49
- {koon-2.0.0 → koon-2.1.0}/python/koon/_adapter.py +1 -9
- {koon-2.0.0 → koon-2.1.0}/python/koon/httpx.py +19 -17
- {koon-2.0.0 → koon-2.1.0}/python/koon/httpx.pyi +11 -3
- {koon-2.0.0 → koon-2.1.0}/python/koon/requests.py +15 -8
- {koon-2.0.0 → koon-2.1.0}/python/koon/requests.pyi +10 -2
- koon-2.0.0/crates/core/Cargo.toml +0 -116
- koon-2.0.0/crates/core/data/references.toml +0 -414
- koon-2.0.0/crates/core/data/releases.toml +0 -351
- koon-2.0.0/crates/core/data/update.py +0 -195
- koon-2.0.0/crates/core/src/client/blink_header_map.rs +0 -301
- koon-2.0.0/crates/core/src/client/blocked.rs +0 -333
- koon-2.0.0/crates/core/src/client/cookies.rs +0 -531
- koon-2.0.0/crates/core/src/client/headers/context.rs +0 -91
- koon-2.0.0/crates/core/src/client/headers/order_tables.rs +0 -435
- koon-2.0.0/crates/core/src/client/headers/tests/basic.rs +0 -1342
- koon-2.0.0/crates/core/src/client/headers/tests/client_hints.rs +0 -683
- koon-2.0.0/crates/core/src/client/headers/tests/mod.rs +0 -6
- koon-2.0.0/crates/core/src/client/headers/tests/safari.rs +0 -970
- koon-2.0.0/crates/core/src/client/headers/tests/subresource.rs +0 -302
- koon-2.0.0/crates/core/src/client/headers/tests/support.rs +0 -88
- koon-2.0.0/crates/core/src/cookie.rs +0 -2641
- koon-2.0.0/crates/core/src/http1.rs +0 -1022
- koon-2.0.0/crates/core/src/options/tests.rs +0 -298
- koon-2.0.0/crates/core/src/profile/accept_language/tests.rs +0 -619
- koon-2.0.0/crates/core/src/profile/chrome/headers.rs +0 -288
- koon-2.0.0/crates/core/src/profile/chrome/tls.rs +0 -363
- koon-2.0.0/crates/core/src/profile/edge.rs +0 -260
- koon-2.0.0/crates/core/src/profile/safari/mod.rs +0 -1176
- koon-2.0.0/crates/core/src/proxy/ca.rs +0 -598
- koon-2.0.0/crates/core/src/tls/ech_grease.rs +0 -269
- koon-2.0.0/crates/core/src/tls/root_store/mod.rs +0 -278
- koon-2.0.0/crates/core/src/util.rs +0 -91
- koon-2.0.0/crates/core/tests/chrome_root_store.rs +0 -502
- koon-2.0.0/crates/core/tests/client_hints.rs +0 -428
- koon-2.0.0/crates/core/tests/clienthello.rs +0 -707
- koon-2.0.0/crates/core/tests/common/h3.rs +0 -492
- koon-2.0.0/crates/core/tests/common/mod.rs +0 -257
- koon-2.0.0/crates/core/tests/common/routes.rs +0 -243
- koon-2.0.0/crates/core/tests/cookies.rs +0 -207
- koon-2.0.0/crates/core/tests/fingerprint.rs +0 -84
- koon-2.0.0/crates/core/tests/generated.rs +0 -1156
- koon-2.0.0/crates/core/tests/h2_frames.rs +0 -745
- koon-2.0.0/crates/core/tests/h3_local.rs +0 -564
- koon-2.0.0/crates/core/tests/http_plain.rs +0 -1143
- koon-2.0.0/crates/core/tests/https_proxy.rs +0 -370
- koon-2.0.0/crates/core/tests/https_rr.rs +0 -672
- koon-2.0.0/crates/core/tests/keylog.rs +0 -44
- koon-2.0.0/crates/core/tests/local_tls.rs +0 -286
- koon-2.0.0/crates/core/tests/network_browser_ua.rs +0 -46
- koon-2.0.0/crates/core/tests/network_doh.rs +0 -31
- koon-2.0.0/crates/core/tests/network_freshness.rs +0 -189
- koon-2.0.0/crates/core/tests/network_google_client_hints.rs +0 -85
- koon-2.0.0/crates/core/tests/network_http.rs +0 -298
- koon-2.0.0/crates/core/tests/network_pool.rs +0 -89
- koon-2.0.0/crates/core/tests/network_redirects.rs +0 -95
- koon-2.0.0/crates/core/tests/network_root_store.rs +0 -99
- koon-2.0.0/crates/core/tests/network_sessions.rs +0 -128
- koon-2.0.0/crates/core/tests/network_streaming.rs +0 -61
- koon-2.0.0/crates/core/tests/network_websocket.rs +0 -35
- koon-2.0.0/crates/core/tests/options_matrix.rs +0 -378
- koon-2.0.0/crates/core/tests/profile_roundtrip.rs +0 -524
- koon-2.0.0/crates/core/tests/proxy_server.rs +0 -979
- koon-2.0.0/crates/core/tests/quic_initial.rs +0 -1295
- koon-2.0.0/crates/core/tests/transport.rs +0 -116
- koon-2.0.0/crates/core/tests/websocket_h2.rs +0 -1271
- koon-2.0.0/crates/python/tests/conftest.py +0 -370
- koon-2.0.0/crates/python/tests/test_adapter_httpx.py +0 -290
- koon-2.0.0/crates/python/tests/test_adapter_requests.py +0 -229
- koon-2.0.0/crates/python/tests/test_cookies.py +0 -307
- koon-2.0.0/crates/python/tests/test_https_proxy.py +0 -164
- koon-2.0.0/crates/python/tests/test_network.py +0 -74
- koon-2.0.0/crates/python/tests/test_offline.py +0 -1032
- koon-2.0.0/crates/python/tests/test_proxy.py +0 -189
- koon-2.0.0/crates/python/tests/test_streaming.py +0 -207
- koon-2.0.0/crates/python/tests/test_stub.py +0 -110
- koon-2.0.0/crates/python/tests/test_sync.py +0 -142
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/http2/config.rs +0 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/http2/mod.rs +0 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/quic/mod.rs +0 -0
- {koon-2.0.0 → koon-2.1.0}/crates/core/src/tls/mod.rs +0 -0
- {koon-2.0.0 → koon-2.1.0}/crates/python/Cargo.toml +0 -0
- {koon-2.0.0 → koon-2.1.0}/python/koon/py.typed +0 -0
|
@@ -1028,7 +1028,7 @@ dependencies = [
|
|
|
1028
1028
|
|
|
1029
1029
|
[[package]]
|
|
1030
1030
|
name = "koon-cli"
|
|
1031
|
-
version = "2.
|
|
1031
|
+
version = "2.1.0"
|
|
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 = "2.
|
|
1045
|
+
version = "2.1.0"
|
|
1046
1046
|
dependencies = [
|
|
1047
1047
|
"base64",
|
|
1048
1048
|
"brotli",
|
|
@@ -1082,7 +1082,7 @@ dependencies = [
|
|
|
1082
1082
|
|
|
1083
1083
|
[[package]]
|
|
1084
1084
|
name = "koon-node"
|
|
1085
|
-
version = "2.
|
|
1085
|
+
version = "2.1.0"
|
|
1086
1086
|
dependencies = [
|
|
1087
1087
|
"http",
|
|
1088
1088
|
"indexmap",
|
|
@@ -1095,7 +1095,7 @@ dependencies = [
|
|
|
1095
1095
|
|
|
1096
1096
|
[[package]]
|
|
1097
1097
|
name = "koon-python"
|
|
1098
|
-
version = "2.
|
|
1098
|
+
version = "2.1.0"
|
|
1099
1099
|
dependencies = [
|
|
1100
1100
|
"koon-core",
|
|
1101
1101
|
"pyo3",
|
|
@@ -6,7 +6,7 @@ exclude = [
|
|
|
6
6
|
]
|
|
7
7
|
|
|
8
8
|
[workspace.package]
|
|
9
|
-
version = "2.
|
|
9
|
+
version = "2.1.0"
|
|
10
10
|
edition = "2024"
|
|
11
11
|
rust-version = "1.85"
|
|
12
12
|
license = "MIT"
|
|
@@ -19,14 +19,9 @@ strip = true
|
|
|
19
19
|
lto = true
|
|
20
20
|
codegen-units = 1
|
|
21
21
|
|
|
22
|
-
# BoringSSL is built by CMake with the build type cmake-rs derives from this
|
|
23
|
-
# package's opt-level; 0 gives Debug, which makes every handshake several
|
|
24
|
-
# times slower. Keep it optimised in development builds too.
|
|
25
22
|
[profile.dev.package.btls-sys]
|
|
26
23
|
opt-level = 3
|
|
27
24
|
|
|
28
|
-
# quinn-btls and h3-quinn build on the crates.io releases of quinn and h3;
|
|
29
|
-
# koon's forks of both replace them in the whole dependency graph.
|
|
30
25
|
[patch.crates-io]
|
|
31
26
|
quinn = { git = "https://github.com/scrape-hub/quinn.git", tag = "koon-1.0.0" }
|
|
32
27
|
quinn-proto = { git = "https://github.com/scrape-hub/quinn.git", tag = "koon-1.0.0" }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: koon
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Classifier: Development Status :: 5 - Production/Stable
|
|
5
5
|
Classifier: Programming Language :: Rust
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
@@ -41,7 +41,6 @@ Project-URL: Repository, https://github.com/scrape-hub/koon
|
|
|
41
41
|
[](https://www.npmjs.com/package/koonjs)
|
|
42
42
|
[](https://pypi.org/project/koon/)
|
|
43
43
|
[](https://github.com/scrape-hub/koon/blob/master/LICENSE)
|
|
44
|
-
[](https://github.com/scrape-hub/koon/actions)
|
|
45
44
|
|
|
46
45
|
An HTTP client that impersonates real browsers at the TLS, HTTP/2, and HTTP/3 fingerprint level.
|
|
47
46
|
|
|
@@ -66,8 +65,8 @@ pip install "koon[requests]" # with the requests adapter's dependency
|
|
|
66
65
|
**R**
|
|
67
66
|
```r
|
|
68
67
|
# Windows, or macOS on Apple silicon, with R 4.6: the prebuilt package of the release
|
|
69
|
-
install.packages("https://github.com/scrape-hub/koon/releases/download/v2.
|
|
70
|
-
install.packages("https://github.com/scrape-hub/koon/releases/download/v2.
|
|
68
|
+
install.packages("https://github.com/scrape-hub/koon/releases/download/v2.1.0/koon_2.1.0.zip", repos = NULL) # Windows
|
|
69
|
+
install.packages("https://github.com/scrape-hub/koon/releases/download/v2.1.0/koon_2.1.0.tgz", repos = NULL) # macOS
|
|
71
70
|
|
|
72
71
|
# Other platforms and R versions build from source: Rust 1.85+ and CMake, on Windows
|
|
73
72
|
# also Rtools and `rustup target add x86_64-pc-windows-gnu`
|
|
@@ -167,28 +166,28 @@ Match the language to the IP as well. koon asks for English pages unless you set
|
|
|
167
166
|
|
|
168
167
|
| Browser | Versions | Platforms | Profiles |
|
|
169
168
|
|---------|----------|-----------|----------|
|
|
170
|
-
| Chrome | 131-
|
|
169
|
+
| Chrome | 131-158 | Windows, macOS, Linux, Android | 112 |
|
|
171
170
|
| Firefox | 135-159 | Windows, macOS, Linux, Android | 100 |
|
|
172
171
|
| Safari | 15.6-27.0 | macOS, iOS | 41 |
|
|
173
|
-
| Edge | 131-
|
|
172
|
+
| Edge | 131-157 | Windows, macOS, Android | 81 |
|
|
174
173
|
| Opera | 124-139 | Windows, macOS, Linux | 48 |
|
|
175
174
|
| Opera Mobile | 102 | Android | 1 |
|
|
176
|
-
| Brave | 153-
|
|
175
|
+
| Brave | 153-157 (1.95 to 1.99) | Windows, macOS, Linux, Android | 20 |
|
|
177
176
|
| Samsung Internet | 29-30 | Android | 2 |
|
|
178
177
|
| OkHttp | 4, 5 | Android | 2 |
|
|
179
178
|
|
|
180
|
-
**
|
|
179
|
+
**407 profiles** total. `koon --list-browsers`, `Koon.browsers()` (Node), `koon.browsers()` (Python) and `koon_browsers()` (R) list them all.
|
|
181
180
|
|
|
182
181
|
### Profile naming
|
|
183
182
|
|
|
184
|
-
Format: `{browser}{version}{-os}`. All parts but the browser name are optional, dash included (`chrome154-macos` or `chrome154macos`). Omit the version for the latest of any browser. Without an OS, desktop browsers default to Windows except Safari (macOS); Brave is named by the Chromium version it reports (`
|
|
183
|
+
Format: `{browser}{version}{-os}`. All parts but the browser name are optional, dash included (`chrome154-macos` or `chrome154macos`). Omit the version for the latest of any browser. Without an OS, desktop browsers default to Windows except Safari (macOS); Brave is named by the Chromium version it reports (`brave157` = Brave 1.99).
|
|
185
184
|
|
|
186
185
|
| Browser | Example profiles |
|
|
187
186
|
|---------|-------------------|
|
|
188
|
-
| Chrome, Firefox, Opera | `
|
|
189
|
-
| Edge, Brave | `
|
|
187
|
+
| Chrome, Firefox, Opera | `chrome158`, `-windows`, `-macos`, `-linux` |
|
|
188
|
+
| Edge, Brave | `edge157`, `-windows`, `-macos` (Brave also `-linux`) |
|
|
190
189
|
| Safari | `safari270-macos` |
|
|
191
|
-
| Chrome/Firefox/Edge/Brave Mobile (Android) | `chrome-
|
|
190
|
+
| Chrome/Firefox/Edge/Brave Mobile (Android) | `chrome-mobile158`, `firefox-mobile159`, `edge-mobile157`, `brave-mobile157` |
|
|
192
191
|
| Safari Mobile (iOS) | `safari-mobile270` |
|
|
193
192
|
| Samsung Internet, Opera Mobile (Android) | `samsung30`, `opera-mobile102` |
|
|
194
193
|
| OkHttp | `okhttp4`, `okhttp5` (`-android` suffix optional) |
|
|
@@ -370,10 +369,12 @@ console.log(blockedBy(page, await page.text())); // null, or e.g. 'cloudflare'
|
|
|
370
369
|
|
|
371
370
|
Only the headers you set are added to the browser's, where the browser puts
|
|
372
371
|
them; Node's own fetch headers (`user-agent: node`, ...) are never sent.
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
`
|
|
376
|
-
|
|
372
|
+
A plain GET goes out as a navigation and a POST of a `URLSearchParams` or
|
|
373
|
+
`FormData` body as a form submission, unless you set an `Accept` without
|
|
374
|
+
`text/html`; anything else is a fetch() call. Redirects (`follow`, `manual`,
|
|
375
|
+
`error`) and cookies are handled by the koon client, `signal` cancels the
|
|
376
|
+
request or its body, and failures reject with `TypeError('fetch failed')`
|
|
377
|
+
whose `cause` carries the koon error `code`. The details are in `index.d.ts`.
|
|
377
378
|
|
|
378
379
|
### Python
|
|
379
380
|
|
|
@@ -513,7 +514,8 @@ session.mount("https://", KoonAdapter("chrome"))
|
|
|
513
514
|
|
|
514
515
|
The library keeps its part: redirects, cookies (its jar; koon's is off),
|
|
515
516
|
auth, hooks, timeouts, and with requests the proxies from `proxies=` and the
|
|
516
|
-
environment.
|
|
517
|
+
environment. The redirects it follows still go out as the browser's: a
|
|
518
|
+
fetch() stays a fetch(), and Referer and Origin follow the redirect chain. Its own default headers, such as `User-Agent: python-httpx/x.y`,
|
|
517
519
|
`python-requests/x.y` and `Accept: */*`, are dropped, so the browser's go out
|
|
518
520
|
in the browser's order; every header you set is sent where the browser puts
|
|
519
521
|
it. `files=` uploads go out as the browser encodes multipart forms (its
|
|
@@ -783,7 +785,7 @@ async fn main() -> Result<(), koon_core::Error> {
|
|
|
783
785
|
fingerprints of the real browsers. Each profile connects to
|
|
784
786
|
[tls.browserleaks.com](https://tls.browserleaks.com/json) (tls.peet.ws if that
|
|
785
787
|
fails), which reports the JA4, JA3N, JA3 and Akamai HTTP/2 fingerprint it sees.
|
|
786
|
-
Where a QUIC reference exists (Chrome 134-
|
|
788
|
+
Where a QUIC reference exists (Chrome 134-158, Edge 153-157, Opera 136-139, Brave, Opera Mobile,
|
|
787
789
|
Firefox 155-159 on the desktop and 146-159 on Android, and the Safari releases whose transport
|
|
788
790
|
parameters were captured;
|
|
789
791
|
Samsung Internet uses no HTTP/3), the
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/koonjs)
|
|
4
4
|
[](https://pypi.org/project/koon/)
|
|
5
5
|
[](https://github.com/scrape-hub/koon/blob/master/LICENSE)
|
|
6
|
-
[](https://github.com/scrape-hub/koon/actions)
|
|
7
6
|
|
|
8
7
|
An HTTP client that impersonates real browsers at the TLS, HTTP/2, and HTTP/3 fingerprint level.
|
|
9
8
|
|
|
@@ -28,8 +27,8 @@ pip install "koon[requests]" # with the requests adapter's dependency
|
|
|
28
27
|
**R**
|
|
29
28
|
```r
|
|
30
29
|
# 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/v2.
|
|
32
|
-
install.packages("https://github.com/scrape-hub/koon/releases/download/v2.
|
|
30
|
+
install.packages("https://github.com/scrape-hub/koon/releases/download/v2.1.0/koon_2.1.0.zip", repos = NULL) # Windows
|
|
31
|
+
install.packages("https://github.com/scrape-hub/koon/releases/download/v2.1.0/koon_2.1.0.tgz", repos = NULL) # macOS
|
|
33
32
|
|
|
34
33
|
# Other platforms and R versions build from source: Rust 1.85+ and CMake, on Windows
|
|
35
34
|
# also Rtools and `rustup target add x86_64-pc-windows-gnu`
|
|
@@ -129,28 +128,28 @@ Match the language to the IP as well. koon asks for English pages unless you set
|
|
|
129
128
|
|
|
130
129
|
| Browser | Versions | Platforms | Profiles |
|
|
131
130
|
|---------|----------|-----------|----------|
|
|
132
|
-
| Chrome | 131-
|
|
131
|
+
| Chrome | 131-158 | Windows, macOS, Linux, Android | 112 |
|
|
133
132
|
| Firefox | 135-159 | Windows, macOS, Linux, Android | 100 |
|
|
134
133
|
| Safari | 15.6-27.0 | macOS, iOS | 41 |
|
|
135
|
-
| Edge | 131-
|
|
134
|
+
| Edge | 131-157 | Windows, macOS, Android | 81 |
|
|
136
135
|
| Opera | 124-139 | Windows, macOS, Linux | 48 |
|
|
137
136
|
| Opera Mobile | 102 | Android | 1 |
|
|
138
|
-
| Brave | 153-
|
|
137
|
+
| Brave | 153-157 (1.95 to 1.99) | Windows, macOS, Linux, Android | 20 |
|
|
139
138
|
| Samsung Internet | 29-30 | Android | 2 |
|
|
140
139
|
| OkHttp | 4, 5 | Android | 2 |
|
|
141
140
|
|
|
142
|
-
**
|
|
141
|
+
**407 profiles** total. `koon --list-browsers`, `Koon.browsers()` (Node), `koon.browsers()` (Python) and `koon_browsers()` (R) list them all.
|
|
143
142
|
|
|
144
143
|
### Profile naming
|
|
145
144
|
|
|
146
|
-
Format: `{browser}{version}{-os}`. All parts but the browser name are optional, dash included (`chrome154-macos` or `chrome154macos`). Omit the version for the latest of any browser. Without an OS, desktop browsers default to Windows except Safari (macOS); Brave is named by the Chromium version it reports (`
|
|
145
|
+
Format: `{browser}{version}{-os}`. All parts but the browser name are optional, dash included (`chrome154-macos` or `chrome154macos`). Omit the version for the latest of any browser. Without an OS, desktop browsers default to Windows except Safari (macOS); Brave is named by the Chromium version it reports (`brave157` = Brave 1.99).
|
|
147
146
|
|
|
148
147
|
| Browser | Example profiles |
|
|
149
148
|
|---------|-------------------|
|
|
150
|
-
| Chrome, Firefox, Opera | `
|
|
151
|
-
| Edge, Brave | `
|
|
149
|
+
| Chrome, Firefox, Opera | `chrome158`, `-windows`, `-macos`, `-linux` |
|
|
150
|
+
| Edge, Brave | `edge157`, `-windows`, `-macos` (Brave also `-linux`) |
|
|
152
151
|
| Safari | `safari270-macos` |
|
|
153
|
-
| Chrome/Firefox/Edge/Brave Mobile (Android) | `chrome-
|
|
152
|
+
| Chrome/Firefox/Edge/Brave Mobile (Android) | `chrome-mobile158`, `firefox-mobile159`, `edge-mobile157`, `brave-mobile157` |
|
|
154
153
|
| Safari Mobile (iOS) | `safari-mobile270` |
|
|
155
154
|
| Samsung Internet, Opera Mobile (Android) | `samsung30`, `opera-mobile102` |
|
|
156
155
|
| OkHttp | `okhttp4`, `okhttp5` (`-android` suffix optional) |
|
|
@@ -332,10 +331,12 @@ console.log(blockedBy(page, await page.text())); // null, or e.g. 'cloudflare'
|
|
|
332
331
|
|
|
333
332
|
Only the headers you set are added to the browser's, where the browser puts
|
|
334
333
|
them; Node's own fetch headers (`user-agent: node`, ...) are never sent.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
`
|
|
338
|
-
|
|
334
|
+
A plain GET goes out as a navigation and a POST of a `URLSearchParams` or
|
|
335
|
+
`FormData` body as a form submission, unless you set an `Accept` without
|
|
336
|
+
`text/html`; anything else is a fetch() call. Redirects (`follow`, `manual`,
|
|
337
|
+
`error`) and cookies are handled by the koon client, `signal` cancels the
|
|
338
|
+
request or its body, and failures reject with `TypeError('fetch failed')`
|
|
339
|
+
whose `cause` carries the koon error `code`. The details are in `index.d.ts`.
|
|
339
340
|
|
|
340
341
|
### Python
|
|
341
342
|
|
|
@@ -475,7 +476,8 @@ session.mount("https://", KoonAdapter("chrome"))
|
|
|
475
476
|
|
|
476
477
|
The library keeps its part: redirects, cookies (its jar; koon's is off),
|
|
477
478
|
auth, hooks, timeouts, and with requests the proxies from `proxies=` and the
|
|
478
|
-
environment.
|
|
479
|
+
environment. The redirects it follows still go out as the browser's: a
|
|
480
|
+
fetch() stays a fetch(), and Referer and Origin follow the redirect chain. Its own default headers, such as `User-Agent: python-httpx/x.y`,
|
|
479
481
|
`python-requests/x.y` and `Accept: */*`, are dropped, so the browser's go out
|
|
480
482
|
in the browser's order; every header you set is sent where the browser puts
|
|
481
483
|
it. `files=` uploads go out as the browser encodes multipart forms (its
|
|
@@ -745,7 +747,7 @@ async fn main() -> Result<(), koon_core::Error> {
|
|
|
745
747
|
fingerprints of the real browsers. Each profile connects to
|
|
746
748
|
[tls.browserleaks.com](https://tls.browserleaks.com/json) (tls.peet.ws if that
|
|
747
749
|
fails), which reports the JA4, JA3N, JA3 and Akamai HTTP/2 fingerprint it sees.
|
|
748
|
-
Where a QUIC reference exists (Chrome 134-
|
|
750
|
+
Where a QUIC reference exists (Chrome 134-158, Edge 153-157, Opera 136-139, Brave, Opera Mobile,
|
|
749
751
|
Firefox 155-159 on the desktop and 146-159 on Android, and the Safari releases whose transport
|
|
750
752
|
parameters were captured;
|
|
751
753
|
Samsung Internet uses no HTTP/3), the
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "koon-core"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
rust-version.workspace = true
|
|
6
|
+
license.workspace = true
|
|
7
|
+
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."
|
|
8
|
+
repository = "https://github.com/scrape-hub/koon"
|
|
9
|
+
homepage = "https://github.com/scrape-hub/koon"
|
|
10
|
+
keywords = ["tls-fingerprint", "browser-impersonation", "anti-bot", "web-scraping", "http-client"]
|
|
11
|
+
categories = ["web-programming::http-client", "network-programming"]
|
|
12
|
+
|
|
13
|
+
[features]
|
|
14
|
+
default = ["socks", "doh"]
|
|
15
|
+
socks = ["dep:tokio-socks"]
|
|
16
|
+
doh = ["dep:hickory-proto", "dep:hickory-resolver"]
|
|
17
|
+
test-util = []
|
|
18
|
+
|
|
19
|
+
[dependencies]
|
|
20
|
+
btls = { git = "https://github.com/scrape-hub/btls.git", tag = "koon-2.0.0" }
|
|
21
|
+
tokio-btls = { git = "https://github.com/scrape-hub/btls.git", tag = "koon-2.0.0" }
|
|
22
|
+
quinn-btls = { git = "https://github.com/scrape-hub/btls.git", tag = "koon-2.0.0" }
|
|
23
|
+
quinn = { version = "0.11", default-features = false, features = ["runtime-tokio"] }
|
|
24
|
+
h3 = "0.0.8"
|
|
25
|
+
h3-quinn = "0.0.10"
|
|
26
|
+
|
|
27
|
+
http2 = { git = "https://github.com/scrape-hub/http2.git", tag = "koon-1.0.0", features = ["unstable"] }
|
|
28
|
+
|
|
29
|
+
http = "1"
|
|
30
|
+
bytes = "1"
|
|
31
|
+
|
|
32
|
+
tokio = { version = "1", features = ["net", "time", "rt", "rt-multi-thread", "macros"] }
|
|
33
|
+
|
|
34
|
+
tokio-socks = { version = "0.5", optional = true }
|
|
35
|
+
|
|
36
|
+
brotli = "8"
|
|
37
|
+
flate2 = "1"
|
|
38
|
+
zstd = "0.13"
|
|
39
|
+
|
|
40
|
+
webpki-root-certs = "1"
|
|
41
|
+
|
|
42
|
+
serde = { version = "1", features = ["derive"] }
|
|
43
|
+
serde_json = "1"
|
|
44
|
+
|
|
45
|
+
httparse = "1"
|
|
46
|
+
|
|
47
|
+
tungstenite = "0.24"
|
|
48
|
+
tokio-tungstenite = { version = "0.24", default-features = false }
|
|
49
|
+
|
|
50
|
+
futures-util = { version = "0.3", default-features = false, features = ["sink"] }
|
|
51
|
+
|
|
52
|
+
hickory-proto = { version = "0.25", optional = true }
|
|
53
|
+
hickory-resolver = { version = "0.25", optional = true, default-features = false, features = [
|
|
54
|
+
"system-config",
|
|
55
|
+
"tokio",
|
|
56
|
+
] }
|
|
57
|
+
|
|
58
|
+
rand = "0.9"
|
|
59
|
+
|
|
60
|
+
base64 = "0.22"
|
|
61
|
+
|
|
62
|
+
encoding_rs = "0.8"
|
|
63
|
+
|
|
64
|
+
url = "2"
|
|
65
|
+
percent-encoding = "2"
|
|
66
|
+
psl = "2"
|
|
67
|
+
thiserror = "2"
|
|
68
|
+
lru = "0.16"
|
|
69
|
+
|
|
70
|
+
[lints]
|
|
71
|
+
workspace = true
|
|
72
|
+
|
|
73
|
+
[dev-dependencies]
|
|
74
|
+
tokio = { version = "1", features = ["full", "test-util"] }
|
|
75
|
+
tempfile = "3"
|
|
76
|
+
hickory-proto = "0.25"
|
|
77
|
+
toml = "0.9"
|
|
78
|
+
koon-core = { path = ".", features = ["test-util"] }
|
|
@@ -5,16 +5,11 @@ use http::Uri;
|
|
|
5
5
|
|
|
6
6
|
use crate::error::Error;
|
|
7
7
|
|
|
8
|
-
/// How long an alternative service stays marked broken after its first failure; doubles with every
|
|
9
|
-
/// further failure (Chrome: 5 minutes, up to 48 hours).
|
|
10
8
|
const BROKEN_INITIAL: Duration = Duration::from_secs(300);
|
|
11
9
|
const BROKEN_MAX: Duration = Duration::from_secs(48 * 3600);
|
|
12
10
|
|
|
13
|
-
/// Most origins kept per map; above it, expired entries go first, then the ones that expire soonest
|
|
14
|
-
/// (Chrome keeps 1000 alternative services).
|
|
15
11
|
const MAX_ENTRIES: usize = 1000;
|
|
16
12
|
|
|
17
|
-
/// Cached Alt-Svc entry for HTTP/3 discovery.
|
|
18
13
|
pub(super) struct AltSvcEntry {
|
|
19
14
|
pub(super) h3_port: u16,
|
|
20
15
|
pub(super) expires: Instant,
|
|
@@ -25,17 +20,12 @@ struct Broken {
|
|
|
25
20
|
failures: u32,
|
|
26
21
|
}
|
|
27
22
|
|
|
28
|
-
/// Known HTTP/3 alternatives per origin, and the ones that failed.
|
|
29
23
|
#[derive(Default)]
|
|
30
24
|
pub(super) struct AltSvcCache {
|
|
31
25
|
entries: HashMap<(String, u16), AltSvcEntry>,
|
|
32
26
|
broken: HashMap<(String, u16), Broken>,
|
|
33
27
|
}
|
|
34
28
|
|
|
35
|
-
/// Make room for one more entry in `map` up to `limit`: drop the expired ones, then the one
|
|
36
|
-
/// expiring first. Shared by every bounded, TTL-evicted map in the client (this cache's own two,
|
|
37
|
-
/// plus [`connection::HostCache`](super::connection::HostCache)) so the eviction algorithm exists
|
|
38
|
-
/// once instead of once per map.
|
|
39
29
|
pub(super) fn make_room<K: Eq + std::hash::Hash + Clone, V>(
|
|
40
30
|
map: &mut HashMap<K, V>,
|
|
41
31
|
limit: usize,
|
|
@@ -58,7 +48,6 @@ pub(super) fn make_room<K: Eq + std::hash::Hash + Clone, V>(
|
|
|
58
48
|
}
|
|
59
49
|
|
|
60
50
|
impl AltSvcCache {
|
|
61
|
-
/// Mark the HTTP/3 alternative of an origin broken after a failure.
|
|
62
51
|
pub(super) fn mark_broken(&mut self, host: &str, port: u16) {
|
|
63
52
|
let key = (host.to_string(), port);
|
|
64
53
|
if !self.broken.contains_key(&key) {
|
|
@@ -76,8 +65,6 @@ impl AltSvcCache {
|
|
|
76
65
|
broken.until = Instant::now() + delay;
|
|
77
66
|
}
|
|
78
67
|
|
|
79
|
-
/// The HTTP/3 alternative of an origin worked: forget its failures, as Chrome's
|
|
80
|
-
/// `HttpServerProperties::ConfirmAlternativeService` does.
|
|
81
68
|
pub(super) fn confirm(&mut self, host: &str, port: u16) {
|
|
82
69
|
self.broken.remove(&(host.to_string(), port));
|
|
83
70
|
}
|
|
@@ -90,14 +77,10 @@ impl AltSvcCache {
|
|
|
90
77
|
}
|
|
91
78
|
}
|
|
92
79
|
|
|
93
|
-
/// Check if a status code is a redirect.
|
|
94
80
|
pub(super) fn is_redirect(status: u16) -> bool {
|
|
95
81
|
matches!(status, 301 | 302 | 303 | 307 | 308)
|
|
96
82
|
}
|
|
97
83
|
|
|
98
|
-
/// Resolve a redirect Location against the current URL (RFC 3986 §5 via the WHATWG URL parser):
|
|
99
|
-
/// relative paths, query-only and dot segments, protocol-relative URLs, and non-ASCII characters
|
|
100
|
-
/// are handled like in a browser. The fragment is dropped.
|
|
101
84
|
pub(super) fn resolve_redirect(base: &Uri, location: &str) -> Result<Uri, Error> {
|
|
102
85
|
let base = url::Url::parse(&base.to_string())?;
|
|
103
86
|
let mut next = base.join(location.trim())?;
|
|
@@ -113,7 +96,6 @@ pub(super) fn resolve_redirect(base: &Uri, location: &str) -> Result<Uri, Error>
|
|
|
113
96
|
.map_err(|_| Error::Url(url::ParseError::InvalidDomainCharacter))
|
|
114
97
|
}
|
|
115
98
|
|
|
116
|
-
/// Parse `ma=SECONDS` from an Alt-Svc entry.
|
|
117
99
|
fn parse_alt_svc_max_age(entry: &str) -> Option<u64> {
|
|
118
100
|
entry.split(';').find_map(|part| {
|
|
119
101
|
part.trim()
|
|
@@ -123,13 +105,10 @@ fn parse_alt_svc_max_age(entry: &str) -> Option<u64> {
|
|
|
123
105
|
}
|
|
124
106
|
|
|
125
107
|
impl super::Client {
|
|
126
|
-
/// Whether the profile switches to HTTP/3 when a server advertises it with Alt-Svc.
|
|
127
108
|
pub(super) fn follows_alt_svc(&self) -> bool {
|
|
128
109
|
self.profile.quic.as_ref().is_some_and(|quic| quic.alt_svc)
|
|
129
110
|
}
|
|
130
111
|
|
|
131
|
-
/// Whether the profile discovers HTTP/3 from a host's DNS HTTPS record (see
|
|
132
|
-
/// [`QuicConfig::https_rr`](crate::quic::QuicConfig::https_rr)).
|
|
133
112
|
pub(super) fn follows_https_rr(&self) -> bool {
|
|
134
113
|
self.profile
|
|
135
114
|
.quic
|
|
@@ -137,7 +116,6 @@ impl super::Client {
|
|
|
137
116
|
.is_some_and(|quic| quic.https_rr && (!quic.https_rr_doh_only || self.uses_doh()))
|
|
138
117
|
}
|
|
139
118
|
|
|
140
|
-
/// Whether a [`DohResolver`](crate::dns::DohResolver) is configured.
|
|
141
119
|
fn uses_doh(&self) -> bool {
|
|
142
120
|
#[cfg(feature = "doh")]
|
|
143
121
|
return self.doh_resolver.is_some();
|
|
@@ -145,10 +123,6 @@ impl super::Client {
|
|
|
145
123
|
false
|
|
146
124
|
}
|
|
147
125
|
|
|
148
|
-
/// Whether the profile's QUIC stack is Apple's: it opens an HTTP/3 connection found through a
|
|
149
|
-
/// DNS HTTPS record directly, without racing TCP like Chrome and Firefox do for an
|
|
150
|
-
/// Alt-Svc-style alternative (`connect_direct_quic` in `execute.rs`), and it prefers the
|
|
151
|
-
/// record's address hints over a normal lookup (`hinted_addresses` in `connection.rs`).
|
|
152
126
|
pub(super) fn quic_stack_is_apple(&self) -> bool {
|
|
153
127
|
matches!(
|
|
154
128
|
self.profile.quic.as_ref().map(|q| q.stack),
|
|
@@ -156,7 +130,6 @@ impl super::Client {
|
|
|
156
130
|
)
|
|
157
131
|
}
|
|
158
132
|
|
|
159
|
-
/// The HTTP/3 port advertised for an origin, unless expired or broken.
|
|
160
133
|
pub(super) fn alt_svc_h3_port(&self, host: &str, port: u16) -> Option<u16> {
|
|
161
134
|
if self.h3_broken(host, port) {
|
|
162
135
|
return None;
|
|
@@ -169,8 +142,6 @@ impl super::Client {
|
|
|
169
142
|
.map(|e| e.h3_port)
|
|
170
143
|
}
|
|
171
144
|
|
|
172
|
-
/// Whether the HTTP/3 alternative of an origin recently failed: checked before racing QUIC
|
|
173
|
-
/// again, whether it was learned from Alt-Svc or from a DNS HTTPS record.
|
|
174
145
|
pub(super) fn h3_broken(&self, host: &str, port: u16) -> bool {
|
|
175
146
|
let cache = crate::util::lock_recover(&self.alt_svc);
|
|
176
147
|
cache
|
|
@@ -179,20 +150,15 @@ impl super::Client {
|
|
|
179
150
|
.is_some_and(|b| b.until > Instant::now())
|
|
180
151
|
}
|
|
181
152
|
|
|
182
|
-
/// Mark the HTTP/3 alternative of an origin broken after a failure.
|
|
183
153
|
pub(super) fn mark_alt_svc_broken(&self, host: &str, port: u16) {
|
|
184
154
|
crate::util::lock_recover(&self.alt_svc).mark_broken(host, port);
|
|
185
155
|
}
|
|
186
156
|
|
|
187
|
-
/// Record an Alt-Svc header from a response (Chrome processes it on every response of a secure
|
|
188
|
-
/// origin, whichever connection it came on). New connections to the origin will try HTTP/3; the
|
|
189
|
-
/// current connection keeps serving requests, as in Chrome.
|
|
190
157
|
pub(super) fn record_alt_svc(&self, host: &str, port: u16, headers: &[(String, String)]) {
|
|
191
158
|
for (name, value) in headers {
|
|
192
159
|
if !name.eq_ignore_ascii_case("alt-svc") {
|
|
193
160
|
continue;
|
|
194
161
|
}
|
|
195
|
-
// Held for the rest of the loop body, which is exactly as long as it's needed.
|
|
196
162
|
#[allow(clippy::significant_drop_tightening)]
|
|
197
163
|
let mut cache = crate::util::lock_recover(&self.alt_svc);
|
|
198
164
|
let key = (host.to_string(), port);
|
|
@@ -202,7 +168,6 @@ impl super::Client {
|
|
|
202
168
|
}
|
|
203
169
|
for part in value.split(',') {
|
|
204
170
|
let part = part.trim();
|
|
205
|
-
// Only same-host alternatives: h3=":PORT"
|
|
206
171
|
let Some(rest) = part.strip_prefix("h3=\":") else {
|
|
207
172
|
continue;
|
|
208
173
|
};
|
|
@@ -213,7 +178,6 @@ impl super::Client {
|
|
|
213
178
|
continue;
|
|
214
179
|
};
|
|
215
180
|
let max_age = parse_alt_svc_max_age(part).unwrap_or(86400);
|
|
216
|
-
// `ma=` near u64::MAX would overflow Instant + Duration.
|
|
217
181
|
let expires = Instant::now()
|
|
218
182
|
.checked_add(Duration::from_secs(max_age))
|
|
219
183
|
.unwrap_or_else(|| Instant::now() + Duration::from_secs(86400));
|
|
@@ -223,59 +187,3 @@ impl super::Client {
|
|
|
223
187
|
}
|
|
224
188
|
}
|
|
225
189
|
}
|
|
226
|
-
|
|
227
|
-
#[cfg(test)]
|
|
228
|
-
mod tests {
|
|
229
|
-
use super::*;
|
|
230
|
-
|
|
231
|
-
fn resolve(base: &str, location: &str) -> String {
|
|
232
|
-
resolve_redirect(&base.parse().unwrap(), location)
|
|
233
|
-
.unwrap()
|
|
234
|
-
.to_string()
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
#[test]
|
|
238
|
-
fn test_resolve_redirect() {
|
|
239
|
-
assert_eq!(resolve("https://a.com/x/y", "/z"), "https://a.com/z");
|
|
240
|
-
assert_eq!(resolve("https://a.com/x/y", "z"), "https://a.com/x/z");
|
|
241
|
-
assert_eq!(
|
|
242
|
-
resolve("https://a.com/x/y", "?p=2"),
|
|
243
|
-
"https://a.com/x/y?p=2"
|
|
244
|
-
);
|
|
245
|
-
assert_eq!(resolve("https://a.com/x/y/", "../z"), "https://a.com/x/z");
|
|
246
|
-
assert_eq!(resolve("https://a.com/x", "//b.com/p"), "https://b.com/p");
|
|
247
|
-
assert_eq!(
|
|
248
|
-
resolve("https://a.com/x", "HTTPS://B.com/p"),
|
|
249
|
-
"https://b.com/p"
|
|
250
|
-
);
|
|
251
|
-
assert_eq!(resolve("https://a.com/x", "/p#frag"), "https://a.com/p");
|
|
252
|
-
assert_eq!(resolve("https://a.com/x", "/ü"), "https://a.com/%C3%BC");
|
|
253
|
-
let err = resolve_redirect(&"https://a.com/".parse().unwrap(), "ftp://a.com/").unwrap_err();
|
|
254
|
-
assert!(matches!(err, Error::UnsupportedScheme(_)));
|
|
255
|
-
assert!(!err.is_retryable());
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
#[test]
|
|
259
|
-
fn test_cache_is_bounded() {
|
|
260
|
-
let mut cache = AltSvcCache::default();
|
|
261
|
-
for i in 0..MAX_ENTRIES + 5 {
|
|
262
|
-
let key = (format!("h{i}.test"), 443);
|
|
263
|
-
cache.insert(
|
|
264
|
-
key.clone(),
|
|
265
|
-
AltSvcEntry {
|
|
266
|
-
h3_port: 443,
|
|
267
|
-
expires: Instant::now() + Duration::from_secs(60 + i as u64),
|
|
268
|
-
},
|
|
269
|
-
);
|
|
270
|
-
cache.mark_broken(&key.0, key.1);
|
|
271
|
-
}
|
|
272
|
-
assert_eq!(cache.entries.len(), MAX_ENTRIES);
|
|
273
|
-
assert_eq!(cache.broken.len(), MAX_ENTRIES);
|
|
274
|
-
// The newest survive.
|
|
275
|
-
assert!(
|
|
276
|
-
cache
|
|
277
|
-
.entries
|
|
278
|
-
.contains_key(&(format!("h{MAX_ENTRIES}.test"), 443))
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
}
|