koon 2.1.0__tar.gz → 2.2.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.
Files changed (101) hide show
  1. {koon-2.1.0 → koon-2.2.0}/Cargo.lock +4 -4
  2. {koon-2.1.0 → koon-2.2.0}/Cargo.toml +1 -1
  3. {koon-2.1.0 → koon-2.2.0}/PKG-INFO +9 -6
  4. {koon-2.1.0 → koon-2.2.0}/README.md +8 -5
  5. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/cookies.rs +3 -3
  6. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/mod.rs +5 -4
  7. {koon-2.1.0 → koon-2.2.0}/crates/core/src/cookie.rs +31 -9
  8. {koon-2.1.0 → koon-2.2.0}/crates/core/src/http1.rs +11 -3
  9. {koon-2.1.0 → koon-2.2.0}/pyproject.toml +1 -1
  10. {koon-2.1.0 → koon-2.2.0}/crates/core/Cargo.toml +0 -0
  11. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/alt_svc.rs +0 -0
  12. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/blink_header_map.rs +0 -0
  13. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/blocked.rs +0 -0
  14. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/body.rs +0 -0
  15. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/cf_header_dict.rs +0 -0
  16. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/client_hints.rs +0 -0
  17. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/connection.rs +0 -0
  18. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/execute.rs +0 -0
  19. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/h1.rs +0 -0
  20. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/h2.rs +0 -0
  21. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/h3.rs +0 -0
  22. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/headers/context.rs +0 -0
  23. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/headers/fetch_metadata.rs +0 -0
  24. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/headers/mod.rs +0 -0
  25. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/headers/order.rs +0 -0
  26. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/headers/order_tables.rs +0 -0
  27. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/headers/safari_map.rs +0 -0
  28. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/headers/util.rs +0 -0
  29. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/headers/websocket.rs +0 -0
  30. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/options.rs +0 -0
  31. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/request_body.rs +0 -0
  32. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/response.rs +0 -0
  33. {koon-2.1.0 → koon-2.2.0}/crates/core/src/client/ws.rs +0 -0
  34. {koon-2.1.0 → koon-2.2.0}/crates/core/src/dns/cache.rs +0 -0
  35. {koon-2.1.0 → koon-2.2.0}/crates/core/src/dns/mod.rs +0 -0
  36. {koon-2.1.0 → koon-2.2.0}/crates/core/src/dns/native.rs +0 -0
  37. {koon-2.1.0 → koon-2.2.0}/crates/core/src/dns/resolver.rs +0 -0
  38. {koon-2.1.0 → koon-2.2.0}/crates/core/src/error.rs +0 -0
  39. {koon-2.1.0 → koon-2.2.0}/crates/core/src/http2/config.rs +0 -0
  40. {koon-2.1.0 → koon-2.2.0}/crates/core/src/http2/mod.rs +0 -0
  41. {koon-2.1.0 → koon-2.2.0}/crates/core/src/lib.rs +0 -0
  42. {koon-2.1.0 → koon-2.2.0}/crates/core/src/multipart.rs +0 -0
  43. {koon-2.1.0 → koon-2.2.0}/crates/core/src/options/doc.rs +0 -0
  44. {koon-2.1.0 → koon-2.2.0}/crates/core/src/options/mod.rs +0 -0
  45. {koon-2.1.0 → koon-2.2.0}/crates/core/src/options/table.rs +0 -0
  46. {koon-2.1.0 → koon-2.2.0}/crates/core/src/pool.rs +0 -0
  47. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/accept_language/mod.rs +0 -0
  48. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/accept_language/tables.rs +0 -0
  49. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/brave.rs +0 -0
  50. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/chrome/client_hints.rs +0 -0
  51. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/chrome/headers.rs +0 -0
  52. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/chrome/http2.rs +0 -0
  53. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/chrome/mod.rs +0 -0
  54. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/chrome/quic.rs +0 -0
  55. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/chrome/tls.rs +0 -0
  56. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/edge.rs +0 -0
  57. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/firefox.rs +0 -0
  58. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/mod.rs +0 -0
  59. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/okhttp.rs +0 -0
  60. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/opera.rs +0 -0
  61. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/opera_mobile.rs +0 -0
  62. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/releases.rs +0 -0
  63. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/safari/headers.rs +0 -0
  64. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/safari/http2.rs +0 -0
  65. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/safari/mod.rs +0 -0
  66. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/safari/quic.rs +0 -0
  67. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/safari/tls.rs +0 -0
  68. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/safari/versions.rs +0 -0
  69. {koon-2.1.0 → koon-2.2.0}/crates/core/src/profile/samsung.rs +0 -0
  70. {koon-2.1.0 → koon-2.2.0}/crates/core/src/proxy/ca.rs +0 -0
  71. {koon-2.1.0 → koon-2.2.0}/crates/core/src/proxy/config.rs +0 -0
  72. {koon-2.1.0 → koon-2.2.0}/crates/core/src/proxy/mod.rs +0 -0
  73. {koon-2.1.0 → koon-2.2.0}/crates/core/src/proxy/server.rs +0 -0
  74. {koon-2.1.0 → koon-2.2.0}/crates/core/src/quic/config.rs +0 -0
  75. {koon-2.1.0 → koon-2.2.0}/crates/core/src/quic/mod.rs +0 -0
  76. {koon-2.1.0 → koon-2.2.0}/crates/core/src/quic/transport.rs +0 -0
  77. {koon-2.1.0 → koon-2.2.0}/crates/core/src/streaming.rs +0 -0
  78. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/cert_compression.rs +0 -0
  79. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/config.rs +0 -0
  80. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/connector.rs +0 -0
  81. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/ech_grease.rs +0 -0
  82. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/keylog.rs +0 -0
  83. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/mod.rs +0 -0
  84. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/root_store/chrome_root_store.rs +0 -0
  85. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/root_store/mod.rs +0 -0
  86. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/session_cache.rs +0 -0
  87. {koon-2.1.0 → koon-2.2.0}/crates/core/src/tls/sigalgs.rs +0 -0
  88. {koon-2.1.0 → koon-2.2.0}/crates/core/src/util.rs +0 -0
  89. {koon-2.1.0 → koon-2.2.0}/crates/core/src/verify/references.rs +0 -0
  90. {koon-2.1.0 → koon-2.2.0}/crates/core/src/verify.rs +0 -0
  91. {koon-2.1.0 → koon-2.2.0}/crates/core/src/websocket.rs +0 -0
  92. {koon-2.1.0 → koon-2.2.0}/crates/python/Cargo.toml +0 -0
  93. {koon-2.1.0 → koon-2.2.0}/crates/python/src/lib.rs +0 -0
  94. {koon-2.1.0 → koon-2.2.0}/python/koon/__init__.py +0 -0
  95. {koon-2.1.0 → koon-2.2.0}/python/koon/__init__.pyi +0 -0
  96. {koon-2.1.0 → koon-2.2.0}/python/koon/_adapter.py +0 -0
  97. {koon-2.1.0 → koon-2.2.0}/python/koon/httpx.py +0 -0
  98. {koon-2.1.0 → koon-2.2.0}/python/koon/httpx.pyi +0 -0
  99. {koon-2.1.0 → koon-2.2.0}/python/koon/py.typed +0 -0
  100. {koon-2.1.0 → koon-2.2.0}/python/koon/requests.py +0 -0
  101. {koon-2.1.0 → koon-2.2.0}/python/koon/requests.pyi +0 -0
