nlcurl 0.6.0 → 0.8.0

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 (354) hide show
  1. package/README.md +143 -140
  2. package/dist/cache/groups.d.ts +75 -0
  3. package/dist/cache/groups.d.ts.map +1 -0
  4. package/dist/cache/groups.js +118 -0
  5. package/dist/cache/groups.js.map +1 -0
  6. package/dist/cache/no-vary-search.d.ts +33 -0
  7. package/dist/cache/no-vary-search.d.ts.map +1 -0
  8. package/dist/cache/no-vary-search.js +148 -0
  9. package/dist/cache/no-vary-search.js.map +1 -0
  10. package/dist/cache/range.d.ts +120 -0
  11. package/dist/cache/range.d.ts.map +1 -0
  12. package/dist/cache/range.js +193 -0
  13. package/dist/cache/range.js.map +1 -0
  14. package/dist/cache/store.d.ts +111 -0
  15. package/dist/cache/store.d.ts.map +1 -0
  16. package/dist/cache/store.js +414 -0
  17. package/dist/cache/store.js.map +1 -0
  18. package/dist/cache/types.d.ts +69 -0
  19. package/dist/cache/types.d.ts.map +1 -0
  20. package/dist/cache/types.js +2 -0
  21. package/dist/cache/types.js.map +1 -0
  22. package/dist/cli/args.d.ts +4 -37
  23. package/dist/cli/args.d.ts.map +1 -1
  24. package/dist/cli/args.js +3 -4
  25. package/dist/cli/args.js.map +1 -1
  26. package/dist/cli/index.d.ts +0 -5
  27. package/dist/cli/index.d.ts.map +1 -1
  28. package/dist/cli/index.js +1 -6
  29. package/dist/cli/index.js.map +1 -1
  30. package/dist/cli/output.d.ts +14 -20
  31. package/dist/cli/output.d.ts.map +1 -1
  32. package/dist/cli/output.js +14 -20
  33. package/dist/cli/output.js.map +1 -1
  34. package/dist/cookies/jar.d.ts +33 -31
  35. package/dist/cookies/jar.d.ts.map +1 -1
  36. package/dist/cookies/jar.js +69 -33
  37. package/dist/cookies/jar.js.map +1 -1
  38. package/dist/cookies/parser.d.ts +14 -16
  39. package/dist/cookies/parser.d.ts.map +1 -1
  40. package/dist/cookies/parser.js +30 -13
  41. package/dist/cookies/parser.js.map +1 -1
  42. package/dist/cookies/psl-data.d.ts +1 -1
  43. package/dist/cookies/psl-data.js +1 -1
  44. package/dist/cookies/public-suffix.d.ts +5 -27
  45. package/dist/cookies/public-suffix.d.ts.map +1 -1
  46. package/dist/cookies/public-suffix.js +5 -37
  47. package/dist/cookies/public-suffix.js.map +1 -1
  48. package/dist/core/auth.d.ts +30 -0
  49. package/dist/core/auth.d.ts.map +1 -0
  50. package/dist/core/auth.js +34 -0
  51. package/dist/core/auth.js.map +1 -0
  52. package/dist/core/client.d.ts +28 -40
  53. package/dist/core/client.d.ts.map +1 -1
  54. package/dist/core/client.js +34 -41
  55. package/dist/core/client.js.map +1 -1
  56. package/dist/core/errors.d.ts +64 -88
  57. package/dist/core/errors.d.ts.map +1 -1
  58. package/dist/core/errors.js +64 -88
  59. package/dist/core/errors.js.map +1 -1
  60. package/dist/core/request.d.ts +63 -85
  61. package/dist/core/request.d.ts.map +1 -1
  62. package/dist/core/response.d.ts +64 -59
  63. package/dist/core/response.d.ts.map +1 -1
  64. package/dist/core/response.js +70 -52
  65. package/dist/core/response.js.map +1 -1
  66. package/dist/core/session.d.ts +81 -70
  67. package/dist/core/session.d.ts.map +1 -1
  68. package/dist/core/session.js +198 -71
  69. package/dist/core/session.js.map +1 -1
  70. package/dist/core/validation.d.ts +44 -42
  71. package/dist/core/validation.d.ts.map +1 -1
  72. package/dist/core/validation.js +47 -58
  73. package/dist/core/validation.js.map +1 -1
  74. package/dist/dns/cache.d.ts +59 -0
  75. package/dist/dns/cache.d.ts.map +1 -0
  76. package/dist/dns/cache.js +99 -0
  77. package/dist/dns/cache.js.map +1 -0
  78. package/dist/dns/codec.d.ts +39 -0
  79. package/dist/dns/codec.d.ts.map +1 -0
  80. package/dist/dns/codec.js +238 -0
  81. package/dist/dns/codec.js.map +1 -0
  82. package/dist/dns/doh-resolver.d.ts +38 -0
  83. package/dist/dns/doh-resolver.d.ts.map +1 -0
  84. package/dist/dns/doh-resolver.js +191 -0
  85. package/dist/dns/doh-resolver.js.map +1 -0
  86. package/dist/dns/dot-resolver.d.ts +89 -0
  87. package/dist/dns/dot-resolver.d.ts.map +1 -0
  88. package/dist/dns/dot-resolver.js +158 -0
  89. package/dist/dns/dot-resolver.js.map +1 -0
  90. package/dist/dns/https-rr.d.ts +40 -0
  91. package/dist/dns/https-rr.d.ts.map +1 -0
  92. package/dist/dns/https-rr.js +109 -0
  93. package/dist/dns/https-rr.js.map +1 -0
  94. package/dist/dns/types.d.ts +82 -0
  95. package/dist/dns/types.d.ts.map +1 -0
  96. package/dist/dns/types.js +23 -0
  97. package/dist/dns/types.js.map +1 -0
  98. package/dist/fingerprints/akamai.d.ts +3 -11
  99. package/dist/fingerprints/akamai.d.ts.map +1 -1
  100. package/dist/fingerprints/akamai.js +3 -11
  101. package/dist/fingerprints/akamai.js.map +1 -1
  102. package/dist/fingerprints/database.d.ts +6 -14
  103. package/dist/fingerprints/database.d.ts.map +1 -1
  104. package/dist/fingerprints/database.js +6 -14
  105. package/dist/fingerprints/database.js.map +1 -1
  106. package/dist/fingerprints/extensions.d.ts +56 -71
  107. package/dist/fingerprints/extensions.d.ts.map +1 -1
  108. package/dist/fingerprints/extensions.js +58 -71
  109. package/dist/fingerprints/extensions.js.map +1 -1
  110. package/dist/fingerprints/ja3.d.ts +12 -30
  111. package/dist/fingerprints/ja3.d.ts.map +1 -1
  112. package/dist/fingerprints/ja3.js +12 -30
  113. package/dist/fingerprints/ja3.js.map +1 -1
  114. package/dist/fingerprints/ja4.d.ts +18 -0
  115. package/dist/fingerprints/ja4.d.ts.map +1 -0
  116. package/dist/fingerprints/ja4.js +83 -0
  117. package/dist/fingerprints/ja4.js.map +1 -0
  118. package/dist/fingerprints/profiles/chrome.d.ts +18 -21
  119. package/dist/fingerprints/profiles/chrome.d.ts.map +1 -1
  120. package/dist/fingerprints/profiles/chrome.js +35 -31
  121. package/dist/fingerprints/profiles/chrome.js.map +1 -1
  122. package/dist/fingerprints/profiles/edge.d.ts +7 -10
  123. package/dist/fingerprints/profiles/edge.d.ts.map +1 -1
  124. package/dist/fingerprints/profiles/edge.js +7 -10
  125. package/dist/fingerprints/profiles/edge.js.map +1 -1
  126. package/dist/fingerprints/profiles/firefox.d.ts +8 -11
  127. package/dist/fingerprints/profiles/firefox.d.ts.map +1 -1
  128. package/dist/fingerprints/profiles/firefox.js +8 -11
  129. package/dist/fingerprints/profiles/firefox.js.map +1 -1
  130. package/dist/fingerprints/profiles/safari.d.ts +11 -14
  131. package/dist/fingerprints/profiles/safari.d.ts.map +1 -1
  132. package/dist/fingerprints/profiles/safari.js +11 -14
  133. package/dist/fingerprints/profiles/safari.js.map +1 -1
  134. package/dist/fingerprints/profiles/tor.d.ts +5 -8
  135. package/dist/fingerprints/profiles/tor.d.ts.map +1 -1
  136. package/dist/fingerprints/profiles/tor.js +5 -8
  137. package/dist/fingerprints/profiles/tor.js.map +1 -1
  138. package/dist/fingerprints/types.d.ts +42 -73
  139. package/dist/fingerprints/types.d.ts.map +1 -1
  140. package/dist/hsts/store.d.ts +39 -0
  141. package/dist/hsts/store.d.ts.map +1 -0
  142. package/dist/hsts/store.js +163 -0
  143. package/dist/hsts/store.js.map +1 -0
  144. package/dist/hsts/types.d.ts +24 -0
  145. package/dist/hsts/types.d.ts.map +1 -0
  146. package/dist/hsts/types.js +2 -0
  147. package/dist/hsts/types.js.map +1 -0
  148. package/dist/http/alt-svc.d.ts +67 -0
  149. package/dist/http/alt-svc.d.ts.map +1 -0
  150. package/dist/http/alt-svc.js +186 -0
  151. package/dist/http/alt-svc.js.map +1 -0
  152. package/dist/http/early-hints.d.ts +23 -0
  153. package/dist/http/early-hints.d.ts.map +1 -0
  154. package/dist/http/early-hints.js +33 -0
  155. package/dist/http/early-hints.js.map +1 -0
  156. package/dist/http/form-data.d.ts +17 -35
  157. package/dist/http/form-data.d.ts.map +1 -1
  158. package/dist/http/form-data.js +12 -34
  159. package/dist/http/form-data.js.map +1 -1
  160. package/dist/http/h1/client.d.ts +14 -26
  161. package/dist/http/h1/client.d.ts.map +1 -1
  162. package/dist/http/h1/client.js +29 -22
  163. package/dist/http/h1/client.js.map +1 -1
  164. package/dist/http/h1/encoder.d.ts +10 -17
  165. package/dist/http/h1/encoder.d.ts.map +1 -1
  166. package/dist/http/h1/encoder.js +10 -17
  167. package/dist/http/h1/encoder.js.map +1 -1
  168. package/dist/http/h1/parser.d.ts +22 -59
  169. package/dist/http/h1/parser.d.ts.map +1 -1
  170. package/dist/http/h1/parser.js +15 -47
  171. package/dist/http/h1/parser.js.map +1 -1
  172. package/dist/http/h2/client.d.ts +18 -59
  173. package/dist/http/h2/client.d.ts.map +1 -1
  174. package/dist/http/h2/client.js +29 -64
  175. package/dist/http/h2/client.js.map +1 -1
  176. package/dist/http/h2/frames.d.ts +53 -84
  177. package/dist/http/h2/frames.d.ts.map +1 -1
  178. package/dist/http/h2/frames.js +48 -76
  179. package/dist/http/h2/frames.js.map +1 -1
  180. package/dist/http/h2/hpack.d.ts +16 -35
  181. package/dist/http/h2/hpack.d.ts.map +1 -1
  182. package/dist/http/h2/hpack.js +16 -35
  183. package/dist/http/h2/hpack.js.map +1 -1
  184. package/dist/http/h3/detection.d.ts +15 -0
  185. package/dist/http/h3/detection.d.ts.map +1 -0
  186. package/dist/http/h3/detection.js +41 -0
  187. package/dist/http/h3/detection.js.map +1 -0
  188. package/dist/http/negotiator.d.ts +43 -33
  189. package/dist/http/negotiator.d.ts.map +1 -1
  190. package/dist/http/negotiator.js +99 -41
  191. package/dist/http/negotiator.js.map +1 -1
  192. package/dist/http/pool.d.ts +34 -64
  193. package/dist/http/pool.d.ts.map +1 -1
  194. package/dist/http/pool.js +22 -41
  195. package/dist/http/pool.js.map +1 -1
  196. package/dist/http/resumable-upload.d.ts +76 -0
  197. package/dist/http/resumable-upload.d.ts.map +1 -0
  198. package/dist/http/resumable-upload.js +104 -0
  199. package/dist/http/resumable-upload.js.map +1 -0
  200. package/dist/http/trailers.d.ts +29 -0
  201. package/dist/http/trailers.d.ts.map +1 -0
  202. package/dist/http/trailers.js +57 -0
  203. package/dist/http/trailers.js.map +1 -0
  204. package/dist/index.d.ts +36 -8
  205. package/dist/index.d.ts.map +1 -1
  206. package/dist/index.js +32 -1
  207. package/dist/index.js.map +1 -1
  208. package/dist/middleware/interceptor.d.ts +13 -32
  209. package/dist/middleware/interceptor.d.ts.map +1 -1
  210. package/dist/middleware/interceptor.js +11 -16
  211. package/dist/middleware/interceptor.js.map +1 -1
  212. package/dist/middleware/rate-limiter.d.ts +8 -17
  213. package/dist/middleware/rate-limiter.d.ts.map +1 -1
  214. package/dist/middleware/rate-limiter.js +15 -12
  215. package/dist/middleware/rate-limiter.js.map +1 -1
  216. package/dist/middleware/retry-after.d.ts +15 -0
  217. package/dist/middleware/retry-after.d.ts.map +1 -0
  218. package/dist/middleware/retry-after.js +36 -0
  219. package/dist/middleware/retry-after.js.map +1 -0
  220. package/dist/middleware/retry.d.ts +9 -18
  221. package/dist/middleware/retry.d.ts.map +1 -1
  222. package/dist/middleware/retry.js +12 -9
  223. package/dist/middleware/retry.js.map +1 -1
  224. package/dist/proxy/auth.d.ts +73 -0
  225. package/dist/proxy/auth.d.ts.map +1 -0
  226. package/dist/proxy/auth.js +128 -0
  227. package/dist/proxy/auth.js.map +1 -0
  228. package/dist/proxy/env-proxy.d.ts +11 -0
  229. package/dist/proxy/env-proxy.d.ts.map +1 -0
  230. package/dist/proxy/env-proxy.js +56 -0
  231. package/dist/proxy/env-proxy.js.map +1 -0
  232. package/dist/proxy/http-proxy.d.ts +13 -18
  233. package/dist/proxy/http-proxy.d.ts.map +1 -1
  234. package/dist/proxy/http-proxy.js +24 -14
  235. package/dist/proxy/http-proxy.js.map +1 -1
  236. package/dist/proxy/socks.d.ts +13 -20
  237. package/dist/proxy/socks.d.ts.map +1 -1
  238. package/dist/proxy/socks.js +6 -9
  239. package/dist/proxy/socks.js.map +1 -1
  240. package/dist/sse/parser.d.ts +47 -0
  241. package/dist/sse/parser.d.ts.map +1 -0
  242. package/dist/sse/parser.js +139 -0
  243. package/dist/sse/parser.js.map +1 -0
  244. package/dist/tls/constants.d.ts +15 -74
  245. package/dist/tls/constants.d.ts.map +1 -1
  246. package/dist/tls/constants.js +15 -74
  247. package/dist/tls/constants.js.map +1 -1
  248. package/dist/tls/ct.d.ts +78 -0
  249. package/dist/tls/ct.d.ts.map +1 -0
  250. package/dist/tls/ct.js +175 -0
  251. package/dist/tls/ct.js.map +1 -0
  252. package/dist/tls/early-data.d.ts +45 -0
  253. package/dist/tls/early-data.d.ts.map +1 -0
  254. package/dist/tls/early-data.js +46 -0
  255. package/dist/tls/early-data.js.map +1 -0
  256. package/dist/tls/ech.d.ts +130 -0
  257. package/dist/tls/ech.d.ts.map +1 -0
  258. package/dist/tls/ech.js +353 -0
  259. package/dist/tls/ech.js.map +1 -0
  260. package/dist/tls/keylog.d.ts +34 -0
  261. package/dist/tls/keylog.d.ts.map +1 -0
  262. package/dist/tls/keylog.js +64 -0
  263. package/dist/tls/keylog.js.map +1 -0
  264. package/dist/tls/node-engine.d.ts +15 -14
  265. package/dist/tls/node-engine.d.ts.map +1 -1
  266. package/dist/tls/node-engine.js +54 -14
  267. package/dist/tls/node-engine.js.map +1 -1
  268. package/dist/tls/ocsp.d.ts +55 -0
  269. package/dist/tls/ocsp.d.ts.map +1 -0
  270. package/dist/tls/ocsp.js +131 -0
  271. package/dist/tls/ocsp.js.map +1 -0
  272. package/dist/tls/pin-verification.d.ts +10 -0
  273. package/dist/tls/pin-verification.d.ts.map +1 -0
  274. package/dist/tls/pin-verification.js +28 -0
  275. package/dist/tls/pin-verification.js.map +1 -0
  276. package/dist/tls/session-cache.d.ts +58 -0
  277. package/dist/tls/session-cache.d.ts.map +1 -0
  278. package/dist/tls/session-cache.js +76 -0
  279. package/dist/tls/session-cache.js.map +1 -0
  280. package/dist/tls/stealth/client-hello.d.ts +34 -32
  281. package/dist/tls/stealth/client-hello.d.ts.map +1 -1
  282. package/dist/tls/stealth/client-hello.js +116 -11
  283. package/dist/tls/stealth/client-hello.js.map +1 -1
  284. package/dist/tls/stealth/engine.d.ts +5 -15
  285. package/dist/tls/stealth/engine.d.ts.map +1 -1
  286. package/dist/tls/stealth/engine.js +163 -47
  287. package/dist/tls/stealth/engine.js.map +1 -1
  288. package/dist/tls/stealth/handshake.d.ts +23 -32
  289. package/dist/tls/stealth/handshake.d.ts.map +1 -1
  290. package/dist/tls/stealth/handshake.js +112 -27
  291. package/dist/tls/stealth/handshake.js.map +1 -1
  292. package/dist/tls/stealth/key-schedule.d.ts +59 -86
  293. package/dist/tls/stealth/key-schedule.d.ts.map +1 -1
  294. package/dist/tls/stealth/key-schedule.js +46 -58
  295. package/dist/tls/stealth/key-schedule.js.map +1 -1
  296. package/dist/tls/stealth/record-layer.d.ts +52 -75
  297. package/dist/tls/stealth/record-layer.d.ts.map +1 -1
  298. package/dist/tls/stealth/record-layer.js +47 -63
  299. package/dist/tls/stealth/record-layer.js.map +1 -1
  300. package/dist/tls/stealth/tls12-handshake.d.ts +30 -0
  301. package/dist/tls/stealth/tls12-handshake.d.ts.map +1 -0
  302. package/dist/tls/stealth/tls12-handshake.js +470 -0
  303. package/dist/tls/stealth/tls12-handshake.js.map +1 -0
  304. package/dist/tls/types.d.ts +46 -48
  305. package/dist/tls/types.d.ts.map +1 -1
  306. package/dist/utils/buffer-reader.d.ts +26 -81
  307. package/dist/utils/buffer-reader.d.ts.map +1 -1
  308. package/dist/utils/buffer-reader.js +26 -81
  309. package/dist/utils/buffer-reader.js.map +1 -1
  310. package/dist/utils/buffer-writer.d.ts +30 -66
  311. package/dist/utils/buffer-writer.d.ts.map +1 -1
  312. package/dist/utils/buffer-writer.js +30 -66
  313. package/dist/utils/buffer-writer.js.map +1 -1
  314. package/dist/utils/compression.d.ts +18 -0
  315. package/dist/utils/compression.d.ts.map +1 -0
  316. package/dist/utils/compression.js +34 -0
  317. package/dist/utils/compression.js.map +1 -0
  318. package/dist/utils/dictionary-transport.d.ts +97 -0
  319. package/dist/utils/dictionary-transport.d.ts.map +1 -0
  320. package/dist/utils/dictionary-transport.js +171 -0
  321. package/dist/utils/dictionary-transport.js.map +1 -0
  322. package/dist/utils/encoding.d.ts +12 -28
  323. package/dist/utils/encoding.d.ts.map +1 -1
  324. package/dist/utils/encoding.js +77 -40
  325. package/dist/utils/encoding.js.map +1 -1
  326. package/dist/utils/happy-eyeballs.d.ts +20 -7
  327. package/dist/utils/happy-eyeballs.d.ts.map +1 -1
  328. package/dist/utils/happy-eyeballs.js +57 -25
  329. package/dist/utils/happy-eyeballs.js.map +1 -1
  330. package/dist/utils/logger.d.ts +54 -81
  331. package/dist/utils/logger.d.ts.map +1 -1
  332. package/dist/utils/logger.js +92 -64
  333. package/dist/utils/logger.js.map +1 -1
  334. package/dist/utils/tcp-fast-open.d.ts +30 -0
  335. package/dist/utils/tcp-fast-open.d.ts.map +1 -0
  336. package/dist/utils/tcp-fast-open.js +36 -0
  337. package/dist/utils/tcp-fast-open.js.map +1 -0
  338. package/dist/utils/url.d.ts +18 -25
  339. package/dist/utils/url.d.ts.map +1 -1
  340. package/dist/utils/url.js +18 -25
  341. package/dist/utils/url.js.map +1 -1
  342. package/dist/ws/client.d.ts +35 -52
  343. package/dist/ws/client.d.ts.map +1 -1
  344. package/dist/ws/client.js +92 -37
  345. package/dist/ws/client.js.map +1 -1
  346. package/dist/ws/frame.d.ts +27 -42
  347. package/dist/ws/frame.d.ts.map +1 -1
  348. package/dist/ws/frame.js +25 -37
  349. package/dist/ws/frame.js.map +1 -1
  350. package/dist/ws/permessage-deflate.d.ts +53 -0
  351. package/dist/ws/permessage-deflate.d.ts.map +1 -0
  352. package/dist/ws/permessage-deflate.js +140 -0
  353. package/dist/ws/permessage-deflate.js.map +1 -0
  354. package/package.json +62 -62
