@fkn/lib 0.9.63 → 0.9.65

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 (169) hide show
  1. package/README.md +34 -0
  2. package/account-Bm7uIcQo.d.ts +39 -0
  3. package/account-Uh0-1Cbp.js +22 -0
  4. package/{account-generation-B0cJrpDx.cjs → account-generation-ACCBzaI-.cjs} +1 -1
  5. package/{account-generation-u31dhamM.js → account-generation-BKHNe-jL.js} +2 -3
  6. package/account-m2iCmNui.cjs +1 -0
  7. package/{account-storage-ZkzqZp3A.js → account-storage-BmCVutNL.js} +4 -5
  8. package/{account-storage-Co9IvkPr.d.ts → account-storage-UmSfF63A.d.ts} +1 -66
  9. package/{account-storage-BnohkyMJ.cjs → account-storage-dYWDpqsr.cjs} +1 -1
  10. package/account.cjs +1 -1
  11. package/account.d.ts +3 -40
  12. package/account.js +1 -23
  13. package/{api-xh6lzApn.d.ts → api-0Yp9uZcV.d.ts} +3 -7
  14. package/{api-Di2Ff3jS.js → api-DRglK7ft.js} +115 -156
  15. package/api-DrvhPN56.cjs +3 -0
  16. package/api.cjs +1 -1
  17. package/api.d.ts +2 -2
  18. package/api.js +1 -2
  19. package/attach-policy.d.ts +0 -4
  20. package/attach-policy.js +2 -3
  21. package/broker-frame-CF4-yXtj.cjs +9 -0
  22. package/broker-frame-vjSpBa8d.js +51 -0
  23. package/broker-frame.cjs +1 -0
  24. package/broker-frame.d.ts +12 -0
  25. package/broker-frame.js +1 -0
  26. package/{busy-DsMWrSzc.js → busy-C1JPjoZ_.js} +1 -2
  27. package/cloud/dgram.cjs +1 -1
  28. package/cloud/dgram.d.ts +1 -1
  29. package/cloud/dgram.js +1 -2
  30. package/cloud/dns.cjs +1 -1
  31. package/cloud/dns.d.ts +2 -2
  32. package/cloud/dns.js +1 -2
  33. package/cloud/fetch.cjs +1 -1
  34. package/cloud/fetch.d.ts +1 -1
  35. package/cloud/fetch.js +1 -2
  36. package/cloud/fs/promises.cjs +1 -1
  37. package/cloud/fs/promises.d.ts +3 -5
  38. package/cloud/fs/promises.js +2 -3
  39. package/cloud/fs.cjs +1 -1
  40. package/cloud/fs.d.ts +4 -4
  41. package/cloud/fs.js +4 -34
  42. package/cloud/http.cjs +1 -1
  43. package/cloud/http.d.ts +1 -1
  44. package/cloud/http.js +1 -2
  45. package/cloud/net.cjs +1 -1
  46. package/cloud/net.d.ts +1 -1
  47. package/cloud/net.js +3 -3
  48. package/{cloud-CI7FFRMC.d.ts → cloud-BoH54gaM.d.ts} +7 -11
  49. package/{cloud-C6rG_aod.js → cloud-C7StNncS.js} +17 -17
  50. package/cloud-TN0eDUy3.cjs +1 -0
  51. package/cloud.cjs +1 -1
  52. package/cloud.d.ts +7 -7
  53. package/cloud.js +7 -7
  54. package/connect-button-2FmOM8ai.d.ts +2 -0
  55. package/{connect-button-DtsN3X1J.js → connect-button-C1wKkIhh.js} +1 -2
  56. package/{contract-BGMJVvTg.d.ts → contract-0rua6Wsh.d.ts} +11 -6
  57. package/contract.d.ts +3 -3
  58. package/contract.js +1 -2
  59. package/desktop-DOubT4ES.d.ts +57 -0
  60. package/desktop-vXKU4wEK.cjs +1 -0
  61. package/desktop-xTT7ciGX.js +50 -0
  62. package/desktop.cjs +1 -1
  63. package/desktop.d.ts +2 -58
  64. package/desktop.js +1 -51
  65. package/dgram-BBbLokVF.js +397 -0
  66. package/dgram-BYk-QDHW.d.ts +118 -0
  67. package/dgram-D9ljiUFh.cjs +1 -0
  68. package/dgram.cjs +1 -1
  69. package/dgram.d.ts +2 -119
  70. package/dgram.js +1 -410
  71. package/dns-2v96zoEh.cjs +1 -0
  72. package/dns-DyB4K2oE.d.ts +9 -0
  73. package/dns-o8DLFjP1.js +5 -0
  74. package/dns.cjs +1 -1
  75. package/dns.d.ts +3 -10
  76. package/dns.js +1 -6
  77. package/extension-BXBjpypy.cjs +1 -0
  78. package/{extension-C3_aJX7C.js → extension-D5UMnEmQ.js} +11 -12
  79. package/{extension-C1bcizcn.d.ts → extension-D98KM8W7.d.ts} +1 -27
  80. package/extension.cjs +1 -1
  81. package/extension.d.ts +2 -2
  82. package/extension.js +2 -2
  83. package/fs/promises.cjs +1 -1
  84. package/fs/promises.d.ts +2 -4
  85. package/fs/promises.js +2 -3
  86. package/fs--MLHvMW-.cjs +1 -0
  87. package/fs-BX_ghRy0.cjs +1 -0
  88. package/fs-BnWXGRik.js +33 -0
  89. package/{fs-DCJAYoYy.d.ts → fs-ChOYC6VD.d.ts} +3 -4
  90. package/{fs-DgdN2HPt.js → fs-Cw7CcUhx.js} +17 -41
  91. package/fs.cjs +1 -1
  92. package/fs.d.ts +4 -4
  93. package/fs.js +2 -2
  94. package/{hosts-t7CKGTRz.js → hosts-HUfgMimI.js} +1 -2
  95. package/http-BE3UBktN.cjs +9 -0
  96. package/http-CDhG4bUc.d.ts +187 -0
  97. package/http-DIDjdm08.js +523 -0
  98. package/http.cjs +1 -9
  99. package/http.d.ts +2 -188
  100. package/http.js +1 -542
  101. package/index-CUWTpQKP.d.ts +87 -0
  102. package/{index-BQgZVQl7.d.ts → index-CcVwh9yz.d.ts} +0 -2
  103. package/{index-C5DdoMGo.d.ts → index-Cu5EcdK0.d.ts} +0 -59
  104. package/{index-57lTXnoe.d.ts → index-D6GPJ4Ow.d.ts} +29 -26
  105. package/index.cjs +1 -1
  106. package/index.d.ts +17 -25
  107. package/index.js +22 -27
  108. package/lib-Bs-g5jyp.cjs +53 -0
  109. package/{lib-BrsqpUkv.js → lib-CtJaID_y.js} +7 -31
  110. package/{messages-AdPfdoLV.d.ts → messages-B9dOXntM.d.ts} +0 -2
  111. package/messages.d.ts +1 -1
  112. package/messages.js +1 -2
  113. package/net-COkJw8lV.js +286 -0
  114. package/net-Dk2kqtgE.cjs +1 -0
  115. package/{net-BpyIeQ8r.d.ts → net-mVAYXs8e.d.ts} +5 -7
  116. package/net.cjs +1 -1
  117. package/net.d.ts +1 -1
  118. package/net.js +3 -323
  119. package/{node-fs-DY2fO5zd.js → node-fs-B4pY08Kc.js} +3 -10
  120. package/node-fs-DN0ejGTL.cjs +1 -0
  121. package/opfs/promises.cjs +1 -1
  122. package/opfs/promises.d.ts +2 -4
  123. package/opfs/promises.js +2 -3
  124. package/{opfs-D0goLAQW.js → opfs-CzCfVam3.js} +2 -3
  125. package/opfs-D3pYzYRc.js +35 -0
  126. package/opfs-DuXvTgIl.cjs +1 -0
  127. package/opfs.cjs +1 -1
  128. package/opfs.d.ts +3 -88
  129. package/opfs.js +1 -36
  130. package/package.json +6 -1
  131. package/packages-BEadIy_h.d.ts +155 -0
  132. package/packages-Cws_rcgf.js +346 -0
  133. package/packages-DT8vPB5_.cjs +1 -0
  134. package/packages.cjs +1 -1
  135. package/packages.d.ts +3 -156
  136. package/packages.js +1 -347
  137. package/{proxy-tsVhjcl-.js → proxy-BBAQxJmP.js} +13 -13
  138. package/{proxy-Dz60YyYy.d.ts → proxy-BP40IXYD.d.ts} +2 -4
  139. package/proxy-DVgGp6A8.cjs +1 -0
  140. package/react.cjs +1 -1
  141. package/react.d.ts +16 -4
  142. package/react.js +96 -7
  143. package/{relay-choice-BGwXRC5d.js → relay-choice-Bb3oP2gw.js} +1 -2
  144. package/{relay-choice-5yUPI-tJ.d.ts → relay-choice-DOUttUnL.d.ts} +2 -4
  145. package/{rolldown-runtime-Dy4uBu1J.js → rolldown-runtime-CGnMp29N.js} +1 -2
  146. package/rooms-C6mbannC.d.ts +227 -0
  147. package/rooms-DHFS9cwA.cjs +1 -0
  148. package/rooms-DP5stTEr.js +300 -0
  149. package/rooms.cjs +1 -1
  150. package/rooms.d.ts +3 -228
  151. package/rooms.js +1 -301
  152. package/storage-BCjYihUO.cjs +1 -0
  153. package/storage-BhfImh_2.js +136 -0
  154. package/storage-DpCLksAa.d.ts +68 -0
  155. package/storage.cjs +1 -1
  156. package/storage.d.ts +3 -69
  157. package/storage.js +1 -137
  158. package/{utils-Cyq8uJiy.js → utils-DtWP-E9x.js} +1 -2
  159. package/{wire-Fk5pJaoy.d.ts → wire-DhmLnYEU.d.ts} +0 -2
  160. package/wire.d.ts +1 -1
  161. package/wire.js +1 -2
  162. package/api-BSk3dc_X.cjs +0 -3
  163. package/cloud-BoiHKoRZ.cjs +0 -1
  164. package/connect-button-Cp0NS95-.d.ts +0 -4
  165. package/extension-Crv4aUAm.cjs +0 -1
  166. package/fs-CjQTj3FA.cjs +0 -1
  167. package/lib-C_X3WR4G.cjs +0 -53
  168. package/node-fs-vsWuoMGa.cjs +0 -1
  169. package/proxy-BA92hkId.cjs +0 -1
