@seanhogg/builderforce-webcontainers-core 2026.10.2 → 2026.10.3

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 (426) hide show
  1. package/dist/build.d.ts +42 -0
  2. package/dist/build.d.ts.map +1 -0
  3. package/dist/build.js +65 -0
  4. package/dist/build.js.map +1 -0
  5. package/dist/buildHost.d.ts +31 -0
  6. package/dist/buildHost.d.ts.map +1 -0
  7. package/dist/buildHost.js +125 -0
  8. package/dist/buildHost.js.map +1 -0
  9. package/dist/buildHtml.d.ts +28 -0
  10. package/dist/buildHtml.d.ts.map +1 -0
  11. package/dist/buildHtml.js +74 -0
  12. package/dist/buildHtml.js.map +1 -0
  13. package/dist/bundler.d.ts +129 -0
  14. package/dist/bundler.d.ts.map +1 -0
  15. package/dist/bundler.js +79 -0
  16. package/dist/bundler.js.map +1 -0
  17. package/dist/check/acquire.d.ts +46 -0
  18. package/dist/check/acquire.d.ts.map +1 -0
  19. package/dist/check/acquire.js +179 -0
  20. package/dist/check/acquire.js.map +1 -0
  21. package/dist/check/compilerHost.d.ts +22 -0
  22. package/dist/check/compilerHost.d.ts.map +1 -0
  23. package/dist/check/compilerHost.js +128 -0
  24. package/dist/check/compilerHost.js.map +1 -0
  25. package/dist/check/diagnostics.d.ts +23 -0
  26. package/dist/check/diagnostics.d.ts.map +1 -0
  27. package/dist/check/diagnostics.js +28 -0
  28. package/dist/check/diagnostics.js.map +1 -0
  29. package/dist/check/index.d.ts +19 -0
  30. package/dist/check/index.d.ts.map +1 -0
  31. package/dist/check/index.js +13 -0
  32. package/dist/check/index.js.map +1 -0
  33. package/dist/check/projects.d.ts +26 -0
  34. package/dist/check/projects.d.ts.map +1 -0
  35. package/dist/check/projects.js +124 -0
  36. package/dist/check/projects.js.map +1 -0
  37. package/dist/check/shims.d.ts +29 -0
  38. package/dist/check/shims.d.ts.map +1 -0
  39. package/dist/check/shims.js +76 -0
  40. package/dist/check/shims.js.map +1 -0
  41. package/dist/check/typeStore.d.ts +57 -0
  42. package/dist/check/typeStore.d.ts.map +1 -0
  43. package/dist/check/typeStore.js +89 -0
  44. package/dist/check/typeStore.js.map +1 -0
  45. package/dist/check/typecheck.d.ts +29 -0
  46. package/dist/check/typecheck.d.ts.map +1 -0
  47. package/dist/check/typecheck.js +91 -0
  48. package/dist/check/typecheck.js.map +1 -0
  49. package/dist/compileComponent.d.ts +8 -0
  50. package/dist/compileComponent.d.ts.map +1 -0
  51. package/dist/compileComponent.js +22 -0
  52. package/dist/compileComponent.js.map +1 -0
  53. package/dist/compileScript.d.ts +19 -4
  54. package/dist/compileScript.d.ts.map +1 -1
  55. package/dist/compileScript.js +37 -12
  56. package/dist/compileScript.js.map +1 -1
  57. package/dist/components.d.ts +41 -0
  58. package/dist/components.d.ts.map +1 -0
  59. package/dist/components.js +14 -0
  60. package/dist/components.js.map +1 -0
  61. package/dist/detectProject.d.ts +3 -0
  62. package/dist/detectProject.d.ts.map +1 -1
  63. package/dist/detectProject.js +16 -6
  64. package/dist/detectProject.js.map +1 -1
  65. package/dist/devServer.d.ts +5 -2
  66. package/dist/devServer.d.ts.map +1 -1
  67. package/dist/devServer.js +10 -6
  68. package/dist/devServer.js.map +1 -1
  69. package/dist/hash.d.ts +2 -0
  70. package/dist/hash.d.ts.map +1 -0
  71. package/dist/hash.js +22 -0
  72. package/dist/hash.js.map +1 -0
  73. package/dist/index.d.ts +24 -6
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +14 -3
  76. package/dist/index.js.map +1 -1
  77. package/dist/installer/bins.d.ts +24 -0
  78. package/dist/installer/bins.d.ts.map +1 -0
  79. package/dist/installer/bins.js +56 -0
  80. package/dist/installer/bins.js.map +1 -0
  81. package/dist/installer/index.d.ts +14 -0
  82. package/dist/installer/index.d.ts.map +1 -0
  83. package/dist/installer/index.js +9 -0
  84. package/dist/installer/index.js.map +1 -0
  85. package/dist/installer/install.d.ts +46 -0
  86. package/dist/installer/install.d.ts.map +1 -0
  87. package/dist/installer/install.js +245 -0
  88. package/dist/installer/install.js.map +1 -0
  89. package/dist/installer/lockfile.d.ts +49 -0
  90. package/dist/installer/lockfile.d.ts.map +1 -0
  91. package/dist/installer/lockfile.js +110 -0
  92. package/dist/installer/lockfile.js.map +1 -0
  93. package/dist/installer/registry.d.ts +84 -0
  94. package/dist/installer/registry.d.ts.map +1 -0
  95. package/dist/installer/registry.js +130 -0
  96. package/dist/installer/registry.js.map +1 -0
  97. package/dist/installer/semver.d.ts +38 -0
  98. package/dist/installer/semver.d.ts.map +1 -0
  99. package/dist/installer/semver.js +187 -0
  100. package/dist/installer/semver.js.map +1 -0
  101. package/dist/installer/spec.d.ts +30 -0
  102. package/dist/installer/spec.d.ts.map +1 -0
  103. package/dist/installer/spec.js +30 -0
  104. package/dist/installer/spec.js.map +1 -0
  105. package/dist/installer/tar.d.ts +17 -0
  106. package/dist/installer/tar.d.ts.map +1 -0
  107. package/dist/installer/tar.js +150 -0
  108. package/dist/installer/tar.js.map +1 -0
  109. package/dist/installer/tree.d.ts +48 -0
  110. package/dist/installer/tree.d.ts.map +1 -0
  111. package/dist/installer/tree.js +179 -0
  112. package/dist/installer/tree.js.map +1 -0
  113. package/dist/node/assert.d.ts +15 -0
  114. package/dist/node/assert.d.ts.map +1 -0
  115. package/dist/node/assert.js +137 -0
  116. package/dist/node/assert.js.map +1 -0
  117. package/dist/node/buffer.d.ts +84 -0
  118. package/dist/node/buffer.d.ts.map +1 -0
  119. package/dist/node/buffer.js +304 -0
  120. package/dist/node/buffer.js.map +1 -0
  121. package/dist/node/builtins.d.ts +25 -0
  122. package/dist/node/builtins.d.ts.map +1 -0
  123. package/dist/node/builtins.js +101 -0
  124. package/dist/node/builtins.js.map +1 -0
  125. package/dist/node/callable.d.ts +13 -0
  126. package/dist/node/callable.d.ts.map +1 -0
  127. package/dist/node/callable.js +26 -0
  128. package/dist/node/callable.js.map +1 -0
  129. package/dist/node/childProcess.d.ts +13 -0
  130. package/dist/node/childProcess.d.ts.map +1 -0
  131. package/dist/node/childProcess.js +143 -0
  132. package/dist/node/childProcess.js.map +1 -0
  133. package/dist/node/crypto.d.ts +3 -0
  134. package/dist/node/crypto.d.ts.map +1 -0
  135. package/dist/node/crypto.js +180 -0
  136. package/dist/node/crypto.js.map +1 -0
  137. package/dist/node/esm.d.ts +9 -0
  138. package/dist/node/esm.d.ts.map +1 -0
  139. package/dist/node/esm.js +202 -0
  140. package/dist/node/esm.js.map +1 -0
  141. package/dist/node/events.d.ts +40 -0
  142. package/dist/node/events.d.ts.map +1 -0
  143. package/dist/node/events.js +160 -0
  144. package/dist/node/events.js.map +1 -0
  145. package/dist/node/fs/index.d.ts +7 -0
  146. package/dist/node/fs/index.d.ts.map +1 -0
  147. package/dist/node/fs/index.js +270 -0
  148. package/dist/node/fs/index.js.map +1 -0
  149. package/dist/node/fs/stats.d.ts +93 -0
  150. package/dist/node/fs/stats.d.ts.map +1 -0
  151. package/dist/node/fs/stats.js +104 -0
  152. package/dist/node/fs/stats.js.map +1 -0
  153. package/dist/node/fs/sync.d.ts +98 -0
  154. package/dist/node/fs/sync.d.ts.map +1 -0
  155. package/dist/node/fs/sync.js +348 -0
  156. package/dist/node/fs/sync.js.map +1 -0
  157. package/dist/node/hashes.d.ts +15 -0
  158. package/dist/node/hashes.d.ts.map +1 -0
  159. package/dist/node/hashes.js +195 -0
  160. package/dist/node/hashes.js.map +1 -0
  161. package/dist/node/http/client.d.ts +35 -0
  162. package/dist/node/http/client.d.ts.map +1 -0
  163. package/dist/node/http/client.js +161 -0
  164. package/dist/node/http/client.js.map +1 -0
  165. package/dist/node/http/index.d.ts +5 -0
  166. package/dist/node/http/index.d.ts.map +1 -0
  167. package/dist/node/http/index.js +125 -0
  168. package/dist/node/http/index.js.map +1 -0
  169. package/dist/node/http/server.d.ts +135 -0
  170. package/dist/node/http/server.d.ts.map +1 -0
  171. package/dist/node/http/server.js +308 -0
  172. package/dist/node/http/server.js.map +1 -0
  173. package/dist/node/http/status.d.ts +3 -0
  174. package/dist/node/http/status.d.ts.map +1 -0
  175. package/dist/node/http/status.js +13 -0
  176. package/dist/node/http/status.js.map +1 -0
  177. package/dist/node/inspect.d.ts +22 -0
  178. package/dist/node/inspect.d.ts.map +1 -0
  179. package/dist/node/inspect.js +172 -0
  180. package/dist/node/inspect.js.map +1 -0
  181. package/dist/node/loader.d.ts +91 -0
  182. package/dist/node/loader.d.ts.map +1 -0
  183. package/dist/node/loader.js +265 -0
  184. package/dist/node/loader.js.map +1 -0
  185. package/dist/node/loop.d.ts +71 -0
  186. package/dist/node/loop.d.ts.map +1 -0
  187. package/dist/node/loop.js +189 -0
  188. package/dist/node/loop.js.map +1 -0
  189. package/dist/node/misc.d.ts +10 -0
  190. package/dist/node/misc.d.ts.map +1 -0
  191. package/dist/node/misc.js +256 -0
  192. package/dist/node/misc.js.map +1 -0
  193. package/dist/node/path.d.ts +14 -0
  194. package/dist/node/path.d.ts.map +1 -0
  195. package/dist/node/path.js +128 -0
  196. package/dist/node/path.js.map +1 -0
  197. package/dist/node/process.d.ts +31 -0
  198. package/dist/node/process.d.ts.map +1 -0
  199. package/dist/node/process.js +309 -0
  200. package/dist/node/process.js.map +1 -0
  201. package/dist/node/program.d.ts +19 -0
  202. package/dist/node/program.d.ts.map +1 -0
  203. package/dist/node/program.js +165 -0
  204. package/dist/node/program.js.map +1 -0
  205. package/dist/node/readline.d.ts +2 -0
  206. package/dist/node/readline.d.ts.map +1 -0
  207. package/dist/node/readline.js +155 -0
  208. package/dist/node/readline.js.map +1 -0
  209. package/dist/node/resolve.d.ts +45 -0
  210. package/dist/node/resolve.d.ts.map +1 -0
  211. package/dist/node/resolve.js +206 -0
  212. package/dist/node/resolve.js.map +1 -0
  213. package/dist/node/runtime.d.ts +40 -0
  214. package/dist/node/runtime.d.ts.map +1 -0
  215. package/dist/node/runtime.js +149 -0
  216. package/dist/node/runtime.js.map +1 -0
  217. package/dist/node/stream/index.d.ts +52 -0
  218. package/dist/node/stream/index.d.ts.map +1 -0
  219. package/dist/node/stream/index.js +184 -0
  220. package/dist/node/stream/index.js.map +1 -0
  221. package/dist/node/stream/readable.d.ts +83 -0
  222. package/dist/node/stream/readable.d.ts.map +1 -0
  223. package/dist/node/stream/readable.js +325 -0
  224. package/dist/node/stream/readable.js.map +1 -0
  225. package/dist/node/stream/writable.d.ts +80 -0
  226. package/dist/node/stream/writable.d.ts.map +1 -0
  227. package/dist/node/stream/writable.js +224 -0
  228. package/dist/node/stream/writable.js.map +1 -0
  229. package/dist/node/urlqs.d.ts +22 -0
  230. package/dist/node/urlqs.d.ts.map +1 -0
  231. package/dist/node/urlqs.js +165 -0
  232. package/dist/node/urlqs.js.map +1 -0
  233. package/dist/node/util.d.ts +37 -0
  234. package/dist/node/util.d.ts.map +1 -0
  235. package/dist/node/util.js +160 -0
  236. package/dist/node/util.js.map +1 -0
  237. package/dist/node/zlib.d.ts +2 -0
  238. package/dist/node/zlib.d.ts.map +1 -0
  239. package/dist/node/zlib.js +133 -0
  240. package/dist/node/zlib.js.map +1 -0
  241. package/dist/packageCdn.d.ts +12 -0
  242. package/dist/packageCdn.d.ts.map +1 -1
  243. package/dist/packageCdn.js +3 -1
  244. package/dist/packageCdn.js.map +1 -1
  245. package/dist/projectConfig.d.ts +6 -2
  246. package/dist/projectConfig.d.ts.map +1 -1
  247. package/dist/projectConfig.js +32 -8
  248. package/dist/projectConfig.js.map +1 -1
  249. package/dist/shell/builtins.d.ts +23 -0
  250. package/dist/shell/builtins.d.ts.map +1 -0
  251. package/dist/shell/builtins.js +131 -0
  252. package/dist/shell/builtins.js.map +1 -0
  253. package/dist/shell/context.d.ts +41 -0
  254. package/dist/shell/context.d.ts.map +1 -0
  255. package/dist/shell/context.js +65 -0
  256. package/dist/shell/context.js.map +1 -0
  257. package/dist/shell/devHandoff.d.ts +18 -0
  258. package/dist/shell/devHandoff.d.ts.map +1 -0
  259. package/dist/shell/devHandoff.js +36 -0
  260. package/dist/shell/devHandoff.js.map +1 -0
  261. package/dist/shell/exec.d.ts +67 -0
  262. package/dist/shell/exec.d.ts.map +1 -0
  263. package/dist/shell/exec.js +247 -0
  264. package/dist/shell/exec.js.map +1 -0
  265. package/dist/shell/expand.d.ts +28 -0
  266. package/dist/shell/expand.d.ts.map +1 -0
  267. package/dist/shell/expand.js +149 -0
  268. package/dist/shell/expand.js.map +1 -0
  269. package/dist/shell/fileCommands.d.ts +10 -0
  270. package/dist/shell/fileCommands.d.ts.map +1 -0
  271. package/dist/shell/fileCommands.js +208 -0
  272. package/dist/shell/fileCommands.js.map +1 -0
  273. package/dist/shell/lineEditor.d.ts +43 -0
  274. package/dist/shell/lineEditor.d.ts.map +1 -0
  275. package/dist/shell/lineEditor.js +234 -0
  276. package/dist/shell/lineEditor.js.map +1 -0
  277. package/dist/shell/npm.d.ts +6 -0
  278. package/dist/shell/npm.d.ts.map +1 -0
  279. package/dist/shell/npm.js +234 -0
  280. package/dist/shell/npm.js.map +1 -0
  281. package/dist/shell/parse.d.ts +73 -0
  282. package/dist/shell/parse.d.ts.map +1 -0
  283. package/dist/shell/parse.js +300 -0
  284. package/dist/shell/parse.js.map +1 -0
  285. package/dist/shell/program.d.ts +12 -0
  286. package/dist/shell/program.d.ts.map +1 -0
  287. package/dist/shell/program.js +219 -0
  288. package/dist/shell/program.js.map +1 -0
  289. package/dist/shell/textCommands.d.ts +15 -0
  290. package/dist/shell/textCommands.d.ts.map +1 -0
  291. package/dist/shell/textCommands.js +185 -0
  292. package/dist/shell/textCommands.js.map +1 -0
  293. package/dist/styleModules.d.ts +6 -0
  294. package/dist/styleModules.d.ts.map +1 -1
  295. package/dist/styleModules.js +14 -4
  296. package/dist/styleModules.js.map +1 -1
  297. package/dist/svelteCompiler.d.ts +28 -0
  298. package/dist/svelteCompiler.d.ts.map +1 -0
  299. package/dist/svelteCompiler.js +13 -0
  300. package/dist/svelteCompiler.js.map +1 -0
  301. package/dist/system/commands.d.ts +26 -0
  302. package/dist/system/commands.d.ts.map +1 -0
  303. package/dist/system/commands.js +53 -0
  304. package/dist/system/commands.js.map +1 -0
  305. package/dist/system/index.d.ts +23 -0
  306. package/dist/system/index.d.ts.map +1 -0
  307. package/dist/system/index.js +16 -0
  308. package/dist/system/index.js.map +1 -0
  309. package/dist/system/kernel.d.ts +54 -0
  310. package/dist/system/kernel.d.ts.map +1 -0
  311. package/dist/system/kernel.js +81 -0
  312. package/dist/system/kernel.js.map +1 -0
  313. package/dist/system/ports.d.ts +32 -0
  314. package/dist/system/ports.d.ts.map +1 -0
  315. package/dist/system/ports.js +57 -0
  316. package/dist/system/ports.js.map +1 -0
  317. package/dist/system/process.d.ts +32 -0
  318. package/dist/system/process.d.ts.map +1 -0
  319. package/dist/system/process.js +130 -0
  320. package/dist/system/process.js.map +1 -0
  321. package/dist/system/programs.d.ts +10 -0
  322. package/dist/system/programs.d.ts.map +1 -0
  323. package/dist/system/programs.js +22 -0
  324. package/dist/system/programs.js.map +1 -0
  325. package/dist/system/terminal.d.ts +45 -0
  326. package/dist/system/terminal.d.ts.map +1 -0
  327. package/dist/system/terminal.js +127 -0
  328. package/dist/system/terminal.js.map +1 -0
  329. package/dist/system/types.d.ts +100 -0
  330. package/dist/system/types.d.ts.map +1 -0
  331. package/dist/system/types.js +2 -0
  332. package/dist/system/types.js.map +1 -0
  333. package/dist/vfs.d.ts +28 -4
  334. package/dist/vfs.d.ts.map +1 -1
  335. package/dist/vfs.js +95 -32
  336. package/dist/vfs.js.map +1 -1
  337. package/dist/vueCompiler.d.ts +75 -0
  338. package/dist/vueCompiler.d.ts.map +1 -0
  339. package/dist/vueCompiler.js +67 -0
  340. package/dist/vueCompiler.js.map +1 -0
  341. package/package.json +18 -2
  342. package/src/build.ts +105 -0
  343. package/src/buildHost.ts +154 -0
  344. package/src/buildHtml.ts +101 -0
  345. package/src/bundler.ts +190 -0
  346. package/src/check/acquire.ts +212 -0
  347. package/src/check/compilerHost.ts +138 -0
  348. package/src/check/diagnostics.ts +48 -0
  349. package/src/check/index.ts +28 -0
  350. package/src/check/projects.ts +149 -0
  351. package/src/check/shims.ts +88 -0
  352. package/src/check/typeStore.ts +103 -0
  353. package/src/check/typecheck.ts +134 -0
  354. package/src/compileComponent.ts +21 -0
  355. package/src/compileScript.ts +42 -13
  356. package/src/components.ts +59 -0
  357. package/src/detectProject.ts +18 -6
  358. package/src/devServer.ts +13 -8
  359. package/src/hash.ts +22 -0
  360. package/src/index.ts +35 -6
  361. package/src/installer/bins.ts +64 -0
  362. package/src/installer/index.ts +13 -0
  363. package/src/installer/install.ts +275 -0
  364. package/src/installer/lockfile.ts +146 -0
  365. package/src/installer/registry.ts +175 -0
  366. package/src/installer/semver.ts +190 -0
  367. package/src/installer/spec.ts +53 -0
  368. package/src/installer/tar.ts +155 -0
  369. package/src/installer/tree.ts +236 -0
  370. package/src/node/assert.ts +127 -0
  371. package/src/node/buffer.ts +304 -0
  372. package/src/node/builtins.ts +123 -0
  373. package/src/node/callable.ts +25 -0
  374. package/src/node/childProcess.ts +164 -0
  375. package/src/node/crypto.ts +187 -0
  376. package/src/node/esm.ts +196 -0
  377. package/src/node/events.ts +176 -0
  378. package/src/node/fs/index.ts +277 -0
  379. package/src/node/fs/stats.ts +110 -0
  380. package/src/node/fs/sync.ts +335 -0
  381. package/src/node/hashes.ts +171 -0
  382. package/src/node/http/client.ts +173 -0
  383. package/src/node/http/index.ts +122 -0
  384. package/src/node/http/server.ts +308 -0
  385. package/src/node/http/status.ts +13 -0
  386. package/src/node/inspect.ts +166 -0
  387. package/src/node/loader.ts +293 -0
  388. package/src/node/loop.ts +193 -0
  389. package/src/node/misc.ts +250 -0
  390. package/src/node/path.ts +135 -0
  391. package/src/node/process.ts +324 -0
  392. package/src/node/program.ts +170 -0
  393. package/src/node/readline.ts +157 -0
  394. package/src/node/resolve.ts +216 -0
  395. package/src/node/runtime.ts +184 -0
  396. package/src/node/stream/index.ts +196 -0
  397. package/src/node/stream/readable.ts +345 -0
  398. package/src/node/stream/writable.ts +244 -0
  399. package/src/node/urlqs.ts +162 -0
  400. package/src/node/util.ts +145 -0
  401. package/src/node/zlib.ts +145 -0
  402. package/src/packageCdn.ts +11 -1
  403. package/src/projectConfig.ts +34 -7
  404. package/src/shell/builtins.ts +141 -0
  405. package/src/shell/context.ts +89 -0
  406. package/src/shell/devHandoff.ts +49 -0
  407. package/src/shell/exec.ts +268 -0
  408. package/src/shell/expand.ts +145 -0
  409. package/src/shell/fileCommands.ts +206 -0
  410. package/src/shell/lineEditor.ts +233 -0
  411. package/src/shell/npm.ts +229 -0
  412. package/src/shell/parse.ts +295 -0
  413. package/src/shell/program.ts +223 -0
  414. package/src/shell/textCommands.ts +177 -0
  415. package/src/styleModules.ts +15 -4
  416. package/src/svelteCompiler.ts +31 -0
  417. package/src/system/commands.ts +72 -0
  418. package/src/system/index.ts +22 -0
  419. package/src/system/kernel.ts +106 -0
  420. package/src/system/ports.ts +73 -0
  421. package/src/system/process.ts +158 -0
  422. package/src/system/programs.ts +31 -0
  423. package/src/system/terminal.ts +135 -0
  424. package/src/system/types.ts +103 -0
  425. package/src/vfs.ts +92 -28
  426. package/src/vueCompiler.ts +121 -0
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Outbound HTTP: `http.request`/`http.get` (ClientRequest → IncomingMessage) and
3
+ * the `fetch` global a program sees. Requests to localhost reach this runtime's
4
+ * own virtual servers (`loopback`); everything else goes through the browser's
5
+ * fetch, so CORS applies — a public API without CORS headers is unreachable
6
+ * from a browser page, and no shim can change that.
7
+ */
8
+ import { Buffer } from '../buffer.js';
9
+ import type { EventLoop } from '../loop.js';
10
+ import type { HttpRequestData, System } from '../../system/types.js';
11
+ import { FakeSocket, IncomingMessage, OutgoingHeaders } from './server.js';
12
+
13
+ const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '0.0.0.0', '::1', '[::1]']);
14
+ /** Headers a browser refuses to let script set; dropping them beats a TypeError. */
15
+ const FORBIDDEN = new Set(['host', 'connection', 'content-length', 'keep-alive', 'transfer-encoding', 'upgrade', 'expect', 'te', 'trailer', 'proxy-connection']);
16
+
17
+ export interface ClientDeps {
18
+ system: System;
19
+ loop: EventLoop;
20
+ }
21
+
22
+ interface RequestOptions {
23
+ protocol?: string;
24
+ host?: string;
25
+ hostname?: string;
26
+ port?: number | string;
27
+ path?: string;
28
+ method?: string;
29
+ headers?: Record<string, string | number | string[]>;
30
+ auth?: string;
31
+ timeout?: number;
32
+ signal?: AbortSignal;
33
+ }
34
+
35
+ function toOptions(input: unknown, extra: unknown, defaultProtocol: string): RequestOptions {
36
+ let options: RequestOptions = {};
37
+ if (typeof input === 'string' || input instanceof URL) {
38
+ const url = new URL(String(input));
39
+ options = { protocol: url.protocol, hostname: url.hostname.replace(/^\[|\]$/g, ''), port: url.port, path: url.pathname + url.search, auth: url.username ? `${decodeURIComponent(url.username)}:${decodeURIComponent(url.password)}` : undefined };
40
+ if (extra && typeof extra === 'object') options = { ...options, ...(extra as RequestOptions) };
41
+ } else if (input && typeof input === 'object') options = { ...(input as RequestOptions) };
42
+ options.protocol ??= defaultProtocol;
43
+ if (!options.hostname && options.host) {
44
+ const [h, p] = options.host.split(':');
45
+ options.hostname = h;
46
+ options.port ??= p;
47
+ }
48
+ options.hostname ??= 'localhost';
49
+ options.path ??= '/';
50
+ options.method = (options.method ?? 'GET').toUpperCase();
51
+ return options;
52
+ }
53
+
54
+ export function isLocalHost(hostname: string): boolean {
55
+ return LOCAL_HOSTS.has(hostname.toLowerCase());
56
+ }
57
+
58
+ function headersToRecord(headers: Headers): Record<string, string> {
59
+ const out: Record<string, string> = {};
60
+ headers.forEach((value, key) => (out[key] = value));
61
+ return out;
62
+ }
63
+
64
+ /** Perform a request against loopback or the network; returns a Fetch Response. */
65
+ export async function sendRequest(system: System, url: URL, request: HttpRequestData, signal?: AbortSignal): Promise<Response> {
66
+ if (isLocalHost(url.hostname)) {
67
+ const port = Number(url.port || (url.protocol === 'https:' ? 443 : 80));
68
+ const reply = await system.loopback(port, request);
69
+ if (!reply) throw Object.assign(new Error(`connect ECONNREFUSED 127.0.0.1:${port}`), { code: 'ECONNREFUSED', errno: -111, syscall: 'connect', address: '127.0.0.1', port });
70
+ const headers = new Headers();
71
+ for (const [k, v] of Object.entries(reply.headers)) for (const item of Array.isArray(v) ? v : [v]) headers.append(k, String(item));
72
+ const empty = reply.status === 204 || reply.status === 304 || request.method === 'HEAD';
73
+ return new Response(empty ? null : (reply.body as unknown as BodyInit), { status: reply.status, statusText: reply.statusText, headers });
74
+ }
75
+ const headers: Record<string, string> = {};
76
+ for (const [k, v] of Object.entries(request.headers)) if (!FORBIDDEN.has(k.toLowerCase())) headers[k] = v;
77
+ const hasBody = request.body && request.method !== 'GET' && request.method !== 'HEAD';
78
+ return system.fetch(url.href, { method: request.method, headers, body: hasBody ? (request.body as unknown as BodyInit) : undefined, signal });
79
+ }
80
+
81
+ export class ClientRequest extends OutgoingHeaders {
82
+ method: string;
83
+ path: string;
84
+ host: string;
85
+ protocol: string;
86
+ aborted = false;
87
+ reusedSocket = false;
88
+ socket = new FakeSocket();
89
+ connection = this.socket;
90
+ private readonly chunks: Uint8Array[] = [];
91
+ private readonly controller = new AbortController();
92
+ private readonly options: RequestOptions;
93
+
94
+ constructor(private readonly deps: ClientDeps, input: unknown, extra: unknown, callback: ((res: IncomingMessage) => void) | undefined, defaultProtocol: string) {
95
+ super({ decodeStrings: true });
96
+ if (typeof extra === 'function') [callback, extra] = [extra as typeof callback, undefined];
97
+ this.options = toOptions(input, extra, defaultProtocol);
98
+ this.method = this.options.method!;
99
+ this.path = this.options.path!;
100
+ this.host = this.options.hostname!;
101
+ this.protocol = this.options.protocol!;
102
+ for (const [k, v] of Object.entries(this.options.headers ?? {})) this.setHeader(k, v as string);
103
+ if (this.options.auth && !this.hasHeader('authorization')) this.setHeader('authorization', `Basic ${Buffer.from(this.options.auth).toString('base64')}`);
104
+ if (callback) this.once('response', callback);
105
+ this.options.signal?.addEventListener('abort', () => this.destroy(Object.assign(new Error('The operation was aborted'), { name: 'AbortError', code: 'ABORT_ERR' })));
106
+ }
107
+
108
+ override _write(chunk: Uint8Array, _encoding: string, callback: () => void): void {
109
+ this.chunks.push(chunk);
110
+ callback();
111
+ }
112
+
113
+ override _final(callback: () => void): void {
114
+ this.headersSent = true;
115
+ callback();
116
+ void this.perform();
117
+ }
118
+
119
+ abort(): void {
120
+ this.aborted = true;
121
+ this.controller.abort();
122
+ this.emit('abort');
123
+ this.destroy();
124
+ }
125
+
126
+ override destroy(error?: Error | null): this {
127
+ this.controller.abort();
128
+ return super.destroy(error);
129
+ }
130
+
131
+ setNoDelay(): void {}
132
+ setSocketKeepAlive(): void {}
133
+
134
+ private async perform(): Promise<void> {
135
+ const release = this.deps.loop.hold();
136
+ try {
137
+ const port = this.options.port ? `:${this.options.port}` : '';
138
+ const host = this.host.includes(':') ? `[${this.host}]` : this.host;
139
+ const url = new URL(`${this.protocol}//${host}${port}${this.path}`);
140
+ const headers: Record<string, string> = {};
141
+ for (const [k, v] of Object.entries(this.getHeaders())) headers[k] = Array.isArray(v) ? v.join(', ') : String(v);
142
+ const body = this.chunks.length ? Buffer.concat(this.chunks) : null;
143
+ const response = await sendRequest(this.deps.system, url, { method: this.method, url: this.path, headers, body }, this.controller.signal);
144
+ const res = new IncomingMessage(this.socket);
145
+ res.statusCode = response.status;
146
+ res.statusMessage = response.statusText;
147
+ res._fill(headersToRecord(response.headers), new Uint8Array(await response.arrayBuffer()));
148
+ this.deps.loop._run(() => {
149
+ if (!this.emit('response', res)) res.resume();
150
+ });
151
+ } catch (error) {
152
+ if (!this.aborted) this.deps.loop._run(() => this.emit('error', error));
153
+ } finally {
154
+ release();
155
+ }
156
+ }
157
+ }
158
+
159
+ /** The `fetch` a program sees: loopback-aware and counted as pending work. */
160
+ export function createFetch(deps: ClientDeps): typeof fetch {
161
+ return async (input: RequestInfo | URL, init?: RequestInit) => {
162
+ const release = deps.loop.hold();
163
+ try {
164
+ const request = new Request(input instanceof URL ? input.href : input, init);
165
+ const url = new URL(request.url);
166
+ if (!isLocalHost(url.hostname)) return await deps.system.fetch(url.href, init ?? (typeof input === 'object' && !(input instanceof URL) ? { method: request.method, headers: request.headers, body: request.body, signal: request.signal } : undefined));
167
+ const body = request.method === 'GET' || request.method === 'HEAD' ? null : new Uint8Array(await request.arrayBuffer());
168
+ return await sendRequest(deps.system, url, { method: request.method, url: url.pathname + url.search, headers: headersToRecord(request.headers), body });
169
+ } finally {
170
+ release();
171
+ }
172
+ };
173
+ }
@@ -0,0 +1,122 @@
1
+ /**
2
+ * The `http`, `https` and `net` module objects. `https.createServer` is the
3
+ * same virtual server (TLS is the preview origin's job); `net` offers just
4
+ * enough — `isIP*` and a port-reserving `createServer` — for the port-probing
5
+ * helpers (get-port, detect-port) dev tools run before listening.
6
+ */
7
+ import { EventEmitterBase } from '../events.js';
8
+ import { ClientRequest, createFetch, type ClientDeps } from './client.js';
9
+ import { FakeSocket, IncomingMessage, OutgoingHeaders, Server, ServerResponse } from './server.js';
10
+ import { METHODS, STATUS_CODES } from './status.js';
11
+
12
+ export { createFetch };
13
+
14
+ class Agent extends EventEmitterBase {
15
+ maxSockets = Infinity;
16
+ maxFreeSockets = 256;
17
+ sockets = {};
18
+ requests = {};
19
+ freeSockets = {};
20
+ constructor(readonly options: Record<string, unknown> = {}) {
21
+ super();
22
+ }
23
+ destroy(): void {}
24
+ }
25
+
26
+ export function createHttpModule(deps: ClientDeps, protocol: 'http:' | 'https:'): Record<string, unknown> {
27
+ const request = (input: unknown, extra?: unknown, callback?: (res: IncomingMessage) => void) => new ClientRequest(deps, input, extra, callback, protocol);
28
+ const get = (input: unknown, extra?: unknown, callback?: (res: IncomingMessage) => void) => {
29
+ const req = request(input, extra, callback);
30
+ req.end();
31
+ return req;
32
+ };
33
+ const globalAgent = new Agent();
34
+ return {
35
+ createServer: (options?: unknown, listener?: (req: IncomingMessage, res: ServerResponse) => void) => new Server(deps, options, listener),
36
+ request,
37
+ get,
38
+ Server: class extends Server {
39
+ constructor(options?: unknown, listener?: (req: IncomingMessage, res: ServerResponse) => void) {
40
+ super(deps, options, listener);
41
+ }
42
+ },
43
+ IncomingMessage,
44
+ ServerResponse,
45
+ OutgoingMessage: OutgoingHeaders,
46
+ ClientRequest,
47
+ Agent,
48
+ globalAgent,
49
+ STATUS_CODES,
50
+ METHODS,
51
+ maxHeaderSize: 16384,
52
+ validateHeaderName(name: string) {
53
+ if (!/^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/.test(name)) throw Object.assign(new TypeError(`Header name must be a valid HTTP token ["${name}"]`), { code: 'ERR_INVALID_HTTP_TOKEN' });
54
+ },
55
+ validateHeaderValue(name: string, value: unknown) {
56
+ if (value === undefined) throw Object.assign(new TypeError(`Invalid value "undefined" for header "${name}"`), { code: 'ERR_HTTP_INVALID_HEADER_VALUE' });
57
+ },
58
+ setMaxIdleHTTPParsers: () => undefined,
59
+ };
60
+ }
61
+
62
+ const IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/;
63
+ const IPV6 = /^(?:[0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$/i;
64
+
65
+ export function createNetModule(deps: ClientDeps): Record<string, unknown> {
66
+ /** A TCP server cannot exist here; one that only RESERVES its port keeps port probes truthful. */
67
+ class NetServer extends EventEmitterBase {
68
+ private reservation?: { port: number; close(): void };
69
+ private release?: () => void;
70
+ listening = false;
71
+ listen(...args: unknown[]): this {
72
+ const callback = typeof args[args.length - 1] === 'function' ? (args.pop() as () => void) : undefined;
73
+ const first = args[0];
74
+ const port = typeof first === 'object' && first ? Number((first as { port?: number }).port ?? 0) : Number(first ?? 0);
75
+ if (callback) this.once('listening', callback);
76
+ try {
77
+ this.reservation = deps.system.listen(port, async () => ({ status: 502, headers: { 'content-type': 'text/plain' }, body: new TextEncoder().encode('Not an HTTP server') }));
78
+ } catch (error) {
79
+ queueMicrotask(() => this.emit('error', error));
80
+ return this;
81
+ }
82
+ this.listening = true;
83
+ this.release = deps.loop.hold();
84
+ queueMicrotask(() => this.emit('listening'));
85
+ return this;
86
+ }
87
+ address() {
88
+ return this.reservation ? { address: '::', family: 'IPv6', port: this.reservation.port } : null;
89
+ }
90
+ close(callback?: () => void): this {
91
+ this.reservation?.close();
92
+ this.reservation = undefined;
93
+ this.listening = false;
94
+ this.release?.();
95
+ if (callback) this.once('close', callback);
96
+ queueMicrotask(() => this.emit('close'));
97
+ return this;
98
+ }
99
+ ref(): this { return this; }
100
+ unref(): this {
101
+ this.release?.();
102
+ this.release = undefined;
103
+ return this;
104
+ }
105
+ }
106
+ const noTcp = () => {
107
+ throw Object.assign(new Error('Raw TCP sockets are not available in the browser runtime'), { code: 'ERR_FEATURE_UNAVAILABLE_ON_PLATFORM' });
108
+ };
109
+ return {
110
+ createServer: () => new NetServer(),
111
+ Server: NetServer,
112
+ Socket: FakeSocket,
113
+ Stream: FakeSocket,
114
+ connect: noTcp,
115
+ createConnection: noTcp,
116
+ isIP: (s: string) => (IPV4.test(s) ? 4 : IPV6.test(s) ? 6 : 0),
117
+ isIPv4: (s: string) => IPV4.test(s),
118
+ isIPv6: (s: string) => IPV6.test(s),
119
+ getDefaultAutoSelectFamily: () => true,
120
+ setDefaultAutoSelectFamily: () => undefined,
121
+ };
122
+ }
@@ -0,0 +1,308 @@
1
+ /**
2
+ * `http.createServer` on a virtual port. `listen(port)` registers a handler with
3
+ * the system; each request arrives as plain data (from the preview service
4
+ * worker, or `loopback` from inside the runtime), becomes an IncomingMessage /
5
+ * ServerResponse pair for the app, and the finished response goes back as data.
6
+ * Responses are buffered: streaming (SSE, long-polling) arrives in one piece.
7
+ */
8
+ import { EventEmitterBase } from '../events.js';
9
+ import { Buffer } from '../buffer.js';
10
+ import { Readable } from '../stream/readable.js';
11
+ import { Writable } from '../stream/writable.js';
12
+ import type { EventLoop } from '../loop.js';
13
+ import type { HttpRequestData, HttpResponseData, System } from '../../system/types.js';
14
+ import { STATUS_CODES } from './status.js';
15
+
16
+ /** Enough of net.Socket for frameworks that read connection details. */
17
+ export class FakeSocket extends EventEmitterBase {
18
+ remoteAddress = '127.0.0.1';
19
+ remotePort = 50000 + Math.floor(Math.random() * 10000);
20
+ remoteFamily = 'IPv4';
21
+ localAddress = '127.0.0.1';
22
+ localPort: number;
23
+ encrypted = false;
24
+ readable = true;
25
+ writable = true;
26
+ destroyed = false;
27
+ bytesRead = 0;
28
+ bytesWritten = 0;
29
+ constructor(port = 0) {
30
+ super();
31
+ this.localPort = port;
32
+ }
33
+ setTimeout(_ms: number, cb?: () => void): this { if (cb) this.once('timeout', cb); return this; }
34
+ setNoDelay(): this { return this; }
35
+ setKeepAlive(): this { return this; }
36
+ address() { return { address: this.localAddress, family: 'IPv4', port: this.localPort }; }
37
+ ref(): this { return this; }
38
+ unref(): this { return this; }
39
+ cork(): void {}
40
+ uncork(): void {}
41
+ write(): boolean { return true; }
42
+ end(): this { return this; }
43
+ destroy(): this {
44
+ this.destroyed = true;
45
+ return this;
46
+ }
47
+ }
48
+
49
+ function lowerHeaders(headers: Record<string, string>): { headers: Record<string, string | string[]>; raw: string[] } {
50
+ const out: Record<string, string | string[]> = {};
51
+ const raw: string[] = [];
52
+ for (const [key, value] of Object.entries(headers)) {
53
+ const k = key.toLowerCase();
54
+ raw.push(key, value);
55
+ out[k] = k === 'set-cookie' ? [value] : value;
56
+ }
57
+ return { headers: out, raw };
58
+ }
59
+
60
+ export class IncomingMessage extends Readable {
61
+ httpVersion = '1.1';
62
+ httpVersionMajor = 1;
63
+ httpVersionMinor = 1;
64
+ method?: string;
65
+ url?: string;
66
+ statusCode?: number;
67
+ statusMessage?: string;
68
+ headers: Record<string, string | string[]> = {};
69
+ rawHeaders: string[] = [];
70
+ trailers: Record<string, string> = {};
71
+ rawTrailers: string[] = [];
72
+ complete = false;
73
+ aborted = false;
74
+ socket: FakeSocket;
75
+ connection: FakeSocket;
76
+
77
+ constructor(socket: FakeSocket = new FakeSocket()) {
78
+ super();
79
+ this.socket = socket;
80
+ this.connection = socket;
81
+ }
82
+
83
+ override _read(): void {
84
+ // the body is pushed up front
85
+ }
86
+
87
+ setTimeout(_ms: number, cb?: () => void): this {
88
+ if (cb) this.once('timeout', cb);
89
+ return this;
90
+ }
91
+
92
+ /** Fill from wire data; `body` null means none. */
93
+ _fill(headers: Record<string, string>, body: Uint8Array | null): void {
94
+ const { headers: lower, raw } = lowerHeaders(headers);
95
+ this.headers = lower;
96
+ this.rawHeaders = raw;
97
+ if (body?.length) this.push(Buffer.from(body));
98
+ this.push(null);
99
+ this.complete = true;
100
+ }
101
+ }
102
+
103
+ export class OutgoingHeaders extends Writable {
104
+ protected _headers = new Map<string, { name: string; value: string | string[] }>();
105
+ headersSent = false;
106
+ sendDate = true;
107
+
108
+ setHeader(name: string, value: string | number | readonly string[]): this {
109
+ if (this.headersSent) throw Object.assign(new Error('Cannot set headers after they are sent to the client'), { code: 'ERR_HTTP_HEADERS_SENT' });
110
+ this._headers.set(name.toLowerCase(), { name, value: Array.isArray(value) ? value.map(String) : String(value) });
111
+ return this;
112
+ }
113
+ appendHeader(name: string, value: string | readonly string[]): this {
114
+ const existing = this.getHeader(name);
115
+ const list = [...(existing === undefined ? [] : Array.isArray(existing) ? existing : [String(existing)]), ...(Array.isArray(value) ? value : [value as string])];
116
+ return this.setHeader(name, list);
117
+ }
118
+ getHeader(name: string): string | string[] | undefined {
119
+ return this._headers.get(name.toLowerCase())?.value;
120
+ }
121
+ getHeaders(): Record<string, string | string[]> {
122
+ const out: Record<string, string | string[]> = Object.create(null);
123
+ for (const [key, { value }] of this._headers) out[key] = value;
124
+ return out;
125
+ }
126
+ getHeaderNames(): string[] {
127
+ return [...this._headers.keys()];
128
+ }
129
+ getRawHeaderNames(): string[] {
130
+ return [...this._headers.values()].map((h) => h.name);
131
+ }
132
+ hasHeader(name: string): boolean {
133
+ return this._headers.has(name.toLowerCase());
134
+ }
135
+ removeHeader(name: string): void {
136
+ this._headers.delete(name.toLowerCase());
137
+ }
138
+ flushHeaders(): void {
139
+ this.headersSent = true;
140
+ }
141
+ setTimeout(_ms: number, cb?: () => void): this {
142
+ if (cb) this.once('timeout', cb);
143
+ return this;
144
+ }
145
+ }
146
+
147
+ export class ServerResponse extends OutgoingHeaders {
148
+ statusCode = 200;
149
+ statusMessage = '';
150
+ req: IncomingMessage;
151
+ socket: FakeSocket;
152
+ connection: FakeSocket;
153
+ chunkedEncoding = false;
154
+ shouldKeepAlive = false;
155
+ private readonly chunks: Uint8Array[] = [];
156
+
157
+ constructor(req: IncomingMessage, private readonly onDone: (response: HttpResponseData) => void) {
158
+ super({ decodeStrings: true });
159
+ this.req = req;
160
+ this.socket = req.socket;
161
+ this.connection = req.socket;
162
+ }
163
+
164
+ get finished(): boolean {
165
+ return this.writableEnded;
166
+ }
167
+
168
+ writeHead(status: number, message?: string | Record<string, unknown> | unknown[], headers?: Record<string, unknown> | unknown[]): this {
169
+ if (typeof message !== 'string') [headers, message] = [message, undefined];
170
+ this.statusCode = status;
171
+ if (message) this.statusMessage = message;
172
+ if (Array.isArray(headers)) {
173
+ for (let i = 0; i + 1 < headers.length; i += 2) this.setHeader(String(headers[i]), headers[i + 1] as string);
174
+ } else if (headers) {
175
+ for (const [k, v] of Object.entries(headers)) if (v !== undefined) this.setHeader(k, v as string);
176
+ }
177
+ this.headersSent = true;
178
+ return this;
179
+ }
180
+ writeContinue(): void {}
181
+ writeProcessing(): void {}
182
+ writeEarlyHints(): void {}
183
+ addTrailers(): void {}
184
+ assignSocket(): void {}
185
+ detachSocket(): void {}
186
+
187
+ override _write(chunk: Uint8Array, _encoding: string, callback: () => void): void {
188
+ this.headersSent = true;
189
+ this.chunks.push(chunk);
190
+ callback();
191
+ }
192
+
193
+ override _final(callback: () => void): void {
194
+ this.headersSent = true;
195
+ const headers: Record<string, string | string[]> = {};
196
+ for (const { name, value } of this._headers.values()) headers[name] = value;
197
+ const body = Buffer.concat(this.chunks);
198
+ if (this.req.method === 'HEAD') this.chunks.length = 0;
199
+ this.onDone({ status: this.statusCode, statusText: this.statusMessage || STATUS_CODES[this.statusCode] || '', headers, body: this.req.method === 'HEAD' ? new Uint8Array() : body });
200
+ callback();
201
+ }
202
+ }
203
+
204
+ export interface ServerDeps {
205
+ system: System;
206
+ loop: EventLoop;
207
+ }
208
+
209
+ export class Server extends EventEmitterBase {
210
+ listening = false;
211
+ timeout = 0;
212
+ keepAliveTimeout = 5000;
213
+ headersTimeout = 60000;
214
+ requestTimeout = 300000;
215
+ maxHeadersCount: number | null = null;
216
+ private registration?: { port: number; close(): void };
217
+ private release?: () => void;
218
+
219
+ constructor(private readonly deps: ServerDeps, options?: unknown, listener?: (req: IncomingMessage, res: ServerResponse) => void) {
220
+ super();
221
+ if (typeof options === 'function') listener = options as typeof listener;
222
+ if (listener) this.on('request', listener);
223
+ }
224
+
225
+ listen(...args: unknown[]): this {
226
+ const callback = typeof args[args.length - 1] === 'function' ? (args.pop() as () => void) : undefined;
227
+ const first = args[0];
228
+ const port = typeof first === 'object' && first ? Number((first as { port?: number }).port ?? 0) : Number(first ?? 0);
229
+ if (callback) this.once('listening', callback);
230
+ try {
231
+ this.registration = this.deps.system.listen(port, (request) => this.handle(request));
232
+ } catch (error) {
233
+ queueMicrotask(() => this.emit('error', error));
234
+ return this;
235
+ }
236
+ this.listening = true;
237
+ this.release = this.deps.loop.hold();
238
+ queueMicrotask(() => this.emit('listening'));
239
+ return this;
240
+ }
241
+
242
+ address(): { address: string; family: string; port: number } | null {
243
+ return this.registration ? { address: '::', family: 'IPv6', port: this.registration.port } : null;
244
+ }
245
+
246
+ close(callback?: (error?: Error) => void): this {
247
+ if (!this.registration) {
248
+ if (callback) queueMicrotask(() => callback(Object.assign(new Error('Server is not running.'), { code: 'ERR_SERVER_NOT_RUNNING' })));
249
+ return this;
250
+ }
251
+ this.registration.close();
252
+ this.registration = undefined;
253
+ this.listening = false;
254
+ this.release?.();
255
+ this.release = undefined;
256
+ if (callback) this.once('close', callback);
257
+ queueMicrotask(() => this.emit('close'));
258
+ return this;
259
+ }
260
+
261
+ closeAllConnections(): void {}
262
+ closeIdleConnections(): void {}
263
+ setTimeout(ms = 0, cb?: () => void): this {
264
+ this.timeout = ms;
265
+ if (cb) this.on('timeout', cb);
266
+ return this;
267
+ }
268
+ ref(): this {
269
+ if (this.registration && !this.release) this.release = this.deps.loop.hold();
270
+ return this;
271
+ }
272
+ unref(): this {
273
+ this.release?.();
274
+ this.release = undefined;
275
+ return this;
276
+ }
277
+ getConnections(cb: (error: null, count: number) => void): void {
278
+ cb(null, 0);
279
+ }
280
+
281
+ private handle(request: HttpRequestData): Promise<HttpResponseData> {
282
+ return new Promise((resolve) => {
283
+ const socket = new FakeSocket(this.registration?.port ?? 0);
284
+ const req = new IncomingMessage(socket);
285
+ req.method = request.method.toUpperCase();
286
+ req.url = request.url;
287
+ // Body parsers (body-parser/type-is) only read a body announced by
288
+ // content-length or transfer-encoding; a browser-originated request
289
+ // relayed by the service worker carries neither.
290
+ const headers = { ...request.headers };
291
+ const announced = Object.keys(headers).some((k) => /^(content-length|transfer-encoding)$/i.test(k));
292
+ if (!announced && request.body?.length) headers['content-length'] = String(request.body.length);
293
+ req._fill(headers, request.body);
294
+ const res = new ServerResponse(req, resolve);
295
+ this.deps.loop._run(() => {
296
+ try {
297
+ this.emit('request', req, res);
298
+ } catch (error) {
299
+ if (!res.writableEnded) {
300
+ res.statusCode = 500;
301
+ res.end('Internal Server Error');
302
+ }
303
+ throw error;
304
+ }
305
+ });
306
+ });
307
+ }
308
+ }
@@ -0,0 +1,13 @@
1
+ export const STATUS_CODES: Record<number, string> = {
2
+ 100: 'Continue', 101: 'Switching Protocols', 102: 'Processing', 103: 'Early Hints',
3
+ 200: 'OK', 201: 'Created', 202: 'Accepted', 203: 'Non-Authoritative Information', 204: 'No Content', 205: 'Reset Content', 206: 'Partial Content', 207: 'Multi-Status', 208: 'Already Reported', 226: 'IM Used',
4
+ 300: 'Multiple Choices', 301: 'Moved Permanently', 302: 'Found', 303: 'See Other', 304: 'Not Modified', 305: 'Use Proxy', 307: 'Temporary Redirect', 308: 'Permanent Redirect',
5
+ 400: 'Bad Request', 401: 'Unauthorized', 402: 'Payment Required', 403: 'Forbidden', 404: 'Not Found', 405: 'Method Not Allowed', 406: 'Not Acceptable', 407: 'Proxy Authentication Required',
6
+ 408: 'Request Timeout', 409: 'Conflict', 410: 'Gone', 411: 'Length Required', 412: 'Precondition Failed', 413: 'Payload Too Large', 414: 'URI Too Long', 415: 'Unsupported Media Type',
7
+ 416: 'Range Not Satisfiable', 417: 'Expectation Failed', 418: "I'm a Teapot", 421: 'Misdirected Request', 422: 'Unprocessable Entity', 423: 'Locked', 424: 'Failed Dependency', 425: 'Too Early',
8
+ 426: 'Upgrade Required', 428: 'Precondition Required', 429: 'Too Many Requests', 431: 'Request Header Fields Too Large', 451: 'Unavailable For Legal Reasons',
9
+ 500: 'Internal Server Error', 501: 'Not Implemented', 502: 'Bad Gateway', 503: 'Service Unavailable', 504: 'Gateway Timeout', 505: 'HTTP Version Not Supported', 506: 'Variant Also Negotiates',
10
+ 507: 'Insufficient Storage', 508: 'Loop Detected', 509: 'Bandwidth Limit Exceeded', 510: 'Not Extended', 511: 'Network Authentication Required',
11
+ };
12
+
13
+ export const METHODS = ['ACL', 'BIND', 'CHECKOUT', 'CONNECT', 'COPY', 'DELETE', 'GET', 'HEAD', 'LINK', 'LOCK', 'M-SEARCH', 'MERGE', 'MKACTIVITY', 'MKCALENDAR', 'MKCOL', 'MOVE', 'NOTIFY', 'OPTIONS', 'PATCH', 'POST', 'PROPFIND', 'PROPPATCH', 'PURGE', 'PUT', 'QUERY', 'REBIND', 'REPORT', 'SEARCH', 'SOURCE', 'SUBSCRIBE', 'TRACE', 'UNBIND', 'UNLINK', 'UNLOCK', 'UNSUBSCRIBE'];