@fkn/lib 0.4.9 → 0.5.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 (88) hide show
  1. package/account.cjs +1 -0
  2. package/account.d.ts +17 -0
  3. package/account.js +28 -0
  4. package/api-ByfayMm1.js +67 -0
  5. package/api-CDb2pv7C.cjs +1 -0
  6. package/background-Dk_vaVP1.cjs +1 -0
  7. package/{background-CTsVv_a0.js → background-TtzKw6g0.js} +5 -4
  8. package/chunk-B6C_zzib.cjs +1 -0
  9. package/chunk-CPXzm0be.js +11 -0
  10. package/cloud/dgram.cjs +1 -0
  11. package/cloud/dgram.d.ts +537 -0
  12. package/cloud/dgram.js +4 -0
  13. package/cloud/dns.cjs +1 -0
  14. package/cloud/dns.d.ts +12 -0
  15. package/cloud/dns.js +3 -0
  16. package/cloud/fs/promises.cjs +1 -0
  17. package/cloud/fs/promises.d.ts +45 -0
  18. package/cloud/fs/promises.js +8 -0
  19. package/cloud/fs.cjs +1 -0
  20. package/cloud/fs.d.ts +75 -0
  21. package/cloud/fs.js +20 -0
  22. package/cloud/http.cjs +1 -0
  23. package/cloud/http.d.ts +767 -0
  24. package/cloud/http.js +5 -0
  25. package/cloud/net.cjs +1 -0
  26. package/cloud/net.d.ts +606 -0
  27. package/cloud/net.js +4 -0
  28. package/cloud-BVnscun4.js +33 -0
  29. package/cloud-DTL2B5pW.cjs +1 -0
  30. package/cloud.cjs +1 -0
  31. package/cloud.d.ts +1048 -0
  32. package/cloud.js +12 -0
  33. package/desktop.cjs +1 -0
  34. package/desktop.d.ts +49 -0
  35. package/desktop.js +51 -0
  36. package/dgram-5YUb70O2.js +326 -0
  37. package/dgram-Cdi6Y7zJ.cjs +1 -0
  38. package/dgram.cjs +1 -0
  39. package/dgram.d.ts +537 -0
  40. package/dgram.js +4 -0
  41. package/dns.cjs +1 -0
  42. package/dns.d.ts +12 -0
  43. package/dns.js +6 -0
  44. package/extension-9Uv_0HdS.cjs +1 -0
  45. package/extension-Dgz0UTy0.js +245 -0
  46. package/extension.cjs +1 -0
  47. package/extension.d.ts +853 -0
  48. package/extension.js +5 -0
  49. package/fs/promises.cjs +1 -0
  50. package/fs/promises.d.ts +46 -0
  51. package/fs/promises.js +8 -0
  52. package/fs-B7JumDCn.js +78 -0
  53. package/fs-DrwvwtqC.cjs +1 -0
  54. package/fs.cjs +1 -0
  55. package/fs.d.ts +84 -0
  56. package/fs.js +5 -0
  57. package/http.cjs +9 -0
  58. package/http.d.ts +767 -0
  59. package/http.js +541 -0
  60. package/index.cjs +1 -9
  61. package/index.d.ts +197 -140
  62. package/index.js +27 -1879
  63. package/locator-Cf7M3QKN.cjs +53 -0
  64. package/{locator-Q5m8i40Z.js → locator-DxAsGV_o.js} +331 -337
  65. package/net-Bl6_W3bd.js +275 -0
  66. package/net-C5kWnI4C.cjs +1 -0
  67. package/net.cjs +1 -0
  68. package/net.d.ts +606 -0
  69. package/net.js +4 -0
  70. package/node-fs-Bd_UUx1m.js +361 -0
  71. package/node-fs-lrlD_zqB.cjs +1 -0
  72. package/opfs/promises.cjs +1 -0
  73. package/opfs/promises.d.ts +46 -0
  74. package/opfs/promises.js +6 -0
  75. package/opfs-BfcYLPGb.js +55 -0
  76. package/opfs-Dsi4FkJU.cjs +1 -0
  77. package/opfs.cjs +1 -0
  78. package/opfs.d.ts +83 -0
  79. package/opfs.js +35 -0
  80. package/package.json +91 -1
  81. package/proxy-A9UvWUaF.cjs +1 -0
  82. package/proxy-wiZN4eTR.js +14 -0
  83. package/storage-BadvHtv0.cjs +1 -0
  84. package/storage-z0q3iena.js +13 -0
  85. package/utils-BsNRWMfl.cjs +1 -0
  86. package/utils-CNydj3OT.js +52 -0
  87. package/background-BqRFQggD.cjs +0 -1
  88. package/locator-Cjl21Nkt.cjs +0 -53