@@ -1,109 +1,79 @@
1
1
  import type { TLSSocket } from "../tls/types.js";
2
2
  import { H2Client } from "./h2/client.js";
3
3
  import type { H2Profile } from "../fingerprints/types.js";
4
- /**
5
- * Represents a single pooled connection entry, holding the TLS socket,
6
- * protocol version, and lifecycle timestamps.
7
- *
8
- * @typedef {Object} PoolEntry
9
- * @property {string} origin - Origin key in `protocol://hostname:port` form.
10
- * @property {TLSSocket} socket - The underlying TLS (or TCP) socket.
11
- * @property {'h1'|'h2'} protocol - Negotiated HTTP protocol version.
12
- * @property {H2Client} [h2Client] - HTTP/2 client instance when `protocol === 'h2'`.
13
- * @property {number} createdAt - Unix timestamp (ms) when the connection was established.
14
- * @property {number} lastUsed - Unix timestamp (ms) when the connection was last checked out.
15
- * @property {boolean} busy - `true` while an HTTP/1.1 request is in flight.
16
- */
4
+ /** A pooled connection entry. */
17
5
  export interface PoolEntry {
6
+ /** Origin key (scheme + host + port). */
18
7
  origin: string;
8
+ /** Underlying TLS socket. */
19
9
  socket: TLSSocket;
20
- protocol: "h1" | "h2";
10
+ /** Negotiated HTTP protocol version. */
11
+ protocol: "h1" | "h2" | "h3";
12
+ /** HTTP/2 multiplexing client, if this is an h2 connection. */
21
13
  h2Client?: H2Client;
14
+ /** Timestamp when the connection was created. */
22
15
  createdAt: number;
16
+ /** Timestamp when the connection was last used. */
23
17
  lastUsed: number;
18
+ /** Whether the connection is currently in use. */
24
19
  busy: boolean;
25
20
  }