@@ -1028,7 +1028,7 @@ dependencies = [
1028
1028
 
1029
1029
  [[package]]
1030
1030
  name = "koon-cli"
1031
- version = "2.1.0"
1031
+ version = "2.2.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.1.0"
1045
+ version = "2.2.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.1.0"
1085
+ version = "2.2.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.1.0"
1098
+ version = "2.2.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.1.0"
9
+ version = "2.2.0"
10
10
  edition = "2024"
11
11
  rust-version = "1.85"
12
12
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koon
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: Implementation :: CPython
@@ -65,8 +65,8 @@ pip install "koon[requests]" # with the requests adapter's dependency
65
65
  **R**
66
66
  ```r
67
67
  # Windows, or macOS on Apple silicon, with R 4.6: the prebuilt package of the release
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
68
+ install.packages("https://github.com/scrape-hub/koon/releases/download/v2.2.0/koon_2.2.0.zip", repos = NULL) # Windows
69
+ install.packages("https://github.com/scrape-hub/koon/releases/download/v2.2.0/koon_2.2.0.tgz", repos = NULL) # macOS
70
70
 
71
71
  # Other platforms and R versions build from source: Rust 1.85+ and CMake, on Windows
72
72
  # also Rtools and `rustup target add x86_64-pc-windows-gnu`
@@ -274,11 +274,13 @@ console.log(r1.remoteAddress); // peer IP (the proxy when one i
274
274
  console.log(r1.blockedBy); // null, or e.g. 'cloudflare' when bot protection answered
275
275
  console.log(r1.bytesSent, r1.bytesReceived); // bandwidth per request
276
276
 
277
- // Per-request headers, timeout, proxy and hooks
277
+ // Per-request headers, timeout, proxy, hooks and cancellation
278
+ const controller = new AbortController();
278
279
  const r7 = await client.get('https://httpbin.org/get', {
279
280
  headers: [['Authorization', 'Bearer token']], // pairs or an object
280
281
  timeout: 2.5, // 2.5 s for this request only
281
282
  proxy: 'http://user:pass@other-proxy:8080', // override proxy for this request
283
+ signal: controller.signal, // controller.abort() cancels it, uploads too
282
284
  onResponse: (status, url) => console.log(status, url),
283
285
  });
284
286
 
@@ -318,8 +320,9 @@ console.log(stream.status);
318
320
  for await (const chunk of stream) process.stdout.write(chunk); // or nextChunk() / collect()
319
321
  // The body arrives decoded (gzip, br, ...); { decode: false } in the options
320
322
  // gives the bytes as sent. cancel() drops the rest of the body; leaving for
321
- // await early does too. blockedBy(stream, body) names a bot protection page
322
- // from the body read (its first 400 KB suffice).
323
+ // await early and an abort of the request's signal do too. blockedBy(stream,
324
+ // body) names a bot protection page from the body read (its first 400 KB
325
+ // suffice).
323
326
 
324
327
  // Multipart upload
325
328
  await client.postMultipart('https://httpbin.org/post', [
@@ -27,8 +27,8 @@ pip install "koon[requests]" # with the requests adapter's dependency
27
27
  **R**
28
28
  ```r
29
29
  # Windows, or macOS on Apple silicon, with R 4.6: the prebuilt package of the release
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
30
+ install.packages("https://github.com/scrape-hub/koon/releases/download/v2.2.0/koon_2.2.0.zip", repos = NULL) # Windows
31
+ install.packages("https://github.com/scrape-hub/koon/releases/download/v2.2.0/koon_2.2.0.tgz", repos = NULL) # macOS
32
32
 
33
33
  # Other platforms and R versions build from source: Rust 1.85+ and CMake, on Windows
34
34
  # also Rtools and `rustup target add x86_64-pc-windows-gnu`
@@ -236,11 +236,13 @@ console.log(r1.remoteAddress); // peer IP (the proxy when one i
236
236
  console.log(r1.blockedBy); // null, or e.g. 'cloudflare' when bot protection answered
237
237
  console.log(r1.bytesSent, r1.bytesReceived); // bandwidth per request
238
238
 
239
- // Per-request headers, timeout, proxy and hooks
239
+ // Per-request headers, timeout, proxy, hooks and cancellation
240
+ const controller = new AbortController();
240
241
  const r7 = await client.get('https://httpbin.org/get', {
241
242
  headers: [['Authorization', 'Bearer token']], // pairs or an object
242
243
  timeout: 2.5, // 2.5 s for this request only
243
244
  proxy: 'http://user:pass@other-proxy:8080', // override proxy for this request
245
+ signal: controller.signal, // controller.abort() cancels it, uploads too
244
246
  onResponse: (status, url) => console.log(status, url),
245
247
  });
246
248
 
@@ -280,8 +282,9 @@ console.log(stream.status);
280
282
  for await (const chunk of stream) process.stdout.write(chunk); // or nextChunk() / collect()
281
283
  // The body arrives decoded (gzip, br, ...); { decode: false } in the options
282
284
  // gives the bytes as sent. cancel() drops the rest of the body; leaving for
283
- // await early does too. blockedBy(stream, body) names a bot protection page
284
- // from the body read (its first 400 KB suffice).
285
+ // await early and an abort of the request's signal do too. blockedBy(stream,
286
+ // body) names a bot protection page from the body read (its first 400 KB
287
+ // suffice).
285
288
 
286
289
  // Multipart upload
287
290
  await client.postMultipart('https://httpbin.org/post', [
@@ -67,13 +67,13 @@ impl Client {
67
67
  }
68
68
 
69
69
  /// Return a snapshot of every cookie currently stored in the jar (e.g. to export back into a
70
- /// browser via Playwright/CDP `addCookies()`).
70
+ /// browser via Playwright/CDP `addCookies()`), after dropping the expired ones.
71
71
  ///
72
72
  /// Returns an empty `Vec` if the cookie jar is disabled, same as an empty jar: there's nothing
73
73
  /// to export either way.
74
74
  pub fn cookies(&self) -> Vec<Cookie> {
75
75
  match &self.cookie_jar {
76
- Some(jar) => crate::util::lock_recover(jar).cookies().to_vec(),
76
+ Some(jar) => crate::util::lock_recover(jar).live_cookies().to_vec(),
77
77
  None => Vec::new(),
78
78
  }
79
79
  }
@@ -83,7 +83,7 @@ impl Client {
83
83
  pub fn cookie_params(&self) -> Vec<CookieParams> {
84
84
  match &self.cookie_jar {
85
85
  Some(jar) => crate::util::lock_recover(jar)
86
- .cookies()
86
+ .live_cookies()
87
87
  .iter()
88
88
  .map(CookieParams::from)
89
89
  .collect(),
@@ -852,13 +852,13 @@ impl Client {
852
852
  self.send(Method::POST, url, body, options).await
853
853
  }
854
854
 
855
- /// Serializes the session, cookies and TLS sessions, to JSON. [`Error::Json`] if serialization
856
- /// fails.
855
+ /// Serializes the session, cookies (expired ones dropped) and TLS sessions, to JSON.
856
+ /// [`Error::Json`] if serialization fails.
857
857
  pub fn save_session(&self) -> Result<String, Error> {
858
858
  let cookies = self
859
859
  .cookie_jar
860
860
  .as_ref()
861
- .map(|jar| crate::util::lock_recover(jar).cookies().to_vec());
861
+ .map(|jar| crate::util::lock_recover(jar).live_cookies().to_vec());
862
862
 
863
863
  let tls_sessions = self
864
864
  .session_cache
@@ -875,7 +875,8 @@ impl Client {
875
875
 
876
876
  /// Loads a session saved with [`save_session`](Self::save_session): its cookies replace the
877
877
  /// jar's, its TLS sessions are added. Parts the client has disabled are skipped, and so are
878
- /// cookies [`CookieJar::from_cookies`] leaves out (such as one for a public suffix).
878
+ /// cookies [`CookieJar::from_cookies`] leaves out (such as an expired one or one for a public
879
+ /// suffix).
879
880
  /// [`Error::Json`] if `json` is not a saved session.
880
881
  pub fn load_session(&self, json: &str) -> Result<(), Error> {
881
882
  let export: SessionExport = serde_json::from_str(json).map_err(Error::Json)?;
@@ -222,6 +222,12 @@ pub struct Cookie {
222
222
  pub partition_key: Option<String>,
223
223
  }
224
224
 
225
+ impl Cookie {
226
+ pub(crate) fn is_expired(&self, now: SystemTime) -> bool {
227
+ self.expires.is_some_and(|exp| exp <= now)
228
+ }
229
+ }
230
+
225
231
  fn serialize_expires<S: serde::Serializer>(
226
232
  time: &Option<SystemTime>,
227
233
  serializer: S,
@@ -353,9 +359,7 @@ impl CookieJar {
353
359
  }
354
360
 
355
361
  pub(crate) fn prune(&mut self) {
356
- let now = SystemTime::now();
357
- self.cookies
358
- .retain(|cookie| cookie.expires.is_none_or(|exp| exp > now));
362
+ self.remove_expired();
359
363
 
360
364
  let mut excess: HashMap<&str, usize> = HashMap::new();
361
365
  for cookie in &self.cookies {
@@ -459,13 +463,29 @@ impl CookieJar {
459
463
  &self.cookies
460
464
  }
461
465
 
462
- /// Serialize all cookies to a JSON string.
466
+ pub(crate) fn remove_expired(&mut self) {
467
+ let now = SystemTime::now();
468
+ self.cookies.retain(|cookie| !cookie.is_expired(now));
469
+ }
470
+
471
+ pub(crate) fn live_cookies(&mut self) -> &[Cookie] {
472
+ self.remove_expired();
473
+ &self.cookies
474
+ }
475
+
476
+ /// Serialize the cookies that have not expired to a JSON string.
463
477
  ///
464
478
  /// # Errors
465
479
  /// Returns an error if a cookie fails to serialize (never expected, since every field is a
466
480
  /// plain value serde already supports).
467
481
  pub fn to_json(&self) -> Result<String, serde_json::Error> {
468
- serde_json::to_string(&self.cookies)
482
+ let now = SystemTime::now();
483
+ let live: Vec<&Cookie> = self
484
+ .cookies
485
+ .iter()
486
+ .filter(|cookie| !cookie.is_expired(now))
487
+ .collect();
488
+ serde_json::to_string(&live)
469
489
  }
470
490
 
471
491
  /// Deserialize cookies from a JSON string, creating a new `CookieJar`. Domains are normalized
@@ -477,12 +497,14 @@ impl CookieJar {
477
497
  Ok(Self::from_cookies(serde_json::from_str(json)?))
478
498
  }
479
499
 
480
- /// Create a `CookieJar` holding `cookies` that pass the checks every other way into the jar
481
- /// applies (name and value, host name, path, no public suffix as a domain, the `__Host-` and
482
- /// `__Secure-` prefixes), with their domains normalized; the others are left out.
500
+ /// Create a `CookieJar` holding `cookies` that have not expired and pass the checks every
501
+ /// other way into the jar applies (name and value, host name, path, no public suffix as a
502
+ /// domain, the `__Host-` and `__Secure-` prefixes), with their domains normalized; the others
503
+ /// are left out.
483
504
  #[must_use]
484
505
  pub fn from_cookies(mut cookies: Vec<Cookie>) -> Self {
485
- cookies.retain_mut(|cookie| validate_imported(cookie).is_ok());
506
+ let now = SystemTime::now();
507
+ cookies.retain_mut(|cookie| !cookie.is_expired(now) && validate_imported(cookie).is_ok());
486
508
  Self { cookies }
487
509
  }
488
510
  }
@@ -11,6 +11,7 @@ use crate::error::Error;
11
11
  const READ_BUF_SIZE: usize = 32 * 1024;
12
12
  const MIN_READ_SPACE: usize = 4 * 1024;
13
13
  const MAX_MERGED_HEAD_AND_BODY: usize = 1400;
14
+ const MAX_BODY_WRITE: usize = 16 * 1024;
14
15
  pub const MAX_HEADER_SIZE: usize = 256 * 1024;
15
16
  const MAX_CHUNK_LINE: usize = 4096;
16
17
 
@@ -161,13 +162,20 @@ pub async fn write_request<S: AsyncWrite + Unpin>(
161
162
  stream.write_all(&head).await?;
162
163
  } else {
163
164
  stream.write_all(&head).await?;
164
- stream.write_all(body).await?;
165
+ write_body(stream, body).await?;
165
166
  }
166
167
  stream.flush().await?;
167
168
 
168
169
  Ok(total as u64)
169
170
  }
170
171
 
172
+ async fn write_body<S: AsyncWrite + Unpin>(stream: &mut S, body: &[u8]) -> std::io::Result<()> {
173
+ for piece in body.chunks(MAX_BODY_WRITE) {
174
+ stream.write_all(piece).await?;
175
+ }
176
+ Ok(())
177
+ }
178
+
171
179
  pub async fn write_streaming_request<S: AsyncWrite + Unpin>(
172
180
  stream: &mut S,
173
181
  method: &Method,
@@ -193,10 +201,10 @@ pub async fn write_streaming_request<S: AsyncWrite + Unpin>(
193
201
  let _ = std::io::Write::write_fmt(&mut encoded, format_args!("{:x}\r\n", chunk.len()));
194
202
  encoded.extend_from_slice(&chunk);
195
203
  encoded.extend_from_slice(b"\r\n");
196
- stream.write_all(&encoded).await?;
204
+ write_body(stream, &encoded).await?;
197
205
  written += encoded.len() as u64;
198
206
  } else {
199
- stream.write_all(&chunk).await?;
207
+ write_body(stream, &chunk).await?;
200
208
  written += chunk.len() as u64;
201
209
  }
202
210
  }
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "koon"
7
- version = "2.1.0"
7
+ version = "2.2.0"
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.11"
10
10
  license = { text = "MIT" }
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