package/http.js ADDED
@@ -0,0 +1,541 @@
1
+ import { n as e } from "./chunk-CPXzm0be.js";
2
+ import "./api-ByfayMm1.js";
3
+ import "./utils-CNydj3OT.js";
4
+ import { n as t, t as n } from "./net-Bl6_W3bd.js";
5
+ import { Buffer as r } from "buffer";
6
+ import { Stream as i } from "stream";
7
+ //#region src/lib/webvpn/http.ts
8
+ var a = /* @__PURE__ */ e({
9
+ Agent: () => T,
10
+ ClientRequest: () => C,
11
+ HTTPParser: () => _,
12
+ IncomingMessage: () => y,
13
+ METHODS: () => s,
14
+ STATUS_CODES: () => c,
15
+ Server: () => w,
16
+ ServerResponse: () => x,
17
+ _default: () => A,
18
+ createServer: () => k,
19
+ default: () => A,
20
+ get: () => O,
21
+ globalAgent: () => E,
22
+ request: () => D
23
+ }), 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 = {
24
+ 100: "Continue",
25
+ 101: "Switching Protocols",
26
+ 102: "Processing",
27
+ 103: "Early Hints",
28
+ 200: "OK",
29
+ 201: "Created",
30
+ 202: "Accepted",
31
+ 203: "Non-Authoritative Information",
32
+ 204: "No Content",
33
+ 205: "Reset Content",
34
+ 206: "Partial Content",
35
+ 207: "Multi-Status",
36
+ 208: "Already Reported",
37
+ 226: "IM Used",
38
+ 300: "Multiple Choices",
39
+ 301: "Moved Permanently",
40
+ 302: "Found",
41
+ 303: "See Other",
42
+ 304: "Not Modified",
43
+ 305: "Use Proxy",
44
+ 307: "Temporary Redirect",
45
+ 308: "Permanent Redirect",
46
+ 400: "Bad Request",
47
+ 401: "Unauthorized",
48
+ 402: "Payment Required",
49
+ 403: "Forbidden",
50
+ 404: "Not Found",
51
+ 405: "Method Not Allowed",
52
+ 406: "Not Acceptable",
53
+ 407: "Proxy Authentication Required",
54
+ 408: "Request Timeout",
55
+ 409: "Conflict",
56
+ 410: "Gone",
57
+ 411: "Length Required",
58
+ 412: "Precondition Failed",
59
+ 413: "Payload Too Large",
60
+ 414: "URI Too Long",
61
+ 415: "Unsupported Media Type",
62
+ 416: "Range Not Satisfiable",
63
+ 417: "Expectation Failed",
64
+ 418: "I'm a Teapot",
65
+ 421: "Misdirected Request",
66
+ 422: "Unprocessable Entity",
67
+ 423: "Locked",
68
+ 424: "Failed Dependency",
69
+ 425: "Too Early",
70
+ 426: "Upgrade Required",
71
+ 428: "Precondition Required",
72
+ 429: "Too Many Requests",
73
+ 431: "Request Header Fields Too Large",
74
+ 451: "Unavailable For Legal Reasons",
75
+ 500: "Internal Server Error",
76
+ 501: "Not Implemented",
77
+ 502: "Bad Gateway",
78
+ 503: "Service Unavailable",
79
+ 504: "Gateway Timeout",
80
+ 505: "HTTP Version Not Supported",
81
+ 506: "Variant Also Negotiates",
82
+ 507: "Insufficient Storage",
83
+ 508: "Loop Detected",
84
+ 509: "Bandwidth Limit Exceeded",
85
+ 510: "Not Extended",
86
+ 511: "Network Authentication Required"
87
+ }, l = new Set([
88
+ "content-type",
89
+ "content-length",
90
+ "user-agent",
91
+ "referer",
92
+ "host",
93
+ "authorization",
94
+ "proxy-authorization",
95
+ "if-modified-since",
96
+ "if-unmodified-since",
97
+ "from",
98
+ "location",
99
+ "max-forwards",
100
+ "retry-after",
101
+ "etag",
102
+ "last-modified",
103
+ "server",
104
+ "age",
105
+ "expires"
106
+ ]), u = 13, d = 10, f = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/, p = (e, t) => (e.code = t, e), m = (e, t) => {
107
+ if (e.length === 0) return t;
108
+ if (t.length === 0) return e;
109
+ let n = new Uint8Array(e.length + t.length);
110
+ return n.set(e, 0), n.set(t, e.length), n;
111
+ }, h = (e, t) => {
112
+ for (let n = t; n + 1 < e.length; n++) if (e[n] === u && e[n + 1] === d) return n;
113
+ return -1;
114
+ }, g = (e) => {
115
+ 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;
116
+ return -1;
117
+ }, _ = class {
118
+ buf = 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
+ return;
201
+ }
202
+ if (this.mode === "response") {
203
+ let t = e.statusCode ?? 0;
204
+ t >= 100 && t < 200 || t === 204 || t === 304 ? this.framing = "none" : this.framing = "eof";
205
+ } else this.framing = "none";
206
+ }
207
+ consumeBody() {
208
+ if (this.framing === "length") {
209
+ if (this.buf.length === 0) return !1;
210
+ let e = Math.min(this.bodyRemaining, this.buf.length);
211
+ return this.handlers.onBody(this.buf.subarray(0, e)), this.buf = this.buf.subarray(e), this.bodyRemaining -= e, this.bodyRemaining === 0;
212
+ }
213
+ return this.framing === "eof" ? (this.buf.length > 0 && (this.handlers.onBody(this.buf), this.buf = new Uint8Array()), !1) : this.framing === "chunked" ? this.consumeChunked() : !0;
214
+ }
215
+ consumeChunked() {
216
+ for (;;) if (this.chunkState === "size") {
217
+ let e = h(this.buf, 0);
218
+ if (e === -1) return !1;
219
+ let t = o.decode(this.buf.subarray(0, e)), n = parseInt(t.split(";")[0].trim(), 16);
220
+ if (this.buf = this.buf.subarray(e + 2), Number.isNaN(n)) return !0;
221
+ n === 0 ? this.chunkState = "trailer" : (this.bodyRemaining = n, this.chunkState = "data");
222
+ } else if (this.chunkState === "data") {
223
+ if (this.buf.length === 0) return !1;
224
+ let e = Math.min(this.bodyRemaining, this.buf.length);
225
+ this.handlers.onBody(this.buf.subarray(0, e)), this.buf = this.buf.subarray(e), this.bodyRemaining -= e, this.bodyRemaining === 0 && (this.chunkState = "dataCRLF");
226
+ } else if (this.chunkState === "dataCRLF") {
227
+ if (this.buf.length < 2) return !1;
228
+ this.buf = this.buf.subarray(2), this.chunkState = "size";
229
+ } else {
230
+ let e = h(this.buf, 0);
231
+ if (e === -1) return !1;
232
+ let t = e === 0;
233
+ if (this.buf = this.buf.subarray(e + 2), t) return !0;
234
+ }
235
+ }
236
+ }, 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 {
237
+ httpVersion = "1.1";
238
+ httpVersionMajor = 1;
239
+ httpVersionMinor = 1;
240
+ headers = {};
241
+ rawHeaders = [];
242
+ trailers = {};
243
+ rawTrailers = [];
244
+ method;
245
+ url;
246
+ statusCode;
247
+ statusMessage;
248
+ complete = !1;
249
+ socket;
250
+ constructor(e) {
251
+ super(), this.socket = e;
252
+ }
253
+ get connection() {
254
+ return this.socket;
255
+ }
256
+ _applyHead(e) {
257
+ 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;
258
+ }
259
+ _read() {}
260
+ setTimeout(e, t) {
261
+ return this.socket.setTimeout(e, t), this;
262
+ }
263
+ }, b = class extends i.Writable {
264
+ _headerStore = /* @__PURE__ */ new Map();
265
+ headersSent = !1;
266
+ chunkedEncoding = !1;
267
+ finished = !1;
268
+ _bodyWritten = !1;
269
+ setHeader(e, t) {
270
+ if (this.headersSent) throw p(/* @__PURE__ */ Error("Cannot set headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
271
+ 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");
272
+ if (t === void 0) throw p(/* @__PURE__ */ TypeError(`Invalid value "undefined" for header "${e}"`), "ERR_HTTP_INVALID_HEADER_VALUE");
273
+ return this._headerStore.set(e.toLowerCase(), [e, Array.isArray(t) ? [...t] : t]), this;
274
+ }
275
+ getHeader(e) {
276
+ return this._headerStore.get(e.toLowerCase())?.[1];
277
+ }
278
+ getHeaderNames() {
279
+ return [...this._headerStore.values()].map(([e]) => e);
280
+ }
281
+ getHeaders() {
282
+ let e = {};
283
+ for (let [t, n] of this._headerStore.values()) e[t] = n;
284
+ return e;
285
+ }
286
+ hasHeader(e) {
287
+ return this._headerStore.has(e.toLowerCase());
288
+ }
289
+ removeHeader(e) {
290
+ if (this.headersSent) throw Error("Cannot remove headers after they are sent to the client");
291
+ this._headerStore.delete(e.toLowerCase());
292
+ }
293
+ _storeHeader(e) {
294
+ let t = this.hasHeader("content-length"), n = this.getHeader("transfer-encoding");
295
+ typeof n == "string" && n.toLowerCase().includes("chunked") ? this.chunkedEncoding = !0 : !t && this._shouldSendBody() && (this.chunkedEncoding = !0, this.setHeader("Transfer-Encoding", "chunked"));
296
+ let r = e + "\r\n";
297
+ for (let [e, t] of this._headerStore.values()) if (Array.isArray(t)) for (let n of t) r += `${e}: ${n}\r\n`;
298
+ else r += `${e}: ${t}\r\n`;
299
+ return r += "\r\n", r;
300
+ }
301
+ _writeToSocket(e, t) {
302
+ if (!this.socket) {
303
+ t(/* @__PURE__ */ Error("Socket is not available"));
304
+ return;
305
+ }
306
+ this.socket.write(e, t);
307
+ }
308
+ write(e, t, n) {
309
+ return this._bodyWritten = !0, super.write(e, t, n);
310
+ }
311
+ _write(e, t, n) {
312
+ let i = v(e), a = [];
313
+ if (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) {
314
+ n();
315
+ return;
316
+ }
317
+ this._writeToSocket(r.concat(a), n);
318
+ }
319
+ _final(e) {
320
+ let t = [];
321
+ if (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) {
322
+ e();
323
+ return;
324
+ }
325
+ this._writeToSocket(r.concat(t), e);
326
+ }
327
+ end(e, t, n) {
328
+ if (e != null && typeof e != "function" && !this._bodyWritten && !this.headersSent && !this.chunkedEncoding && !this.hasHeader("content-length")) {
329
+ let n = typeof t == "string" ? t : void 0;
330
+ this.setHeader("Content-Length", v(e, n).length);
331
+ }
332
+ return super.end(e, t, n);
333
+ }
334
+ _headBlock;
335
+ }, x = class extends b {
336
+ statusCode = 200;
337
+ statusMessage;
338
+ _writeHeadCalled = !1;
339
+ sendDate = !0;
340
+ req;
341
+ socket;
342
+ _keepAlive = !0;
343
+ constructor(e) {
344
+ super(), this.req = e, this.socket = e.socket;
345
+ }
346
+ _shouldSendBody() {
347
+ if (this.req.method === "HEAD") return !1;
348
+ let e = this.statusCode;
349
+ return !(e >= 100 && e < 200 || e === 204 || e === 304);
350
+ }
351
+ writeHead(e, t, n) {
352
+ if (this._writeHeadCalled || this.headersSent) throw p(/* @__PURE__ */ Error("Cannot render headers after they are sent to the client"), "ERR_HTTP_HEADERS_SENT");
353
+ this._writeHeadCalled = !0, this.statusCode = e;
354
+ let r = n;
355
+ if (typeof t == "string" ? this.statusMessage = t : t != null && (r = t), Array.isArray(r)) {
356
+ let e = Array.isArray(r[0]) ? r : Array.from({ length: Math.floor(r.length / 2) }, (e, t) => [r[t * 2], r[t * 2 + 1]]);
357
+ for (let [t, n] of e) n !== void 0 && this._appendHeader(t, n);
358
+ } else if (r) for (let [e, t] of Object.entries(r)) t !== void 0 && this.setHeader(e, t);
359
+ return this;
360
+ }
361
+ _appendHeader(e, t) {
362
+ let n = this.getHeader(e);
363
+ if (n === void 0) this.setHeader(e, t);
364
+ else {
365
+ let r = [...Array.isArray(n) ? n : [n], ...Array.isArray(t) ? t : [t]].map(String);
366
+ this.setHeader(e, r);
367
+ }
368
+ }
369
+ _implicitHeader() {
370
+ let e = this.statusMessage ?? c[this.statusCode] ?? "unknown";
371
+ 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}`);
372
+ }
373
+ writeContinue() {
374
+ this._writeToSocket(r.from("HTTP/1.1 100 Continue\r\n\r\n", "latin1"), () => {});
375
+ }
376
+ setTimeout(e, t) {
377
+ return this.socket?.setTimeout(e, t), this;
378
+ }
379
+ }, S = (...e) => {
380
+ let t = {}, n = {}, r, i = [...e], a = i.shift();
381
+ if (typeof a == "string" || a instanceof URL) {
382
+ let e = typeof a == "string" ? new URL(a) : a;
383
+ t = {
384
+ protocol: e.protocol,
385
+ hostname: e.hostname,
386
+ host: e.hostname,
387
+ port: e.port,
388
+ path: `${e.pathname}${e.search}`,
389
+ auth: e.username ? `${e.username}:${e.password}` : void 0
390
+ };
391
+ let o = i.shift();
392
+ typeof o == "function" ? r = o : o && typeof o == "object" && (n = o, r = i.shift());
393
+ } else a && typeof a == "object" && (n = a, r = i.shift());
394
+ return {
395
+ options: {
396
+ ...t,
397
+ ...n
398
+ },
399
+ callback: r
400
+ };
401
+ }, C = class extends b {
402
+ method;
403
+ path;
404
+ host;
405
+ protocol;
406
+ socket;
407
+ get connection() {
408
+ return this.socket;
409
+ }
410
+ res = null;
411
+ aborted = !1;
412
+ _aborted = !1;
413
+ constructor(e, n) {
414
+ super(), this.method = (e.method ?? "GET").toUpperCase(), this.path = e.path ?? "/", this.protocol = e.protocol ?? "http:";
415
+ let i = e.hostname ?? e.host ?? "localhost";
416
+ this.host = i;
417
+ let a = Number(e.port ?? (this.protocol === "https:" ? 443 : 80));
418
+ if (n && this.once("response", n), e.headers) for (let [t, n] of Object.entries(e.headers)) n !== void 0 && this.setHeader(t, n);
419
+ if (!this.hasHeader("host")) {
420
+ let e = this.protocol === "https:" && a === 443 || this.protocol !== "https:" && a === 80;
421
+ this.setHeader("Host", e ? i : `${i}:${a}`);
422
+ }
423
+ 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) => {
424
+ this._aborted || this.emit("error", e);
425
+ }), this._attachResponseParser(), this.socket.connect({
426
+ host: i,
427
+ port: a
428
+ }, () => {
429
+ this.emit("connect");
430
+ });
431
+ }
432
+ _shouldSendBody() {
433
+ return this.method !== "GET" && this.method !== "HEAD" && this.method !== "DELETE";
434
+ }
435
+ _implicitHeader() {
436
+ this._headBlock = this._storeHeader(`${this.method} ${this.path} HTTP/1.1`);
437
+ }
438
+ _attachResponseParser() {
439
+ let e = new y(this.socket), t = new _("response", {
440
+ onHeaders: (n) => {
441
+ e._applyHead(n), this.method === "HEAD" && (t.skipBody = !0), this.res = e, this.emit("response", e);
442
+ },
443
+ onBody: (t) => {
444
+ e.push(r.from(t));
445
+ },
446
+ onComplete: () => {
447
+ e.complete = !0, e.push(null);
448
+ }
449
+ });
450
+ this.socket.on("data", (e) => {
451
+ this._aborted || t.execute(e);
452
+ }), this.socket.on("end", () => {
453
+ t.finish();
454
+ }), this.socket.on("close", () => {
455
+ this.emit("close");
456
+ });
457
+ }
458
+ abort() {
459
+ this._aborted || (this._aborted = !0, this.aborted = !0, this.emit("abort"), this.socket.destroy());
460
+ }
461
+ destroy(e) {
462
+ return this._aborted ? this : (this._aborted = !0, this.socket.destroy(e), super.destroy(e), this);
463
+ }
464
+ end(e, t, n) {
465
+ return this._aborted ? this : super.end(e, t, n);
466
+ }
467
+ _writeToSocket(e, t) {
468
+ if (this._aborted) {
469
+ t();
470
+ return;
471
+ }
472
+ super._writeToSocket(e, t);
473
+ }
474
+ setTimeout(e, t) {
475
+ return this.socket.setTimeout(e, t), this;
476
+ }
477
+ setNoDelay(e) {
478
+ this.socket.setNoDelay(e);
479
+ }
480
+ setSocketKeepAlive(e, t) {
481
+ this.socket.setKeepAlive(e, t);
482
+ }
483
+ }, w = new Proxy(class extends n {
484
+ constructor(e, t) {
485
+ let n = {}, r = t;
486
+ typeof e == "function" ? r = e : e && (n = e), super(n), r && this.on("request", r), this.on("connection", (e) => this._handleConnection(e));
487
+ }
488
+ _handleConnection(e) {
489
+ let t = null, n = new _("request", {
490
+ onHeaders: (r) => {
491
+ t = new y(e), t._applyHead(r), r.method === "HEAD" && (n.skipBody = !0);
492
+ let i = new x(t), a = String(r.headers.connection ?? "").toLowerCase();
493
+ i._keepAlive = r.httpVersionMinor >= 1 ? a !== "close" : a === "keep-alive", i.on("finish", () => {
494
+ i._keepAlive || e.end();
495
+ }), this.emit("request", t, i);
496
+ },
497
+ onBody: (e) => {
498
+ t?.push(r.from(e));
499
+ },
500
+ onComplete: () => {
501
+ t && (t.complete = !0, t.push(null)), t = null;
502
+ }
503
+ });
504
+ e.on("data", (e) => n.execute(e)), e.on("end", () => {
505
+ n.finish(), t && t.push(null);
506
+ }), e.on("error", (t) => this.emit("clientError", t, e));
507
+ }
508
+ }, { apply: (e, t, n) => new e(...n) }), T = class {
509
+ maxSockets;
510
+ maxFreeSockets;
511
+ keepAlive;
512
+ options;
513
+ constructor(e = {}) {
514
+ this.options = e, this.keepAlive = !!e.keepAlive, this.maxSockets = e.maxSockets ?? Infinity, this.maxFreeSockets = e.maxFreeSockets ?? 256;
515
+ }
516
+ getName(e = {}) {
517
+ return `${e.host ?? "localhost"}:${e.port ?? ""}:${e.localAddress ?? ""}`;
518
+ }
519
+ destroy() {}
520
+ }, E = new T(), D = (...e) => {
521
+ let { options: t, callback: n } = S(...e);
522
+ return new C(t, n);
523
+ }, O = (...e) => {
524
+ let t = D(...e);
525
+ return t.end(), t;
526
+ }, k = (e, t) => new w(e, t), A = {
527
+ METHODS: s,
528
+ STATUS_CODES: c,
529
+ Agent: T,
530
+ globalAgent: E,
531
+ Server: w,
532
+ ServerResponse: x,
533
+ IncomingMessage: y,
534
+ ClientRequest: C,
535
+ OutgoingMessage: b,
536
+ createServer: k,
537
+ request: D,
538
+ get: O
539
+ };
540
+ //#endregion
541
+ export { T as Agent, C as ClientRequest, _ as HTTPParser, y as IncomingMessage, s as METHODS, c as STATUS_CODES, w as Server, x as ServerResponse, A as _default, A as default, k as createServer, O as get, E as globalAgent, D as request, a as t };