26
- /**
27
- * Configuration options for the {@link ConnectionPool}.
28
- *
29
- * @typedef {Object} PoolOptions
30
- * @property {number} [maxConnectionsPerOrigin=6] - Maximum simultaneous connections to a single origin.
31
- * @property {number} [maxTotalConnections=64] - Maximum total connections across all origins.
32
- * @property {number} [idleTimeout=60000] - Milliseconds of inactivity before a connection is evicted.
33
- * @property {number} [maxAge=300000] - Maximum lifetime of a connection in milliseconds.
34
- */
21
+ /** Connection pool configuration. */
35
22
  export interface PoolOptions {
23
+ /** Maximum connections per origin. */
36
24
  maxConnectionsPerOrigin?: number;
25
+ /** Maximum total connections across all origins. */
37
26
  maxTotalConnections?: number;
27
+ /** Idle timeout in milliseconds before connections are closed. */
38
28
  idleTimeout?: number;
29
+ /** Maximum connection age in milliseconds. */
39
30
  maxAge?: number;
40
31
  }
41
- /**
42
- * Maintains a pool of reusable TLS connections, keyed by origin, supporting
43
- * both HTTP/1.1 (exclusive per-request access) and HTTP/2 (multiplexed)
44
- * connections. Idle and expired connections are evicted automatically on a
45
- * 30-second timer.
46
- */
32
+ /** HTTP connection pool with idle eviction and per-origin limits. */
47
33
  export declare class ConnectionPool {
48
34
  private readonly options;
49
35
  private readonly connections;
50
36
  private totalConnections;
51
37
  private cleanupTimer;
52
38
  /**
53
- * Creates a new ConnectionPool.
39
+ * Create a new connection pool.
54
40
  *
55
- * @param {PoolOptions} [options={}] - Pool configuration; unset fields use their defaults.
41
+ * @param {PoolOptions} [options] - Pool configuration.
56
42
  */
57
43
  constructor(options?: PoolOptions);
58
44
  /**
59
- * Checks out a usable connection for the given origin. For HTTP/2 returns
60
- * any live connection (multiplexing); for HTTP/1.1 returns a non-busy,
61
- * non-expired connection and marks it busy.
45
+ * Get an available connection for the given origin.
62
46
  *
63
- * @param {string} origin - Origin key in `protocol://hostname:port` form.
64
- * @returns {PoolEntry|undefined} A ready connection entry, or `undefined` if none is available.
47
+ * @param {string} origin - Origin to look up.
48
+ * @returns {PoolEntry|undefined} A pool entry, or `undefined` if none is available.
65
49
  */
66
50
  get(origin: string): PoolEntry | undefined;
67
51
  /**
68
- * Registers a new connection in the pool. If adding the entry would exceed
69
- * the per-origin limit, the oldest entry for that origin is evicted. If the
70
- * total connection limit has been reached, the globally least-recently-used
71
- * idle connection is evicted first.
52
+ * Add a new connection to the pool.
72
53
  *
73
- * @param {string} origin - Origin key.
74
- * @param {TLSSocket} socket - Connected socket to pool.
75
- * @param {'h1'|'h2'} protocol - Negotiated HTTP protocol.
76
- * @param {H2Profile} [h2Profile] - H2 profile used to configure the H2Client.
77
- * @param {Array<[string,string]>} [defaultHeaders] - Default headers applied to every H2 request.
78
- * @returns {PoolEntry} The newly created pool entry.
54
+ * @param {string} origin - Origin key.
55
+ * @param {TLSSocket} socket - TLS socket.
56
+ * @param {"h1"|"h2"|"h3"} protocol - Negotiated protocol.
57
+ * @param {H2Profile} [h2Profile] - Optional HTTP/2 profile for h2 connections.
58
+ * @param {Array<[string, string]>} [defaultHeaders] - Default headers for h2 connections.
59
+ * @returns {PoolEntry} The created pool entry.
79
60
  */
80
- put(origin: string, socket: TLSSocket, protocol: "h1" | "h2", h2Profile?: H2Profile, defaultHeaders?: Array<[string, string]>): PoolEntry;
61
+ put(origin: string, socket: TLSSocket, protocol: "h1" | "h2" | "h3", h2Profile?: H2Profile, defaultHeaders?: Array<[string, string]>): PoolEntry;
81
62
  /**
82
- * Marks an HTTP/1.1 pool entry as available for reuse once a request has
83
- * completed. Updates the `lastUsed` timestamp.
63
+ * Mark a connection as idle and available for reuse.
84
64
  *
85
- * @param {PoolEntry} entry - The connection entry to release.
65
+ * @param {PoolEntry} entry - Pool entry to release.
86
66
  */
87
67
  release(entry: PoolEntry): void;
88
68
  /**
89
- * Removes a connection entry from the pool and destroys its socket.
90
- * Typically called when a connection error has occurred or the server
91
- * sent a `Connection: close` header.
69
+ * Remove a connection from the pool and destroy its socket.
92
70
  *
93
- * @param {PoolEntry} entry - The connection entry to remove and destroy.
71
+ * @param {PoolEntry} entry - Pool entry to remove.
94
72
  */
95
73
  remove(entry: PoolEntry): void;
96
- /**
97
- * Destroys all pooled connections and stops the idle-eviction timer.
98
- * The pool must not be used after this call.
99
- */
74
+ /** Close all pooled connections and stop the cleanup timer. */
100
75
  close(): void;
101
- /**
102
- * Returns the total number of connections (both idle and busy) currently held
103
- * in the pool across all origins.
104
- *
105
- * @returns {number} Total pooled connection count.
106
- */
76
+ /** Total number of connections across all origins. */
107
77
  get size(): number;
108
78
  private isExpired;
109
79
  private evictIdle;
@@ -1 +1 @@
1
- {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/http/pool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAqB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,QAAQ,EAA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IAC7B,OAAO,CAAC,YAAY,CAA6C;IAEjE;;;;OAIG;gBACS,OAAO,GAAE,WAAgB;IAUrC;;;;;OAKG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAyB1C;;;;;;;;;OASG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,cAAc,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS;IAsChJ;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAK/B;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAe9B,+DAA+D;IAC/D,KAAK,IAAI,IAAI;IAgBb,sDAAsD;IACtD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,SAAS;IAkBjB,OAAO,CAAC,WAAW;CAiBpB"}
package/dist/http/pool.js CHANGED
@@ -5,36 +5,31 @@ const DEFAULT_POOL_OPTIONS = {
5
5
  idleTimeout: 60_000,
6
6
  maxAge: 300_000,
7
7
  };
8
- /**
9
- * Maintains a pool of reusable TLS connections, keyed by origin, supporting
10
- * both HTTP/1.1 (exclusive per-request access) and HTTP/2 (multiplexed)
11
- * connections. Idle and expired connections are evicted automatically on a
12
- * 30-second timer.
13
- */
8
+ /** HTTP connection pool with idle eviction and per-origin limits. */
14
9
  export class ConnectionPool {
15
10
  options;
16
11
  connections = new Map();
17
12
  totalConnections = 0;
18
13
  cleanupTimer;
19
14
  /**
20
- * Creates a new ConnectionPool.
15
+ * Create a new connection pool.
21
16
  *
22
- * @param {PoolOptions} [options={}] - Pool configuration; unset fields use their defaults.
17
+ * @param {PoolOptions} [options] - Pool configuration.
23
18
  */
24
19
  constructor(options = {}) {
25
20
  this.options = { ...DEFAULT_POOL_OPTIONS, ...options };
26
- this.cleanupTimer = setInterval(() => this.evictIdle(), 30_000);
21
+ this.cleanupTimer = setInterval(() => {
22
+ this.evictIdle();
23
+ }, 30_000);
27
24
  if (this.cleanupTimer.unref) {
28
25
  this.cleanupTimer.unref();
29
26
  }
30
27
  }
31
28
  /**
32
- * Checks out a usable connection for the given origin. For HTTP/2 returns
33
- * any live connection (multiplexing); for HTTP/1.1 returns a non-busy,
34
- * non-expired connection and marks it busy.
29
+ * Get an available connection for the given origin.
35
30
  *
36
- * @param {string} origin - Origin key in `protocol://hostname:port` form.
37
- * @returns {PoolEntry|undefined} A ready connection entry, or `undefined` if none is available.
31
+ * @param {string} origin - Origin to look up.
32
+ * @returns {PoolEntry|undefined} A pool entry, or `undefined` if none is available.
38
33
  */
39
34
  get(origin) {
40
35
  const entries = this.connections.get(origin);
@@ -58,17 +53,14 @@ export class ConnectionPool {
58
53
  return undefined;
59
54
  }
60
55
  /**
61
- * Registers a new connection in the pool. If adding the entry would exceed
62
- * the per-origin limit, the oldest entry for that origin is evicted. If the
63
- * total connection limit has been reached, the globally least-recently-used
64
- * idle connection is evicted first.
56
+ * Add a new connection to the pool.
65
57
  *
66
- * @param {string} origin - Origin key.
67
- * @param {TLSSocket} socket - Connected socket to pool.
68
- * @param {'h1'|'h2'} protocol - Negotiated HTTP protocol.
69
- * @param {H2Profile} [h2Profile] - H2 profile used to configure the H2Client.
70
- * @param {Array<[string,string]>} [defaultHeaders] - Default headers applied to every H2 request.
71
- * @returns {PoolEntry} The newly created pool entry.
58
+ * @param {string} origin - Origin key.
59
+ * @param {TLSSocket} socket - TLS socket.
60
+ * @param {"h1"|"h2"|"h3"} protocol - Negotiated protocol.
61
+ * @param {H2Profile} [h2Profile] - Optional HTTP/2 profile for h2 connections.
62
+ * @param {Array<[string, string]>} [defaultHeaders] - Default headers for h2 connections.
63
+ * @returns {PoolEntry} The created pool entry.
72
64
  */
73
65
  put(origin, socket, protocol, h2Profile, defaultHeaders) {
74
66
  if (this.totalConnections >= this.options.maxTotalConnections) {
@@ -102,21 +94,18 @@ export class ConnectionPool {
102
94
  return entry;
103
95
  }
104
96
  /**
105
- * Marks an HTTP/1.1 pool entry as available for reuse once a request has
106
- * completed. Updates the `lastUsed` timestamp.
97
+ * Mark a connection as idle and available for reuse.
107
98
  *
108
- * @param {PoolEntry} entry - The connection entry to release.
99
+ * @param {PoolEntry} entry - Pool entry to release.
109
100
  */
110
101
  release(entry) {
111
102
  entry.busy = false;
112
103
  entry.lastUsed = Date.now();
113
104
  }
114
105
  /**
115
- * Removes a connection entry from the pool and destroys its socket.
116
- * Typically called when a connection error has occurred or the server
117
- * sent a `Connection: close` header.
106
+ * Remove a connection from the pool and destroy its socket.
118
107
  *
119
- * @param {PoolEntry} entry - The connection entry to remove and destroy.
108
+ * @param {PoolEntry} entry - Pool entry to remove.
120
109
  */
121
110
  remove(entry) {
122
111
  const entries = this.connections.get(entry.origin);
@@ -132,10 +121,7 @@ export class ConnectionPool {
132
121
  }
133
122
  entry.socket.destroyTLS();
134
123
  }
135
- /**
136
- * Destroys all pooled connections and stops the idle-eviction timer.
137
- * The pool must not be used after this call.
138
- */
124
+ /** Close all pooled connections and stop the cleanup timer. */
139
125
  close() {
140
126
  if (this.cleanupTimer) {
141
127
  clearInterval(this.cleanupTimer);
@@ -151,12 +137,7 @@ export class ConnectionPool {
151
137
  this.connections.clear();
152
138
  this.totalConnections = 0;
153
139
  }
154
- /**
155
- * Returns the total number of connections (both idle and busy) currently held
156
- * in the pool across all origins.
157
- *
158
- * @returns {number} Total pooled connection count.
159
- */
140
+ /** Total number of connections across all origins. */
160
141
  get size() {
161
142
  return this.totalConnections;
162
143
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../src/http/pool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AA0C1C,MAAM,oBAAoB,GAA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H,CAAC;IAEO,WAAW;QACjB,IAAI,MAAwD,CAAC;QAE7D,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACjD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC5B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;oBAChB,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;wBACtD,MAAM,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;oBAC7B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,76 @@
1
+ /** State of a resumable upload session. */
2
+ export interface UploadSession {
3
+ /** Server-assigned upload URL. */
4
+ uploadUrl: string;
5
+ /** Number of bytes already uploaded. */
6
+ offset: number;
7
+ /** Total size of the upload in bytes. */
8
+ totalSize: number;
9
+ /** Whether the upload has been completed. */
10
+ complete: boolean;
11
+ /** Timestamp when the session was created. */
12
+ createdAt: number;
13
+ }
14
+ /** Configuration for resumable upload operations. */
15
+ export interface ResumableUploadConfig {
16
+ /** Size of each upload chunk in bytes. */
17
+ chunkSize?: number;
18
+ /** Maximum number of retry attempts per chunk. */
19
+ maxRetries?: number;
20
+ /** Progress callback invoked after each chunk. */
21
+ onProgress?: (offset: number, total: number) => void;
22
+ }
23
+ /**
24
+ * Build headers for initiating a new resumable upload.
25
+ *
26
+ * @param {number} totalSize - Total upload size in bytes.
27
+ * @param {string} [contentType] - MIME type of the upload content.
28
+ * @returns {Record<string, string>} Header record for the upload creation request.
29
+ */
30
+ export declare function buildUploadCreationHeaders(totalSize: number, contentType?: string): Record<string, string>;
31
+ /**
32
+ * Build headers for resuming an upload at a given offset.
33
+ *
34
+ * @param {number} offset - Byte offset to resume from.
35
+ * @param {number} chunkSize - Size of the chunk being sent.
36
+ * @param {boolean} isLast - Whether this is the final chunk.
37
+ * @returns {Record<string, string>} Header record for the resume request.
38
+ */
39
+ export declare function buildUploadResumeHeaders(offset: number, chunkSize: number, isLast: boolean): Record<string, string>;
40
+ /**
41
+ * Build headers for querying the current upload offset.
42
+ *
43
+ * @returns {Record<string, string>} Header record for the offset query request.
44
+ */
45
+ export declare function buildUploadOffsetHeaders(): Record<string, string>;
46
+ /**
47
+ * Parse the upload offset from response headers.
48
+ *
49
+ * @param {Record<string, string>} headers - Response headers.
50
+ * @returns {number} Byte offset, or -1 if not present or invalid.
51
+ */
52
+ export declare function parseUploadOffset(headers: Record<string, string>): number;
53
+ /**
54
+ * Check whether the upload is marked as complete in response headers.
55
+ *
56
+ * @param {Record<string, string>} headers - Response headers.
57
+ * @returns {boolean} `true` if the upload-complete header is "?1".
58
+ */
59
+ export declare function isUploadComplete(headers: Record<string, string>): boolean;
60
+ /**
61
+ * Split a buffer into offset-chunk pairs for resumable upload.
62
+ *
63
+ * @param {Buffer} data - Data to split.
64
+ * @param {number} [chunkSize] - Maximum chunk size in bytes.
65
+ * @returns {Array<[number, Buffer]>} Array of [offset, chunk] tuples.
66
+ */
67
+ export declare function splitIntoChunks(data: Buffer, chunkSize?: number): Array<[number, Buffer]>;
68
+ /**
69
+ * Extract the upload URL from response headers.
70
+ *
71
+ * @param {Record<string, string>} headers - Response headers.
72
+ * @param {string} requestUrl - Original request URL for resolving relative locations.
73
+ * @returns {string | null} Absolute upload URL, or `null` if not present.
74
+ */
75
+ export declare function parseUploadUrl(headers: Record<string, string>, requestUrl: string): string | null;
76
+ //# sourceMappingURL=resumable-upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resumable-upload.d.ts","sourceRoot":"","sources":["../../src/http/resumable-upload.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,MAAM,WAAW,aA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CAAC,CAAC,CAUzF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQjG"}
@@ -0,0 +1,104 @@
1
+ const DEFAULT_CHUNK_SIZE = 5 * 1024 * 1024;
2
+ const UPLOAD_CONTENT_TYPE = "application/partial-upload";
3
+ /**
4
+ * Build headers for initiating a new resumable upload.
5
+ *
6
+ * @param {number} totalSize - Total upload size in bytes.
7
+ * @param {string} [contentType] - MIME type of the upload content.
8
+ * @returns {Record<string, string>} Header record for the upload creation request.
9
+ */
10
+ export function buildUploadCreationHeaders(totalSize, contentType) {
11
+ return {
12
+ "upload-complete": "?0",
13
+ "upload-draft-interop-version": "7",
14
+ "content-type": contentType ?? "application/octet-stream",
15
+ "content-length": String(totalSize),
16
+ };
17
+ }
18
+ /**
19
+ * Build headers for resuming an upload at a given offset.
20
+ *
21
+ * @param {number} offset - Byte offset to resume from.
22
+ * @param {number} chunkSize - Size of the chunk being sent.
23
+ * @param {boolean} isLast - Whether this is the final chunk.
24
+ * @returns {Record<string, string>} Header record for the resume request.
25
+ */
26
+ export function buildUploadResumeHeaders(offset, chunkSize, isLast) {
27
+ return {
28
+ "upload-offset": String(offset),
29
+ "upload-complete": isLast ? "?1" : "?0",
30
+ "upload-draft-interop-version": "7",
31
+ "content-type": UPLOAD_CONTENT_TYPE,
32
+ "content-length": String(chunkSize),
33
+ };
34
+ }
35
+ /**
36
+ * Build headers for querying the current upload offset.
37
+ *
38
+ * @returns {Record<string, string>} Header record for the offset query request.
39
+ */
40
+ export function buildUploadOffsetHeaders() {
41
+ return {
42
+ "upload-draft-interop-version": "7",
43
+ };
44
+ }
45
+ /**
46
+ * Parse the upload offset from response headers.
47
+ *
48
+ * @param {Record<string, string>} headers - Response headers.
49
+ * @returns {number} Byte offset, or -1 if not present or invalid.
50
+ */
51
+ export function parseUploadOffset(headers) {
52
+ const val = headers["upload-offset"];
53
+ if (!val)
54
+ return -1;
55
+ const offset = parseInt(val, 10);
56
+ return Number.isFinite(offset) && offset >= 0 ? offset : -1;
57
+ }
58
+ /**
59
+ * Check whether the upload is marked as complete in response headers.
60
+ *
61
+ * @param {Record<string, string>} headers - Response headers.
62
+ * @returns {boolean} `true` if the upload-complete header is "?1".
63
+ */
64
+ export function isUploadComplete(headers) {
65
+ const val = headers["upload-complete"];
66
+ return val === "?1";
67
+ }
68
+ /**
69
+ * Split a buffer into offset-chunk pairs for resumable upload.
70
+ *
71
+ * @param {Buffer} data - Data to split.
72
+ * @param {number} [chunkSize] - Maximum chunk size in bytes.
73
+ * @returns {Array<[number, Buffer]>} Array of [offset, chunk] tuples.
74
+ */
75
+ export function splitIntoChunks(data, chunkSize) {
76
+ const size = chunkSize ?? DEFAULT_CHUNK_SIZE;
77
+ const chunks = [];
78
+ let offset = 0;
79
+ while (offset < data.length) {
80
+ const end = Math.min(offset + size, data.length);
81
+ chunks.push([offset, data.subarray(offset, end)]);
82
+ offset = end;
83
+ }
84
+ return chunks;
85
+ }
86
+ /**
87
+ * Extract the upload URL from response headers.
88
+ *
89
+ * @param {Record<string, string>} headers - Response headers.
90
+ * @param {string} requestUrl - Original request URL for resolving relative locations.
91
+ * @returns {string | null} Absolute upload URL, or `null` if not present.
92
+ */
93
+ export function parseUploadUrl(headers, requestUrl) {
94
+ const location = headers["location"];
95
+ if (!location)
96
+ return null;
97
+ try {
98
+ return new URL(location, requestUrl).href;
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ }
104
+ //# sourceMappingURL=resumable-upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resumable-upload.js","sourceRoot":"","sources":["../../src/http/resumable-upload.ts"],"names":[],"mappings":"AAwBA,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3C,MAAM,mBAAmB,GAAG,4BAA4B,CAAC;AAEzD;;;;;;GAMG;AACH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C,IAAY,EAAE,SAAkB;IAC9D,MAAM,IAAI,GAAG,SAAS,IAAI,kBAAkB,CAAC;IAC7C,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACjD,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,GAAG,GAAG,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,OAA+B,EAAE,UAAkB;IAChF,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Check whether a header name is allowed as an HTTP trailer field.
3
+ *
4
+ * @param {string} name - Header field name.
5
+ * @returns {boolean} `true` if the name is not in the forbidden trailer fields set.
6
+ */
7
+ export declare function isValidTrailerField(name: string): boolean;
8
+ /**
9
+ * Serialize trailer fields into a wire-format buffer.
10
+ *
11
+ * @param {Record<string, string>} trailers - Key-value pairs of trailer fields.
12
+ * @returns {Buffer} CRLF-delimited buffer of valid trailer fields.
13
+ */
14
+ export declare function serializeTrailers(trailers: Record<string, string>): Buffer;
15
+ /**
16
+ * Parse trailer field data into a key-value record.
17
+ *
18
+ * @param {Buffer} data - Raw trailer data buffer.
19
+ * @returns {Record<string, string>} Parsed trailer fields keyed by lowercase name.
20
+ */
21
+ export declare function parseTrailers(data: Buffer): Record<string, string>;
22
+ /**
23
+ * Build a Trailer header value listing the trailer field names.
24
+ *
25
+ * @param {string[]} fieldNames - Trailer field names to advertise.
26
+ * @returns {string} Comma-separated string of valid trailer field names.
27
+ */
28
+ export declare function buildTrailerHeader(fieldNames: string[]): string;
29
+ //# sourceMappingURL=trailers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trailers.d.ts","sourceRoot":"","sources":["../../src/http/trailers.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAQ1E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAclE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAE/D"}
@@ -0,0 +1,57 @@
1
+ const FORBIDDEN_TRAILER_FIELDS = new Set(["transfer-encoding", "content-length", "host", "cache-control", "expect", "max-forwards", "pragma", "range", "te", "authorization", "content-encoding", "content-range", "content-type", "trailer", "set-cookie"]);
2
+ /**
3
+ * Check whether a header name is allowed as an HTTP trailer field.
4
+ *
5
+ * @param {string} name - Header field name.
6
+ * @returns {boolean} `true` if the name is not in the forbidden trailer fields set.
7
+ */
8
+ export function isValidTrailerField(name) {
9
+ return !FORBIDDEN_TRAILER_FIELDS.has(name.toLowerCase());
10
+ }
11
+ /**
12
+ * Serialize trailer fields into a wire-format buffer.
13
+ *
14
+ * @param {Record<string, string>} trailers - Key-value pairs of trailer fields.
15
+ * @returns {Buffer} CRLF-delimited buffer of valid trailer fields.
16
+ */
17
+ export function serializeTrailers(trailers) {
18
+ const lines = [];
19
+ for (const [name, value] of Object.entries(trailers)) {
20
+ if (isValidTrailerField(name)) {
21
+ lines.push(`${name}: ${value}`);
22
+ }
23
+ }
24
+ return Buffer.from(lines.join("\r\n") + "\r\n", "ascii");
25
+ }
26
+ /**
27
+ * Parse trailer field data into a key-value record.
28
+ *
29
+ * @param {Buffer} data - Raw trailer data buffer.
30
+ * @returns {Record<string, string>} Parsed trailer fields keyed by lowercase name.
31
+ */
32
+ export function parseTrailers(data) {
33
+ const trailers = {};
34
+ const text = data.toString("ascii");
35
+ const lines = text.split("\r\n");
36
+ for (const line of lines) {
37
+ const colonIdx = line.indexOf(":");
38
+ if (colonIdx < 0)
39
+ continue;
40
+ const name = line.substring(0, colonIdx).trim().toLowerCase();
41
+ const value = line.substring(colonIdx + 1).trim();
42
+ if (name && isValidTrailerField(name)) {
43
+ trailers[name] = value;
44
+ }
45
+ }
46
+ return trailers;
47
+ }
48
+ /**
49
+ * Build a Trailer header value listing the trailer field names.
50
+ *
51
+ * @param {string[]} fieldNames - Trailer field names to advertise.
52
+ * @returns {string} Comma-separated string of valid trailer field names.
53
+ */
54
+ export function buildTrailerHeader(fieldNames) {
55
+ return fieldNames.filter(isValidTrailerField).join(", ");
56
+ }
57
+ //# sourceMappingURL=trailers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trailers.js","sourceRoot":"","sources":["../../src/http/trailers.ts"],"names":[],"mappings":"AAAA,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,kBAAkB,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;AAE7P;;;;;GAKG;AACH,MAAM,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