@@ -0,0 +1,523 @@
1
+ import { t as e } from "./rolldown-runtime-CGnMp29N.js";
2
+ import { n as t, t as n } from "./net-COkJw8lV.js";
3
+ import { Buffer as r } from "buffer";
4
+ import { Stream as i } from "stream";
5
+ // src/webvpn/http.ts
6
+ var a = /* @__PURE__ */ e({
7
+ Agent: () => T,
8
+ ClientRequest: () => C,
9
+ HTTPParser: () => _,
10
+ IncomingMessage: () => y,
11
+ METHODS: () => s,
12
+ STATUS_CODES: () => c,
13
+ Server: () => w,
14
+ ServerResponse: () => x,
15
+ _default: () => A,
16
+ createServer: () => k,
17
+ default: () => A,
18
+ get: () => O,
19
+ globalAgent: () => E,
20
+ request: () => D
21
+ }), o = new TextDecoder("latin1"), s = /* @__PURE__ */ "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.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE".split("."), c = {
22
+ 100: "Continue",
23
+ 101: "Switching Protocols",
24
+ 102: "Processing",
25
+ 103: "Early Hints",
26
+ 200: "OK",
27
+ 201: "Created",
28
+ 202: "Accepted",
29
+ 203: "Non-Authoritative Information",
30
+ 204: "No Content",
31
+ 205: "Reset Content",
32
+ 206: "Partial Content",
33
+ 207: "Multi-Status",
34
+ 208: "Already Reported",
35
+ 226: "IM Used",
36
+ 300: "Multiple Choices",
37
+ 301: "Moved Permanently",
38
+ 302: "Found",
39
+ 303: "See Other",
40
+ 304: "Not Modified",
41
+ 305: "Use Proxy",
42
+ 307: "Temporary Redirect",
43
+ 308: "Permanent Redirect",
44
+ 400: "Bad Request",
45
+ 401: "Unauthorized",
46
+ 402: "Payment Required",
47
+ 403: "Forbidden",
48
+ 404: "Not Found",
49
+ 405: "Method Not Allowed",
50
+ 406: "Not Acceptable",
51
+ 407: "Proxy Authentication Required",
52
+ 408: "Request Timeout",
53
+ 409: "Conflict",
54
+ 410: "Gone",
55
+ 411: "Length Required",
56
+ 412: "Precondition Failed",
57
+ 413: "Payload Too Large",
58
+ 414: "URI Too Long",
59
+ 415: "Unsupported Media Type",
60
+ 416: "Range Not Satisfiable",
61
+ 417: "Expectation Failed",
62
+ 418: "I'm a Teapot",
63
+ 421: "Misdirected Request",
64
+ 422: "Unprocessable Entity",
65
+ 423: "Locked",
66
+ 424: "Failed Dependency",
67
+ 425: "Too Early",
68
+ 426: "Upgrade Required",
69
+ 428: "Precondition Required",
70
+ 429: "Too Many Requests",
71
+ 431: "Request Header Fields Too Large",
72
+ 451: "Unavailable For Legal Reasons",
73
+ 500: "Internal Server Error",
74
+ 501: "Not Implemented",
75
+ 502: "Bad Gateway",
76
+ 503: "Service Unavailable",
77
+ 504: "Gateway Timeout",
78
+ 505: "HTTP Version Not Supported",
79
+ 506: "Variant Also Negotiates",
80
+ 507: "Insufficient Storage",
81
+ 508: "Loop Detected",
82
+ 509: "Bandwidth Limit Exceeded",
83
+ 510: "Not Extended",
84
+ 511: "Network Authentication Required"
85
+ }, l = /* @__PURE__ */ new Set([
86
+ "content-type",
87
+ "content-length",
88
+ "user-agent",
89
+ "referer",
90
+ "host",
91
+ "authorization",
92
+ "proxy-authorization",
93
+ "if-modified-since",
94
+ "if-unmodified-since",
95
+ "from",
96
+ "location",
97
+ "max-forwards",
98
+ "retry-after",
99
+ "etag",
100
+ "last-modified",
101
+ "server",
102
+ "age",
103
+ "expires"
104
+ ]), u = 13, d = 10, f = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, p = (e, t) => (e.code = t, e), m = (e, t) => {
105
+ if (e.length === 0) return t;
106
+ if (t.length === 0) return e;
107
+ let n = new Uint8Array(e.length + t.length);
108
+ return n.set(e, 0), n.set(t, e.length), n;
109
+ }, h = (e, t) => {
110
+ for (let n = t; n + 1 < e.length; n++) if (e[n] === u && e[n + 1] === d) return n;
111
+ return -1;
112
+ }, g = (e) => {
113
+ for (let t = 0; t + 3 < e.length; t++) if (e[t] === u && e[t + 1] === d && e[t + 2] === u && e[t + 3] === d) return t;
114
+ return -1;
115
+ }, _ = class {
116
+ mode;
117
+ handlers;
118
+ buf = /* @__PURE__ */ new Uint8Array();
119
+ state = "HEAD";
120
+ framing = "none";
121
+ bodyRemaining = 0;
122
+ chunkState = "size";
123
+ skipBody = !1;
124
+ constructor(e, t) {
125
+ this.mode = e, this.handlers = t;
126
+ }
127
+ execute(e) {
128
+ this.buf = m(this.buf, e);
129
+ let t = !0;
130
+ for (; t;) if (t = !1, this.state === "HEAD") {
131
+ let e = g(this.buf);
132
+ if (e === -1) return;
133
+ let n = this.buf.subarray(0, e);
134
+ this.buf = this.buf.subarray(e + 4);
135
+ let r = this.parseHead(n);
136
+ this.handlers.onHeaders(r), this.setupBody(r), this.framing === "none" ? (this.handlers.onComplete(), this.reset(), t = this.buf.length > 0) : (this.state = "BODY", t = !0);
137
+ } else this.consumeBody() && (this.handlers.onComplete(), this.reset(), t = this.buf.length > 0);
138
+ }
139
+ finish() {
140
+ this.state === "BODY" && this.framing === "eof" && (this.handlers.onComplete(), this.reset());
141
+ }
142
+ reset() {
143
+ this.state = "HEAD", this.framing = "none", this.bodyRemaining = 0, this.chunkState = "size", this.skipBody = !1;
144
+ }
145
+ parseHead(e) {
146
+ let t = o.decode(e).split("\r\n"), n = t.shift() ?? "", r = [];
147
+ for (let e of t) (e.startsWith(" ") || e.startsWith(" ")) && r.length > 0 ? r[r.length - 1] += " " + e.trim() : r.push(e);
148
+ let i = [], a = {};
149
+ for (let e of r) {
150
+ if (!e) continue;
151
+ let t = e.indexOf(":");
152
+ if (t === -1) continue;
153
+ let n = e.slice(0, t).trim(), r = e.slice(t + 1).trim();
154
+ i.push(n, r), this.addHeader(a, n, r);
155
+ }
156
+ let s = {
157
+ httpVersionMajor: 1,
158
+ httpVersionMinor: 1,
159
+ httpVersion: "1.1",
160
+ headers: a,
161
+ rawHeaders: i
162
+ };
163
+ if (this.mode === "request") {
164
+ let [e, t, r] = n.split(" ");
165
+ s.method = (e ?? "GET").toUpperCase(), s.url = t ?? "/", this.applyVersion(s, r);
166
+ } else {
167
+ let e = n.indexOf(" "), t = n.slice(0, e), r = n.slice(e + 1), i = r.indexOf(" "), a = i === -1 ? r : r.slice(0, i);
168
+ s.statusCode = parseInt(a, 10) || 0, s.statusMessage = i === -1 ? "" : r.slice(i + 1), this.applyVersion(s, t);
169
+ }
170
+ return s;
171
+ }
172
+ applyVersion(e, t) {
173
+ let n = /HTTP\/(\d)\.(\d)/i.exec(t ?? "");
174
+ n && (e.httpVersionMajor = parseInt(n[1], 10), e.httpVersionMinor = parseInt(n[2], 10), e.httpVersion = `${e.httpVersionMajor}.${e.httpVersionMinor}`);
175
+ }
176
+ addHeader(e, t, n) {
177
+ let r = t.toLowerCase();
178
+ if (r === "set-cookie") {
179
+ let t = e["set-cookie"];
180
+ Array.isArray(t) ? t.push(n) : e["set-cookie"] = [n];
181
+ return;
182
+ }
183
+ let i = e[r];
184
+ i === void 0 ? e[r] = n : l.has(r) || (e[r] = `${i}, ${n}`);
185
+ }
186
+ setupBody(e) {
187
+ if (this.skipBody) {
188
+ this.framing = "none";
189
+ return;
190
+ }
191
+ let t = e.headers["transfer-encoding"];
192
+ if (typeof t == "string" && t.toLowerCase().includes("chunked")) {
193
+ this.framing = "chunked", this.chunkState = "size";
194
+ return;
195
+ }
196
+ let n = e.headers["content-length"];
197
+ if (typeof n == "string" && n !== "") {
198
+ let e = parseInt(n, 10);
199
+ e > 0 ? (this.framing = "length", this.bodyRemaining = e) : this.framing = "none";
200
+ } else if (this.mode === "response") {
201
+ let t = e.statusCode ?? 0;
202
+ this.framing = t >= 100 && t < 200 || t === 204 || t === 304 ? "none" : "eof";
203
+ } else this.framing = "none";
204
+ }
205
+ consumeBody() {
206
+ if (this.framing === "length") {
207
+ if (this.buf.length === 0) return !1;
208
+ let e = Math.min(this.bodyRemaining, this.buf.length);
209
+ return this.handlers.onBody(this.buf.subarray(0, e)), this.buf = this.buf.subarray(e), this.bodyRemaining -= e, this.bodyRemaining === 0;
210
+ }
211
+ return this.framing === "eof" ? (this.buf.length > 0 && (this.handlers.onBody(this.buf), this.buf = /* @__PURE__ */ new Uint8Array()), !1) : this.framing !== "chunked" || this.consumeChunked();
212
+ }
213
+ consumeChunked() {
214
+ for (;;) if (this.chunkState === "size") {
215
+ let e = h(this.buf, 0);
216
+ if (e === -1) return !1;
217
+ let t = o.decode(this.buf.subarray(0, e)), n = parseInt(t.split(";")[0].trim(), 16);
218
+ if (this.buf = this.buf.subarray(e + 2), Number.isNaN(n)) return !0;
219
+ n === 0 ? this.chunkState = "trailer" : (this.bodyRemaining = n, this.chunkState = "data");
220
+ } else if (this.chunkState === "data") {
221
+ if (this.buf.length === 0) return !1;
222
+ let e = Math.min(this.bodyRemaining, this.buf.length);
223
+ this.handlers.onBody(this.buf.subarray(0, e)), this.buf = this.buf.subarray(e), this.bodyRemaining -= e, this.bodyRemaining === 0 && (this.chunkState = "dataCRLF");
224
+ } else if (this.chunkState === "dataCRLF") {
225
+ if (this.buf.length < 2) return !1;
226
+ this.buf = this.buf.subarray(2), this.chunkState = "size";
227
+ } else {
228
+ let e = h(this.buf, 0);
229
+ if (e === -1) return !1;
230
+ let t = e === 0;
231
+ if (this.buf = this.buf.subarray(e + 2), t) return !0;
232
+ }
233
+ }
234
+ }, v = (e, t) => r.isBuffer(e) ? e : typeof e == "string" ? r.from(e, t ?? "utf8") : e instanceof Uint8Array ? r.from(e) : e instanceof ArrayBuffer ? r.from(new Uint8Array(e)) : r.from(String(e)), y = class extends i.Readable {
235
+ httpVersion = "1.1";
236
+ httpVersionMajor = 1;
237
+ httpVersionMinor = 1;
238
+ headers = {};
239
+ rawHeaders = [];
240
+ trailers = {};
241
+ rawTrailers = [];
242
+ method;
243
+ url;
244
+ statusCode;
245
+ statusMessage;
246
+ complete = !1;
247
+ socket;
248
+ constructor(e) {
249
+ super(), this.socket = e;
250
+ }
251
+ get connection() {
252
+ return this.socket;
253
+ }
254
+ _applyHead(e) {
255
+ this.httpVersion = e.httpVersion, this.httpVersionMajor = e.httpVersionMajor, this.httpVersionMinor = e.httpVersionMinor, this.headers = e.headers, this.rawHeaders = e.rawHeaders, this.method = e.method, this.url = e.url, this.statusCode = e.statusCode, this.statusMessage = e.statusMessage;
256
+ }
257
+ _read() {}
258
+ setTimeout(e, t) {
259
+ return this.socket.setTimeout(e, t), this;
260
+ }
261
+ }, b = class extends i.Writable {
262
+ _headerStore = /* @__PURE__ */ new Map();
263
+ headersSent = !1;
264
+ chunkedEncoding = !1;
265
+ finished = !1;
266
+ _bodyWritten = !1;
267
+ setHeader(e, t) {
268
+ if (this.headersSent) throw p(/* @__PURE__ */ Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
269
+ if (typeof e != "string" || !f.test(e)) throw p(/* @__PURE__ */ TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`), "ERR_INVALID_HTTP_TOKEN");
270
+ if (t === void 0) throw p(/* @__PURE__ */ TypeError(`Invalid value "undefined" for header "${e}"`), "ERR_HTTP_INVALID_HEADER_VALUE");
271
+ return this._headerStore.set(e.toLowerCase(), [e, Array.isArray(t) ? [...t] : t]), this;
272
+ }
273
+ getHeader(e) {
274
+ return this._headerStore.get(e.toLowerCase())?.[1];
275
+ }
276
+ getHeaderNames() {
277
+ return [...this._headerStore.values()].map(([e]) => e);
278
+ }
279
+ getHeaders() {
280
+ let e = {};
281
+ for (let [t, n] of this._headerStore.values()) e[t] = n;
282
+ return e;
283
+ }
284
+ hasHeader(e) {
285
+ return this._headerStore.has(e.toLowerCase());
286
+ }
287
+ removeHeader(e) {
288
+ if (this.headersSent) throw Error("Cannot remove headers after they are sent to the client");
289
+ this._headerStore.delete(e.toLowerCase());
290
+ }
291
+ _storeHeader(e) {
292
+ let t = this.hasHeader("content-length"), n = this.getHeader("transfer-encoding");
293
+ typeof n == "string" && n.toLowerCase().includes("chunked") ? this.chunkedEncoding = !0 : !t && this._shouldSendBody() && (this.chunkedEncoding = !0, this.setHeader("Transfer-Encoding", "chunked"));
294
+ let r = e + "\r\n";
295
+ for (let [e, t] of this._headerStore.values()) if (Array.isArray(t)) for (let n of t) r += `${e}: ${n}\r\n`;
296
+ else r += `${e}: ${t}\r\n`;
297
+ return r += "\r\n", r;
298
+ }
299
+ _writeToSocket(e, t) {
300
+ this.socket ? this.socket.write(e, t) : t(/* @__PURE__ */ Error("Socket is not available"));
301
+ }
302
+ write(e, t, n) {
303
+ return this._bodyWritten = !0, super.write(e, t, n);
304
+ }
305
+ _write(e, t, n) {
306
+ let i = v(e), a = [];
307
+ this.headersSent ||= (this._implicitHeader(), a.push(r.from(this._headBlock, "latin1")), !0), this.chunkedEncoding ? i.length > 0 && (a.push(r.from(`${i.length.toString(16)}\r\n`, "latin1")), a.push(i), a.push(r.from("\r\n", "latin1"))) : a.push(i), a.length === 0 ? n() : this._writeToSocket(r.concat(a), n);
308
+ }
309
+ _final(e) {
310
+ let t = [];
311
+ this.headersSent ||= (!this.chunkedEncoding && !this.hasHeader("content-length") && this.setHeader("Content-Length", 0), this._implicitHeader(), t.push(r.from(this._headBlock, "latin1")), !0), this.chunkedEncoding && t.push(r.from("0\r\n\r\n", "latin1")), this.finished = !0, t.length === 0 ? e() : this._writeToSocket(r.concat(t), e);
312
+ }
313
+ end(e, t, n) {
314
+ if (e != null && typeof e != "function" && !this._bodyWritten && !this.headersSent && !this.chunkedEncoding && !this.hasHeader("content-length")) {
315
+ let n = typeof t == "string" ? t : void 0;
316
+ this.setHeader("Content-Length", v(e, n).length);
317
+ }
318
+ return super.end(e, t, n);
319
+ }
320
+ _headBlock;
321
+ }, x = class extends b {
322
+ statusCode = 200;
323
+ statusMessage;
324
+ _writeHeadCalled = !1;
325
+ sendDate = !0;
326
+ req;
327
+ socket;
328
+ _keepAlive = !0;
329
+ constructor(e) {
330
+ super(), this.req = e, this.socket = e.socket;
331
+ }
332
+ _shouldSendBody() {
333
+ if (this.req.method === "HEAD") return !1;
334
+ let e = this.statusCode;
335
+ return !(e >= 100 && e < 200 || e === 204 || e === 304);
336
+ }
337
+ writeHead(e, t, n) {
338
+ if (this._writeHeadCalled || this.headersSent) throw p(/* @__PURE__ */ Error("Cannot render headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
339
+ this._writeHeadCalled = !0, this.statusCode = e;
340
+ let r = n;
341
+ if (typeof t == "string" ? this.statusMessage = t : t != null && (r = t), Array.isArray(r)) {
342
+ let e = Array.isArray(r[0]) ? r : Array.from({ length: Math.floor(r.length / 2) }, (e, t) => [r[t * 2], r[t * 2 + 1]]);
343
+ for (let [t, n] of e) n !== void 0 && this._appendHeader(t, n);
344
+ } else if (r) for (let [e, t] of Object.entries(r)) t !== void 0 && this.setHeader(e, t);
345
+ return this;
346
+ }
347
+ _appendHeader(e, t) {
348
+ let n = this.getHeader(e);
349
+ if (n === void 0) this.setHeader(e, t);
350
+ else {
351
+ let r = [...Array.isArray(n) ? n : [n], ...Array.isArray(t) ? t : [t]].map(String);
352
+ this.setHeader(e, r);
353
+ }
354
+ }
355
+ _implicitHeader() {
356
+ let e = this.statusMessage ?? c[this.statusCode] ?? "unknown";
357
+ this.sendDate && !this.hasHeader("date") && this.setHeader("Date", (/* @__PURE__ */ new Date()).toUTCString()), this.hasHeader("connection") || this.setHeader("Connection", this._keepAlive ? "keep-alive" : "close"), this._headBlock = this._storeHeader(`HTTP/1.1 ${this.statusCode} ${e}`);
358
+ }
359
+ writeContinue() {
360
+ this._writeToSocket(r.from("HTTP/1.1 100 Continue\r\n\r\n", "latin1"), () => {});
361
+ }
362
+ setTimeout(e, t) {
363
+ return this.socket?.setTimeout(e, t), this;
364
+ }
365
+ }, S = (...e) => {
366
+ let t = {}, n = {}, r, i = [...e], a = i.shift();
367
+ if (typeof a == "string" || a instanceof URL) {
368
+ let e = typeof a == "string" ? new URL(a) : a;
369
+ t = {
370
+ protocol: e.protocol,
371
+ hostname: e.hostname,
372
+ host: e.hostname,
373
+ port: e.port,
374
+ path: `${e.pathname}${e.search}`,
375
+ auth: e.username ? `${e.username}:${e.password}` : void 0
376
+ };
377
+ let o = i.shift();
378
+ typeof o == "function" ? r = o : o && typeof o == "object" && (n = o, r = i.shift());
379
+ } else a && typeof a == "object" && (n = a, r = i.shift());
380
+ return {
381
+ options: {
382
+ ...t,
383
+ ...n
384
+ },
385
+ callback: r
386
+ };
387
+ }, C = class extends b {
388
+ method;
389
+ path;
390
+ host;
391
+ protocol;
392
+ socket;
393
+ get connection() {
394
+ return this.socket;
395
+ }
396
+ res = null;
397
+ aborted = !1;
398
+ _aborted = !1;
399
+ constructor(e, n) {
400
+ super(), this.method = (e.method ?? "GET").toUpperCase(), this.path = e.path ?? "/", this.protocol = e.protocol ?? "http:";
401
+ let i = e.hostname ?? e.host ?? "localhost";
402
+ this.host = i;
403
+ let a = Number(e.port ?? (this.protocol === "https:" ? 443 : 80));
404
+ if (n && this.once("response", n), e.headers) for (let [t, n] of Object.entries(e.headers)) n !== void 0 && this.setHeader(t, n);
405
+ if (!this.hasHeader("host")) {
406
+ let e = this.protocol === "https:" && a === 443 || this.protocol !== "https:" && a === 80;
407
+ this.setHeader("Host", e ? i : `${i}:${a}`);
408
+ }
409
+ e.auth && !this.hasHeader("authorization") && this.setHeader("Authorization", `Basic ${r.from(e.auth).toString("base64")}`), this.socket = new t(), this.emit("socket", this.socket), this.socket.on("error", (e) => {
410
+ this._aborted || this.emit("error", e);
411
+ }), this._attachResponseParser(), this.socket.connect({
412
+ host: i,
413
+ port: a,
414
+ relay: e.relay
415
+ }, () => {
416
+ this.emit("connect");
417
+ });
418
+ }
419
+ _shouldSendBody() {
420
+ return this.method !== "GET" && this.method !== "HEAD" && this.method !== "DELETE";
421
+ }
422
+ _implicitHeader() {
423
+ this._headBlock = this._storeHeader(`${this.method} ${this.path} HTTP/1.1`);
424
+ }
425
+ _attachResponseParser() {
426
+ let e = new y(this.socket), t = new _("response", {
427
+ onHeaders: (n) => {
428
+ e._applyHead(n), this.method === "HEAD" && (t.skipBody = !0), this.res = e, this.emit("response", e);
429
+ },
430
+ onBody: (t) => {
431
+ e.push(r.from(t));
432
+ },
433
+ onComplete: () => {
434
+ e.complete = !0, e.push(null);
435
+ }
436
+ });
437
+ this.socket.on("data", (e) => {
438
+ this._aborted || t.execute(e);
439
+ }), this.socket.on("end", () => {
440
+ t.finish();
441
+ }), this.socket.on("close", () => {
442
+ this.emit("close");
443
+ });
444
+ }
445
+ abort() {
446
+ this._aborted || (this._aborted = !0, this.aborted = !0, this.emit("abort"), this.socket.destroy());
447
+ }
448
+ destroy(e) {
449
+ return this._aborted || (this._aborted = !0, this.socket.destroy(e), super.destroy(e)), this;
450
+ }
451
+ end(e, t, n) {
452
+ return this._aborted ? this : super.end(e, t, n);
453
+ }
454
+ _writeToSocket(e, t) {
455
+ this._aborted ? t() : super._writeToSocket(e, t);
456
+ }
457
+ setTimeout(e, t) {
458
+ return this.socket.setTimeout(e, t), this;
459
+ }
460
+ setNoDelay(e) {
461
+ this.socket.setNoDelay(e);
462
+ }
463
+ setSocketKeepAlive(e, t) {
464
+ this.socket.setKeepAlive(e, t);
465
+ }
466
+ }, w = new Proxy(class extends n {
467
+ constructor(e, t) {
468
+ let n = {}, r = t;
469
+ typeof e == "function" ? r = e : e && (n = e), super(n), r && this.on("request", r), this.on("connection", (e) => this._handleConnection(e));
470
+ }
471
+ _handleConnection(e) {
472
+ let t = null, n = new _("request", {
473
+ onHeaders: (r) => {
474
+ t = new y(e), t._applyHead(r), r.method === "HEAD" && (n.skipBody = !0);
475
+ let i = new x(t), a = String(r.headers.connection ?? "").toLowerCase();
476
+ i._keepAlive = r.httpVersionMinor >= 1 ? a !== "close" : a === "keep-alive", i.on("finish", () => {
477
+ i._keepAlive || e.end();
478
+ }), this.emit("request", t, i);
479
+ },
480
+ onBody: (e) => {
481
+ t?.push(r.from(e));
482
+ },
483
+ onComplete: () => {
484
+ t && (t.complete = !0, t.push(null)), t = null;
485
+ }
486
+ });
487
+ e.on("data", (e) => n.execute(e)), e.on("end", () => {
488
+ n.finish(), t && t.push(null);
489
+ }), e.on("error", (t) => this.emit("clientError", t, e));
490
+ }
491
+ }, { apply: (e, t, n) => new e(...n) }), T = class {
492
+ maxSockets;
493
+ maxFreeSockets;
494
+ keepAlive;
495
+ options;
496
+ constructor(e = {}) {
497
+ this.options = e, this.keepAlive = !!e.keepAlive, this.maxSockets = e.maxSockets ?? Infinity, this.maxFreeSockets = e.maxFreeSockets ?? 256;
498
+ }
499
+ getName(e = {}) {
500
+ return `${e.host ?? "localhost"}:${e.port ?? ""}:${e.localAddress ?? ""}`;
501
+ }
502
+ destroy() {}
503
+ }, E = new T(), D = (...e) => {
504
+ let { options: t, callback: n } = S(...e);
505
+ return new C(t, n);
506
+ }, O = (...e) => {
507
+ let t = D(...e);
508
+ return t.end(), t;
509
+ }, k = (e, t) => new w(e, t), A = {
510
+ METHODS: s,
511
+ STATUS_CODES: c,
512
+ Agent: T,
513
+ globalAgent: E,
514
+ Server: w,
515
+ ServerResponse: x,
516
+ IncomingMessage: y,
517
+ ClientRequest: C,
518
+ OutgoingMessage: b,
519
+ createServer: k,
520
+ request: D,
521
+ get: O
522
+ };
523
+ export { s as a, x as c, O as d, E as f, y as i, A as l, D as m, C as n, c as o, a as p, _ as r, w as s, T as t, k as u };
package/http.cjs CHANGED
@@ -1,9 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./net.cjs");let n=require("buffer"),r=require("stream");var i=e.t({Agent:()=>T,ClientRequest:()=>S,HTTPParser:()=>g,IncomingMessage:()=>v,METHODS:()=>o,STATUS_CODES:()=>s,Server:()=>w,ServerResponse:()=>b,_default:()=>A,createServer:()=>k,default:()=>A,get:()=>O,globalAgent:()=>E,request:()=>D}),a=new TextDecoder(`latin1`),o=`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.REBIND.REPORT.SEARCH.SOURCE.SUBSCRIBE.TRACE.UNBIND.UNLINK.UNLOCK.UNSUBSCRIBE`.split(`.`),s={100:`Continue`,101:`Switching Protocols`,102:`Processing`,103:`Early Hints`,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`,300:`Multiple Choices`,301:`Moved Permanently`,302:`Found`,303:`See Other`,304:`Not Modified`,305:`Use Proxy`,307:`Temporary Redirect`,308:`Permanent Redirect`,400:`Bad Request`,401:`Unauthorized`,402:`Payment Required`,403:`Forbidden`,404:`Not Found`,405:`Method Not Allowed`,406:`Not Acceptable`,407:`Proxy Authentication Required`,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`,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`,426:`Upgrade Required`,428:`Precondition Required`,429:`Too Many Requests`,431:`Request Header Fields Too Large`,451:`Unavailable For Legal Reasons`,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`,507:`Insufficient Storage`,508:`Loop Detected`,509:`Bandwidth Limit Exceeded`,510:`Not Extended`,511:`Network Authentication Required`},c=new Set([`content-type`,`content-length`,`user-agent`,`referer`,`host`,`authorization`,`proxy-authorization`,`if-modified-since`,`if-unmodified-since`,`from`,`location`,`max-forwards`,`retry-after`,`etag`,`last-modified`,`server`,`age`,`expires`]),l=13,u=10,d=/^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/,f=(e,t)=>(e.code=t,e),p=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Uint8Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},m=(e,t)=>{for(let n=t;n+1<e.length;n++)if(e[n]===l&&e[n+1]===u)return n;return-1},h=e=>{for(let t=0;t+3<e.length;t++)if(e[t]===l&&e[t+1]===u&&e[t+2]===l&&e[t+3]===u)return t;return-1},g=class{mode;handlers;buf=new Uint8Array;state=`HEAD`;framing=`none`;bodyRemaining=0;chunkState=`size`;skipBody=!1;constructor(e,t){this.mode=e,this.handlers=t}execute(e){this.buf=p(this.buf,e);let t=!0;for(;t;)if(t=!1,this.state===`HEAD`){let e=h(this.buf);if(e===-1)return;let n=this.buf.subarray(0,e);this.buf=this.buf.subarray(e+4);let r=this.parseHead(n);this.handlers.onHeaders(r),this.setupBody(r),this.framing===`none`?(this.handlers.onComplete(),this.reset(),t=this.buf.length>0):(this.state=`BODY`,t=!0)}else this.consumeBody()&&(this.handlers.onComplete(),this.reset(),t=this.buf.length>0)}finish(){this.state===`BODY`&&this.framing===`eof`&&(this.handlers.onComplete(),this.reset())}reset(){this.state=`HEAD`,this.framing=`none`,this.bodyRemaining=0,this.chunkState=`size`,this.skipBody=!1}parseHead(e){let t=a.decode(e).split(`\r
2
- `),n=t.shift()??``,r=[];for(let e of t)(e.startsWith(` `)||e.startsWith(` `))&&r.length>0?r[r.length-1]+=` `+e.trim():r.push(e);let i=[],o={};for(let e of r){if(!e)continue;let t=e.indexOf(`:`);if(t===-1)continue;let n=e.slice(0,t).trim(),r=e.slice(t+1).trim();i.push(n,r),this.addHeader(o,n,r)}let s={httpVersionMajor:1,httpVersionMinor:1,httpVersion:`1.1`,headers:o,rawHeaders:i};if(this.mode===`request`){let[e,t,r]=n.split(` `);s.method=(e??`GET`).toUpperCase(),s.url=t??`/`,this.applyVersion(s,r)}else{let e=n.indexOf(` `),t=n.slice(0,e),r=n.slice(e+1),i=r.indexOf(` `),a=i===-1?r:r.slice(0,i);s.statusCode=parseInt(a,10)||0,s.statusMessage=i===-1?``:r.slice(i+1),this.applyVersion(s,t)}return s}applyVersion(e,t){let n=/HTTP\/(\d)\.(\d)/i.exec(t??``);n&&(e.httpVersionMajor=parseInt(n[1],10),e.httpVersionMinor=parseInt(n[2],10),e.httpVersion=`${e.httpVersionMajor}.${e.httpVersionMinor}`)}addHeader(e,t,n){let r=t.toLowerCase();if(r===`set-cookie`){let t=e[`set-cookie`];Array.isArray(t)?t.push(n):e[`set-cookie`]=[n];return}let i=e[r];i===void 0?e[r]=n:c.has(r)||(e[r]=`${i}, ${n}`)}setupBody(e){if(this.skipBody){this.framing=`none`;return}let t=e.headers[`transfer-encoding`];if(typeof t==`string`&&t.toLowerCase().includes(`chunked`)){this.framing=`chunked`,this.chunkState=`size`;return}let n=e.headers[`content-length`];if(typeof n==`string`&&n!==``){let e=parseInt(n,10);e>0?(this.framing=`length`,this.bodyRemaining=e):this.framing=`none`;return}if(this.mode===`response`){let t=e.statusCode??0;this.framing=t>=100&&t<200||t===204||t===304?`none`:`eof`}else this.framing=`none`}consumeBody(){if(this.framing===`length`){if(this.buf.length===0)return!1;let e=Math.min(this.bodyRemaining,this.buf.length);return this.handlers.onBody(this.buf.subarray(0,e)),this.buf=this.buf.subarray(e),this.bodyRemaining-=e,this.bodyRemaining===0}return this.framing===`eof`?(this.buf.length>0&&(this.handlers.onBody(this.buf),this.buf=new Uint8Array),!1):this.framing!==`chunked`||this.consumeChunked()}consumeChunked(){for(;;)if(this.chunkState===`size`){let e=m(this.buf,0);if(e===-1)return!1;let t=a.decode(this.buf.subarray(0,e)),n=parseInt(t.split(`;`)[0].trim(),16);if(this.buf=this.buf.subarray(e+2),Number.isNaN(n))return!0;n===0?this.chunkState=`trailer`:(this.bodyRemaining=n,this.chunkState=`data`)}else if(this.chunkState===`data`){if(this.buf.length===0)return!1;let e=Math.min(this.bodyRemaining,this.buf.length);this.handlers.onBody(this.buf.subarray(0,e)),this.buf=this.buf.subarray(e),this.bodyRemaining-=e,this.bodyRemaining===0&&(this.chunkState=`dataCRLF`)}else if(this.chunkState===`dataCRLF`){if(this.buf.length<2)return!1;this.buf=this.buf.subarray(2),this.chunkState=`size`}else{let e=m(this.buf,0);if(e===-1)return!1;let t=e===0;if(this.buf=this.buf.subarray(e+2),t)return!0}}},_=(e,t)=>n.Buffer.isBuffer(e)?e:typeof e==`string`?n.Buffer.from(e,t??`utf8`):e instanceof Uint8Array?n.Buffer.from(e):e instanceof ArrayBuffer?n.Buffer.from(new Uint8Array(e)):n.Buffer.from(String(e)),v=class extends r.Stream.Readable{httpVersion=`1.1`;httpVersionMajor=1;httpVersionMinor=1;headers={};rawHeaders=[];trailers={};rawTrailers=[];method;url;statusCode;statusMessage;complete=!1;socket;constructor(e){super(),this.socket=e}get connection(){return this.socket}_applyHead(e){this.httpVersion=e.httpVersion,this.httpVersionMajor=e.httpVersionMajor,this.httpVersionMinor=e.httpVersionMinor,this.headers=e.headers,this.rawHeaders=e.rawHeaders,this.method=e.method,this.url=e.url,this.statusCode=e.statusCode,this.statusMessage=e.statusMessage}_read(){}setTimeout(e,t){return this.socket.setTimeout(e,t),this}},y=class extends r.Stream.Writable{_headerStore=new Map;headersSent=!1;chunkedEncoding=!1;finished=!1;_bodyWritten=!1;setHeader(e,t){if(this.headersSent)throw f(Error(`Cannot set headers after they are sent to the client`),`ERR_HTTP_HEADERS_SENT`);if(typeof e!=`string`||!d.test(e))throw f(TypeError(`Header name must be a valid HTTP token [${JSON.stringify(String(e))}]`),`ERR_INVALID_HTTP_TOKEN`);if(t===void 0)throw f(TypeError(`Invalid value "undefined" for header "${e}"`),`ERR_HTTP_INVALID_HEADER_VALUE`);return this._headerStore.set(e.toLowerCase(),[e,Array.isArray(t)?[...t]:t]),this}getHeader(e){return this._headerStore.get(e.toLowerCase())?.[1]}getHeaderNames(){return[...this._headerStore.values()].map(([e])=>e)}getHeaders(){let e={};for(let[t,n]of this._headerStore.values())e[t]=n;return e}hasHeader(e){return this._headerStore.has(e.toLowerCase())}removeHeader(e){if(this.headersSent)throw Error(`Cannot remove headers after they are sent to the client`);this._headerStore.delete(e.toLowerCase())}_storeHeader(e){let t=this.hasHeader(`content-length`),n=this.getHeader(`transfer-encoding`);typeof n==`string`&&n.toLowerCase().includes(`chunked`)?this.chunkedEncoding=!0:!t&&this._shouldSendBody()&&(this.chunkedEncoding=!0,this.setHeader(`Transfer-Encoding`,`chunked`));let r=e+`\r
3
- `;for(let[e,t]of this._headerStore.values())if(Array.isArray(t))for(let n of t)r+=`${e}: ${n}\r\n`;else r+=`${e}: ${t}\r\n`;return r+=`\r
4
- `,r}_writeToSocket(e,t){if(!this.socket){t(Error(`Socket is not available`));return}this.socket.write(e,t)}write(e,t,n){return this._bodyWritten=!0,super.write(e,t,n)}_write(e,t,r){let i=_(e),a=[];if(this.headersSent||=(this._implicitHeader(),a.push(n.Buffer.from(this._headBlock,`latin1`)),!0),this.chunkedEncoding?i.length>0&&(a.push(n.Buffer.from(`${i.length.toString(16)}\r\n`,`latin1`)),a.push(i),a.push(n.Buffer.from(`\r
5
- `,`latin1`))):a.push(i),a.length===0){r();return}this._writeToSocket(n.Buffer.concat(a),r)}_final(e){let t=[];if(this.headersSent||=(!this.chunkedEncoding&&!this.hasHeader(`content-length`)&&this.setHeader(`Content-Length`,0),this._implicitHeader(),t.push(n.Buffer.from(this._headBlock,`latin1`)),!0),this.chunkedEncoding&&t.push(n.Buffer.from(`0\r
6
- \r
7
- `,`latin1`)),this.finished=!0,t.length===0){e();return}this._writeToSocket(n.Buffer.concat(t),e)}end(e,t,n){if(e!=null&&typeof e!=`function`&&!this._bodyWritten&&!this.headersSent&&!this.chunkedEncoding&&!this.hasHeader(`content-length`)){let n=typeof t==`string`?t:void 0;this.setHeader(`Content-Length`,_(e,n).length)}return super.end(e,t,n)}_headBlock},b=class extends y{statusCode=200;statusMessage;_writeHeadCalled=!1;sendDate=!0;req;socket;_keepAlive=!0;constructor(e){super(),this.req=e,this.socket=e.socket}_shouldSendBody(){if(this.req.method===`HEAD`)return!1;let e=this.statusCode;return!(e>=100&&e<200||e===204||e===304)}writeHead(e,t,n){if(this._writeHeadCalled||this.headersSent)throw f(Error(`Cannot render headers after they are sent to the client`),`ERR_HTTP_HEADERS_SENT`);this._writeHeadCalled=!0,this.statusCode=e;let r=n;if(typeof t==`string`?this.statusMessage=t:t!=null&&(r=t),Array.isArray(r)){let e=Array.isArray(r[0])?r:Array.from({length:Math.floor(r.length/2)},(e,t)=>[r[t*2],r[t*2+1]]);for(let[t,n]of e)n!==void 0&&this._appendHeader(t,n)}else if(r)for(let[e,t]of Object.entries(r))t!==void 0&&this.setHeader(e,t);return this}_appendHeader(e,t){let n=this.getHeader(e);if(n===void 0)this.setHeader(e,t);else{let r=[...Array.isArray(n)?n:[n],...Array.isArray(t)?t:[t]].map(String);this.setHeader(e,r)}}_implicitHeader(){let e=this.statusMessage??s[this.statusCode]??`unknown`;this.sendDate&&!this.hasHeader(`date`)&&this.setHeader(`Date`,new Date().toUTCString()),this.hasHeader(`connection`)||this.setHeader(`Connection`,this._keepAlive?`keep-alive`:`close`),this._headBlock=this._storeHeader(`HTTP/1.1 ${this.statusCode} ${e}`)}writeContinue(){this._writeToSocket(n.Buffer.from(`HTTP/1.1 100 Continue\r
8
- \r
9
- `,`latin1`),()=>{})}setTimeout(e,t){return this.socket?.setTimeout(e,t),this}},x=(...e)=>{let t={},n={},r,i=[...e],a=i.shift();if(typeof a==`string`||a instanceof URL){let e=typeof a==`string`?new URL(a):a;t={protocol:e.protocol,hostname:e.hostname,host:e.hostname,port:e.port,path:`${e.pathname}${e.search}`,auth:e.username?`${e.username}:${e.password}`:void 0};let o=i.shift();typeof o==`function`?r=o:o&&typeof o==`object`&&(n=o,r=i.shift())}else a&&typeof a==`object`&&(n=a,r=i.shift());return{options:{...t,...n},callback:r}},S=class extends y{method;path;host;protocol;socket;get connection(){return this.socket}res=null;aborted=!1;_aborted=!1;constructor(e,r){super(),this.method=(e.method??`GET`).toUpperCase(),this.path=e.path??`/`,this.protocol=e.protocol??`http:`;let i=e.hostname??e.host??`localhost`;this.host=i;let a=Number(e.port??(this.protocol===`https:`?443:80));if(r&&this.once(`response`,r),e.headers)for(let[t,n]of Object.entries(e.headers))n!==void 0&&this.setHeader(t,n);if(!this.hasHeader(`host`)){let e=this.protocol===`https:`&&a===443||this.protocol!==`https:`&&a===80;this.setHeader(`Host`,e?i:`${i}:${a}`)}e.auth&&!this.hasHeader(`authorization`)&&this.setHeader(`Authorization`,`Basic ${n.Buffer.from(e.auth).toString(`base64`)}`),this.socket=new t.Socket,this.emit(`socket`,this.socket),this.socket.on(`error`,e=>{this._aborted||this.emit(`error`,e)}),this._attachResponseParser(),this.socket.connect({host:i,port:a,relay:e.relay},()=>{this.emit(`connect`)})}_shouldSendBody(){return this.method!==`GET`&&this.method!==`HEAD`&&this.method!==`DELETE`}_implicitHeader(){this._headBlock=this._storeHeader(`${this.method} ${this.path} HTTP/1.1`)}_attachResponseParser(){let e=new v(this.socket),t=new g(`response`,{onHeaders:n=>{e._applyHead(n),this.method===`HEAD`&&(t.skipBody=!0),this.res=e,this.emit(`response`,e)},onBody:t=>{e.push(n.Buffer.from(t))},onComplete:()=>{e.complete=!0,e.push(null)}});this.socket.on(`data`,e=>{this._aborted||t.execute(e)}),this.socket.on(`end`,()=>{t.finish()}),this.socket.on(`close`,()=>{this.emit(`close`)})}abort(){this._aborted||(this._aborted=!0,this.aborted=!0,this.emit(`abort`),this.socket.destroy())}destroy(e){return this._aborted?this:(this._aborted=!0,this.socket.destroy(e),super.destroy(e),this)}end(e,t,n){return this._aborted?this:super.end(e,t,n)}_writeToSocket(e,t){if(this._aborted){t();return}super._writeToSocket(e,t)}setTimeout(e,t){return this.socket.setTimeout(e,t),this}setNoDelay(e){this.socket.setNoDelay(e)}setSocketKeepAlive(e,t){this.socket.setKeepAlive(e,t)}},C=class extends t.Server{constructor(e,t){let n={},r=t;typeof e==`function`?r=e:e&&(n=e),super(n),r&&this.on(`request`,r),this.on(`connection`,e=>this._handleConnection(e))}_handleConnection(e){let t=null,r=new g(`request`,{onHeaders:n=>{t=new v(e),t._applyHead(n),n.method===`HEAD`&&(r.skipBody=!0);let i=new b(t),a=String(n.headers.connection??``).toLowerCase();i._keepAlive=n.httpVersionMinor>=1?a!==`close`:a===`keep-alive`,i.on(`finish`,()=>{i._keepAlive||e.end()}),this.emit(`request`,t,i)},onBody:e=>{t?.push(n.Buffer.from(e))},onComplete:()=>{t&&(t.complete=!0,t.push(null)),t=null}});e.on(`data`,e=>r.execute(e)),e.on(`end`,()=>{r.finish(),t&&t.push(null)}),e.on(`error`,t=>this.emit(`clientError`,t,e))}},w=new Proxy(C,{apply:(e,t,n)=>new e(...n)}),T=class{maxSockets;maxFreeSockets;keepAlive;options;constructor(e={}){this.options=e,this.keepAlive=!!e.keepAlive,this.maxSockets=e.maxSockets??1/0,this.maxFreeSockets=e.maxFreeSockets??256}getName(e={}){return`${e.host??`localhost`}:${e.port??``}:${e.localAddress??``}`}destroy(){}},E=new T,D=(...e)=>{let{options:t,callback:n}=x(...e);return new S(t,n)},O=(...e)=>{let t=D(...e);return t.end(),t},k=(e,t)=>new w(e,t),A={METHODS:o,STATUS_CODES:s,Agent:T,globalAgent:E,Server:w,ServerResponse:b,IncomingMessage:v,ClientRequest:S,OutgoingMessage:y,createServer:k,request:D,get:O};exports.Agent=T,exports.ClientRequest=S,exports.HTTPParser=g,exports.IncomingMessage=v,exports.METHODS=o,exports.STATUS_CODES=s,exports.Server=w,exports.ServerResponse=b,exports._default=A,exports.default=A,exports.createServer=k,exports.get=O,exports.globalAgent=E,exports.request=D,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}});
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./http-BE3UBktN.cjs");exports.Agent=e.t,exports.ClientRequest=e.n,exports.HTTPParser=e.r,exports.IncomingMessage=e.i,exports.METHODS=e.a,exports.STATUS_CODES=e.o,exports.Server=e.s,exports.ServerResponse=e.c,exports._default=e.l,exports.default=e.l,exports.createServer=e.u,exports.get=e.d,exports.globalAgent=e.f,exports.request=e.m;