@potok-web-framework/core 0.1.0 → 0.3.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.
- package/dist/block.d.ts +17 -0
- package/dist/bootstrap-app.d.ts +8 -0
- package/dist/client-only.d.ts +3 -0
- package/dist/client.mjs +133 -0
- package/dist/constants-BOAOReQ3.mjs +26 -0
- package/dist/constants.d.ts +2 -0
- package/dist/context.d.ts +12 -0
- package/dist/detect-child.d.ts +6 -0
- package/dist/error-boundary.d.ts +5 -0
- package/dist/exports/client.d.ts +1 -0
- package/dist/exports/hmr.d.ts +1 -0
- package/dist/exports/index.d.ts +14 -0
- package/dist/exports/jsx-runtime.d.ts +4 -0
- package/dist/exports/server.d.ts +1 -0
- package/dist/fragment-BahmURhz.mjs +17 -0
- package/dist/fragment.d.ts +4 -0
- package/dist/hmr/hmr-dev.d.ts +9 -0
- package/dist/hmr/register-component.d.ts +2 -0
- package/dist/hmr/registered-component.d.ts +23 -0
- package/dist/hmr/registry.d.ts +12 -0
- package/dist/hmr/types.d.ts +4 -0
- package/dist/hmr/utils.d.ts +3 -0
- package/dist/hmr.mjs +42 -0
- package/dist/html-element-Cm0RtMkT.mjs +42 -0
- package/dist/html-element.d.ts +6 -0
- package/dist/index.mjs +199 -0
- package/dist/jsx-runtime.mjs +10 -0
- package/dist/jsx-types.d.ts +11 -0
- package/dist/lazy.d.ts +7 -0
- package/dist/lib-context-reader.d.ts +5 -0
- package/dist/lib-scripts.d.ts +2 -0
- package/dist/lifecycle-4vjEuXGy.mjs +57 -0
- package/dist/lifecycle.d.ts +8 -0
- package/dist/list.d.ts +9 -0
- package/dist/portal-CbcYOHLv.mjs +44 -0
- package/dist/portal.d.ts +10 -0
- package/dist/prop-types.d.ts +939 -0
- package/dist/ref.d.ts +6 -0
- package/dist/render-to-dom.d.ts +8 -0
- package/dist/render-to-string.d.ts +2 -0
- package/dist/server-node.d.ts +10 -0
- package/dist/server.mjs +1192 -0
- package/dist/show.d.ts +6 -0
- package/dist/signals.d.ts +32 -0
- package/dist/store.d.ts +26 -0
- package/dist/text.d.ts +5 -0
- package/dist/types.d.ts +39 -0
- package/dist/utils-CAe_kbSH.mjs +345 -0
- package/dist/utils.d.ts +11 -0
- package/package.json +9 -3
- package/CHANGELOG.md +0 -7
- package/bun.lock +0 -25
- package/src/block.ts +0 -102
- package/src/bootstrap-app.ts +0 -115
- package/src/client-only.ts +0 -17
- package/src/constants.ts +0 -27
- package/src/context.ts +0 -85
- package/src/detect-child.ts +0 -21
- package/src/error-boundary.ts +0 -51
- package/src/exports/client.ts +0 -1
- package/src/exports/hmr.ts +0 -1
- package/src/exports/index.ts +0 -21
- package/src/exports/jsx-runtime.ts +0 -4
- package/src/exports/server.ts +0 -1
- package/src/fragment.ts +0 -28
- package/src/global.dev.d.ts +0 -12
- package/src/hmr/hmr-dev.ts +0 -10
- package/src/hmr/register-component.ts +0 -109
- package/src/hmr/registered-component.ts +0 -59
- package/src/hmr/registry.ts +0 -78
- package/src/hmr/types.ts +0 -6
- package/src/hmr/utils.ts +0 -20
- package/src/html-element.ts +0 -95
- package/src/jsx-types.ts +0 -13
- package/src/lazy.ts +0 -44
- package/src/lib-context-reader.ts +0 -33
- package/src/lib-scripts.ts +0 -8
- package/src/lifecycle.ts +0 -44
- package/src/list.ts +0 -175
- package/src/portal.ts +0 -101
- package/src/prop-types.ts +0 -1165
- package/src/ref.ts +0 -11
- package/src/render-to-dom.ts +0 -325
- package/src/render-to-string.ts +0 -65
- package/src/server-node.ts +0 -98
- package/src/show.ts +0 -46
- package/src/signals.ts +0 -323
- package/src/store.ts +0 -68
- package/src/text.ts +0 -35
- package/src/types.ts +0 -69
- package/src/utils.ts +0 -118
- package/tests/signals.test.ts +0 -403
- package/tsconfig.json +0 -17
- package/vite.config.ts +0 -21
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,1192 @@
|
|
|
1
|
+
import { l as createSignal } from "./utils-CAe_kbSH.mjs";
|
|
2
|
+
import { t as fragment } from "./fragment-BahmURhz.mjs";
|
|
3
|
+
import { t as PortalIn } from "./portal-CbcYOHLv.mjs";
|
|
4
|
+
import { t as CLIENT_ENTRY_FILE_NAME } from "./constants-BOAOReQ3.mjs";
|
|
5
|
+
import { t as htmlElement } from "./html-element-Cm0RtMkT.mjs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { Readable, Writable } from "node:stream";
|
|
8
|
+
import util from "node:util";
|
|
9
|
+
import { Buffer } from "node:buffer";
|
|
10
|
+
var ServerNode = class {
|
|
11
|
+
libNode;
|
|
12
|
+
parent = null;
|
|
13
|
+
children = [];
|
|
14
|
+
constructor(e) {
|
|
15
|
+
this.libNode = e;
|
|
16
|
+
}
|
|
17
|
+
addChild(e, t) {
|
|
18
|
+
if (t) {
|
|
19
|
+
let n = this.children.indexOf(t);
|
|
20
|
+
this.children.splice(n + 1, 0, e);
|
|
21
|
+
} else this.children.push(e);
|
|
22
|
+
e.parent = this;
|
|
23
|
+
}
|
|
24
|
+
remove() {
|
|
25
|
+
this.parent && this.parent.children.splice(this.parent.children.indexOf(this), 1);
|
|
26
|
+
}
|
|
27
|
+
stringify() {
|
|
28
|
+
if (this.libNode.type === "text") {
|
|
29
|
+
let e = this.libNode.context.parentBlock?.nearestParentElement?.props.tag;
|
|
30
|
+
return e && ["title", "script"].includes(e) ? String(this.libNode.props.text) : `<!-- -->${this.libNode.props.text}`;
|
|
31
|
+
} else if (this.libNode.type === "html-element") {
|
|
32
|
+
let e = `<${this.libNode.props.tag}`;
|
|
33
|
+
for (let [t, n] of Object.entries(Object.getOwnPropertyDescriptors(this.libNode.props))) {
|
|
34
|
+
if ([
|
|
35
|
+
"tag",
|
|
36
|
+
"children",
|
|
37
|
+
"ref"
|
|
38
|
+
].includes(t) || t.startsWith("on")) continue;
|
|
39
|
+
let r = n.get?.() ?? n.value;
|
|
40
|
+
if (r) {
|
|
41
|
+
if (t === "style") {
|
|
42
|
+
let t = "";
|
|
43
|
+
Object.entries(r).forEach(([e, n]) => {
|
|
44
|
+
t += `${e.replace(/([A-Z])/g, "-$1").toLowerCase()}:${n};`;
|
|
45
|
+
}), e += ` style="${t}"`;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (t.startsWith("aria")) {
|
|
49
|
+
e += ` ${t.toLowerCase().replace("aria", "aria-")}="${r}"`;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (t === "className") {
|
|
53
|
+
e += ` class="${r}"`;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
e += ` ${t}="${r}"`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return e += ">", this.children.forEach((t) => {
|
|
60
|
+
e += t.stringify();
|
|
61
|
+
}), e += `</${this.libNode.props.tag}>`, e;
|
|
62
|
+
}
|
|
63
|
+
throw Error("Not implemented");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
async function renderToString(t) {
|
|
67
|
+
let n = createSignal({
|
|
68
|
+
portals: {},
|
|
69
|
+
listeners: {}
|
|
70
|
+
}), r = /* @__PURE__ */ new Map(), i, a = [];
|
|
71
|
+
if (t({
|
|
72
|
+
parentBlock: null,
|
|
73
|
+
index: 0,
|
|
74
|
+
portals: n.portals,
|
|
75
|
+
contexts: {},
|
|
76
|
+
listeners: n.listeners,
|
|
77
|
+
isServer: !0,
|
|
78
|
+
promises: a,
|
|
79
|
+
isHydrating: !1,
|
|
80
|
+
insertNode(e, t, n) {
|
|
81
|
+
e && !r.has(e) && r.set(e, new ServerNode(e)), r.has(t) || r.set(t, new ServerNode(t));
|
|
82
|
+
let a = r.get(t);
|
|
83
|
+
if (r.set(t, a), e === null) i = a;
|
|
84
|
+
else {
|
|
85
|
+
let t = n && r.has(n) ? r.get(n) : null;
|
|
86
|
+
r.get(e)?.addChild(a, t);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
updateTextNode() {},
|
|
90
|
+
updateHtmlElementNodeProp() {},
|
|
91
|
+
removeNode(e) {
|
|
92
|
+
r.get(e)?.remove();
|
|
93
|
+
}
|
|
94
|
+
}), await Promise.all(a), !i) throw Error("Корневая нода не найдена");
|
|
95
|
+
return i.stringify();
|
|
96
|
+
}
|
|
97
|
+
var classRegExp = /^([A-Z][a-z0-9]*)+$/, kTypes = [
|
|
98
|
+
"string",
|
|
99
|
+
"function",
|
|
100
|
+
"number",
|
|
101
|
+
"object",
|
|
102
|
+
"Function",
|
|
103
|
+
"Object",
|
|
104
|
+
"boolean",
|
|
105
|
+
"bigint",
|
|
106
|
+
"symbol"
|
|
107
|
+
];
|
|
108
|
+
function determineSpecificType(e) {
|
|
109
|
+
if (e == null) return "" + e;
|
|
110
|
+
if (typeof e == "function" && e.name) return `function ${e.name}`;
|
|
111
|
+
if (typeof e == "object") return e.constructor?.name ? `an instance of ${e.constructor.name}` : `${util.inspect(e, { depth: -1 })}`;
|
|
112
|
+
let t = util.inspect(e, { colors: !1 });
|
|
113
|
+
return t.length > 28 && (t = `${t.slice(0, 25)}...`), `type ${typeof e} (${t})`;
|
|
114
|
+
}
|
|
115
|
+
var ERR_HTTP_BODY_NOT_ALLOWED = class extends Error {
|
|
116
|
+
constructor() {
|
|
117
|
+
super("Adding content for this request method or response status is not allowed.");
|
|
118
|
+
}
|
|
119
|
+
}, ERR_HTTP_CONTENT_LENGTH_MISMATCH = class extends Error {
|
|
120
|
+
constructor(e, t) {
|
|
121
|
+
super(`Response body's content-length of ${e} byte(s) does not match the content-length of ${t} byte(s) set in header`);
|
|
122
|
+
}
|
|
123
|
+
}, ERR_HTTP_HEADERS_SENT = class extends Error {
|
|
124
|
+
constructor(e) {
|
|
125
|
+
super(`Cannot ${e} headers after they are sent to the client`);
|
|
126
|
+
}
|
|
127
|
+
}, ERR_INVALID_ARG_VALUE = class extends TypeError {
|
|
128
|
+
constructor(e, t, n = "is invalid") {
|
|
129
|
+
let r = util.inspect(t);
|
|
130
|
+
r.length > 128 && (r = `${r.slice(0, 128)}...`);
|
|
131
|
+
let i = e.includes(".") ? "property" : "argument";
|
|
132
|
+
super(`The ${i} '${e}' ${n}. Received ${r}`);
|
|
133
|
+
}
|
|
134
|
+
}, ERR_INVALID_CHAR = class extends TypeError {
|
|
135
|
+
constructor(e, t) {
|
|
136
|
+
let n = `Invalid character in ${e}`;
|
|
137
|
+
t !== void 0 && (n += ` ["${t}"]`), super(n);
|
|
138
|
+
}
|
|
139
|
+
}, ERR_HTTP_INVALID_HEADER_VALUE = class extends TypeError {
|
|
140
|
+
constructor(e, t) {
|
|
141
|
+
super(`Invalid value "${e}" for header "${t}"`);
|
|
142
|
+
}
|
|
143
|
+
}, ERR_HTTP_INVALID_STATUS_CODE = class extends RangeError {
|
|
144
|
+
originalStatusCode;
|
|
145
|
+
constructor(e) {
|
|
146
|
+
super(`Invalid status code: ${e}`), this.originalStatusCode = e;
|
|
147
|
+
}
|
|
148
|
+
}, ERR_HTTP_TRAILER_INVALID = class extends Error {
|
|
149
|
+
constructor() {
|
|
150
|
+
super("Trailers are invalid with this transfer encoding");
|
|
151
|
+
}
|
|
152
|
+
}, ERR_INVALID_ARG_TYPE = class extends TypeError {
|
|
153
|
+
constructor(e, t, n) {
|
|
154
|
+
Array.isArray(t) || (t = [t]);
|
|
155
|
+
let r = "The ";
|
|
156
|
+
if (e.endsWith(" argument")) r += `${e} `;
|
|
157
|
+
else {
|
|
158
|
+
let t = e.includes(".") ? "property" : "argument";
|
|
159
|
+
r += `"${e}" ${t} `;
|
|
160
|
+
}
|
|
161
|
+
r += "must be ";
|
|
162
|
+
let i = [], a = [], o = [];
|
|
163
|
+
for (let e of t) kTypes.includes(e) ? i.push(e.toLowerCase()) : classRegExp.exec(e) === null ? o.push(e) : a.push(e);
|
|
164
|
+
if (a.length > 0) {
|
|
165
|
+
let e = i.indexOf("object");
|
|
166
|
+
e !== -1 && (i.splice(e, 1), a.push("Object"));
|
|
167
|
+
}
|
|
168
|
+
if (i.length > 0) {
|
|
169
|
+
if (i.length > 2) {
|
|
170
|
+
let e = i.pop();
|
|
171
|
+
r += `one of type ${i.join(", ")}, or ${e}`;
|
|
172
|
+
} else i.length === 2 ? r += `one of type ${i[0]} or ${i[1]}` : r += `of type ${i[0]}`;
|
|
173
|
+
(a.length > 0 || o.length > 0) && (r += " or ");
|
|
174
|
+
}
|
|
175
|
+
if (a.length > 0) {
|
|
176
|
+
if (a.length > 2) {
|
|
177
|
+
let e = a.pop();
|
|
178
|
+
r += `an instance of ${a.join(", ")}, or ${e}`;
|
|
179
|
+
} else r += `an instance of ${a[0]}`, a.length === 2 && (r += ` or ${a[1]}`);
|
|
180
|
+
o.length > 0 && (r += " or ");
|
|
181
|
+
}
|
|
182
|
+
if (o.length > 0) if (o.length > 2) {
|
|
183
|
+
let e = o.pop();
|
|
184
|
+
r += `one of ${o.join(", ")}, or ${e}`;
|
|
185
|
+
} else o.length === 2 ? r += `one of ${o[0]} or ${o[1]}` : (o[0].toLowerCase() !== o[0] && (r += "an "), r += `${o[0]}`);
|
|
186
|
+
r += `. Received ${determineSpecificType(n)}`, super(r);
|
|
187
|
+
}
|
|
188
|
+
}, ERR_INVALID_HTTP_TOKEN = class extends TypeError {
|
|
189
|
+
constructor(e, t) {
|
|
190
|
+
super(`${e} must be a valid HTTP token ["${t}"]`);
|
|
191
|
+
}
|
|
192
|
+
}, ERR_METHOD_NOT_IMPLEMENTED = class extends Error {
|
|
193
|
+
constructor(e) {
|
|
194
|
+
super(`The ${e} method is not implemented`);
|
|
195
|
+
}
|
|
196
|
+
}, ERR_STREAM_ALREADY_FINISHED = class extends Error {
|
|
197
|
+
constructor(e) {
|
|
198
|
+
super(`Cannot call ${e} after a stream was finished`);
|
|
199
|
+
}
|
|
200
|
+
}, ERR_STREAM_CANNOT_PIPE = class extends Error {
|
|
201
|
+
constructor() {
|
|
202
|
+
super("Cannot pipe, not readable");
|
|
203
|
+
}
|
|
204
|
+
}, ERR_STREAM_DESTROYED = class extends Error {
|
|
205
|
+
constructor(e) {
|
|
206
|
+
super(`Cannot call ${e} after a stream was destroyed`);
|
|
207
|
+
}
|
|
208
|
+
}, ERR_STREAM_NULL_VALUES = class extends TypeError {
|
|
209
|
+
constructor() {
|
|
210
|
+
super("May not write null values to stream");
|
|
211
|
+
}
|
|
212
|
+
}, ERR_STREAM_WRITE_AFTER_END = class extends Error {
|
|
213
|
+
constructor() {
|
|
214
|
+
super("write after end");
|
|
215
|
+
}
|
|
216
|
+
}, kHeaders = Symbol("kHeaders"), kHeadersDistinct = Symbol("kHeadersDistinct"), kHeadersCount = Symbol("kHeadersCount"), kTrailers = Symbol("kTrailers"), kTrailersDistinct = Symbol("kTrailersDistinct"), kTrailersCount = Symbol("kTrailersCount"), FetchIncomingMessage = class extends Readable {
|
|
217
|
+
get socket() {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
set socket(e) {
|
|
221
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("socket");
|
|
222
|
+
}
|
|
223
|
+
httpVersionMajor;
|
|
224
|
+
httpVersionMinor;
|
|
225
|
+
httpVersion;
|
|
226
|
+
complete = !1;
|
|
227
|
+
[kHeaders] = null;
|
|
228
|
+
[kHeadersDistinct] = null;
|
|
229
|
+
[kHeadersCount] = 0;
|
|
230
|
+
rawHeaders = [];
|
|
231
|
+
[kTrailers] = null;
|
|
232
|
+
[kTrailersDistinct] = null;
|
|
233
|
+
[kTrailersCount] = 0;
|
|
234
|
+
rawTrailers = [];
|
|
235
|
+
joinDuplicateHeaders = !1;
|
|
236
|
+
aborted = !1;
|
|
237
|
+
upgrade = !1;
|
|
238
|
+
url = "";
|
|
239
|
+
method;
|
|
240
|
+
_consuming;
|
|
241
|
+
_dumped;
|
|
242
|
+
_stream = null;
|
|
243
|
+
constructor() {
|
|
244
|
+
super({}), this._readableState.readingMore = !0, this._consuming = !1, this._dumped = !1;
|
|
245
|
+
}
|
|
246
|
+
get connection() {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
set connection(e) {
|
|
250
|
+
console.error("No support for IncomingMessage.connection");
|
|
251
|
+
}
|
|
252
|
+
get headers() {
|
|
253
|
+
if (!this[kHeaders]) {
|
|
254
|
+
this[kHeaders] = {};
|
|
255
|
+
let e = this.rawHeaders, t = this[kHeaders];
|
|
256
|
+
for (let n = 0; n < this[kHeadersCount]; n += 2) this._addHeaderLine(e[n], e[n + 1], t);
|
|
257
|
+
}
|
|
258
|
+
return this[kHeaders];
|
|
259
|
+
}
|
|
260
|
+
set headers(e) {
|
|
261
|
+
this[kHeaders] = e;
|
|
262
|
+
}
|
|
263
|
+
get headersDistinct() {
|
|
264
|
+
if (!this[kHeadersDistinct]) {
|
|
265
|
+
this[kHeadersDistinct] = {};
|
|
266
|
+
let e = this.rawHeaders, t = this[kHeadersDistinct];
|
|
267
|
+
for (let n = 0; n < this[kHeadersCount]; n += 2) this._addHeaderLineDistinct(e[n], e[n + 1], t);
|
|
268
|
+
}
|
|
269
|
+
return this[kHeadersDistinct];
|
|
270
|
+
}
|
|
271
|
+
set headersDistinct(e) {
|
|
272
|
+
this[kHeadersDistinct] = e;
|
|
273
|
+
}
|
|
274
|
+
get trailers() {
|
|
275
|
+
if (!this[kTrailers]) {
|
|
276
|
+
this[kTrailers] = {};
|
|
277
|
+
let e = this.rawTrailers, t = this[kTrailers];
|
|
278
|
+
for (let n = 0; n < this[kTrailersCount]; n += 2) this._addHeaderLine(e[n], e[n + 1], t);
|
|
279
|
+
}
|
|
280
|
+
return this[kTrailers];
|
|
281
|
+
}
|
|
282
|
+
set trailers(e) {
|
|
283
|
+
this[kTrailers] = e;
|
|
284
|
+
}
|
|
285
|
+
get trailersDistinct() {
|
|
286
|
+
if (!this[kTrailersDistinct]) {
|
|
287
|
+
this[kTrailersDistinct] = {};
|
|
288
|
+
let e = this.rawTrailers, t = this[kTrailersDistinct];
|
|
289
|
+
for (let n = 0; n < this[kTrailersCount]; n += 2) this._addHeaderLineDistinct(e[n], e[n + 1], t);
|
|
290
|
+
}
|
|
291
|
+
return this[kTrailersDistinct];
|
|
292
|
+
}
|
|
293
|
+
set trailersDistinct(e) {
|
|
294
|
+
this[kTrailersDistinct] = e;
|
|
295
|
+
}
|
|
296
|
+
setTimeout(e, t) {
|
|
297
|
+
return this;
|
|
298
|
+
}
|
|
299
|
+
async _read(e) {
|
|
300
|
+
if (this._consuming ||= (this._readableState.readingMore = !1, !0), this._stream == null) {
|
|
301
|
+
this.complete = !0, this.push(null);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
let t = this._stream.getReader();
|
|
305
|
+
try {
|
|
306
|
+
let e = await t.read();
|
|
307
|
+
e.done ? (this.complete = !0, this.push(null)) : this.push(e.value);
|
|
308
|
+
} catch (e) {
|
|
309
|
+
this.destroy(e);
|
|
310
|
+
} finally {
|
|
311
|
+
t.releaseLock();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
_destroy(e, t) {
|
|
315
|
+
(!this.readableEnded || !this.complete) && (this.aborted = !0, this.emit("aborted")), setTimeout(onError$1, 0, this, e, t);
|
|
316
|
+
}
|
|
317
|
+
_addHeaderLines(e, t) {
|
|
318
|
+
if (e?.length) {
|
|
319
|
+
let n;
|
|
320
|
+
if (this.complete ? (this.rawTrailers = e, this[kTrailersCount] = t, n = this[kTrailers]) : (this.rawHeaders = e, this[kHeadersCount] = t, n = this[kHeaders]), n) for (let r = 0; r < t; r += 2) this._addHeaderLine(e[r], e[r + 1], n);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
_addHeaderLine(e, t, n) {
|
|
324
|
+
e = matchKnownFields(e);
|
|
325
|
+
let r = e.charCodeAt(0);
|
|
326
|
+
r === 0 || r === 2 ? (e = e.slice(1), typeof n[e] == "string" ? n[e] += (r === 0 ? ", " : "; ") + t : n[e] = t) : r === 1 ? n["set-cookie"] === void 0 ? n["set-cookie"] = [t] : n["set-cookie"].push(t) : this.joinDuplicateHeaders ? n[e] === void 0 ? n[e] = t : n[e] += ", " + t : n[e] === void 0 && (n[e] = t);
|
|
327
|
+
}
|
|
328
|
+
_addHeaderLineDistinct(e, t, n) {
|
|
329
|
+
e = e.toLowerCase(), n[e] ? n[e].push(t) : n[e] = [t];
|
|
330
|
+
}
|
|
331
|
+
_dump() {
|
|
332
|
+
this._dumped || (this._dumped = !0, this.removeAllListeners("data"), this.resume());
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
function matchKnownFields(e, t = !1) {
|
|
336
|
+
switch (e.length) {
|
|
337
|
+
case 3:
|
|
338
|
+
if (e === "Age" || e === "age") return "age";
|
|
339
|
+
break;
|
|
340
|
+
case 4:
|
|
341
|
+
if (e === "Host" || e === "host") return "host";
|
|
342
|
+
if (e === "From" || e === "from") return "from";
|
|
343
|
+
if (e === "ETag" || e === "etag") return "etag";
|
|
344
|
+
if (e === "Date" || e === "date") return "\0date";
|
|
345
|
+
if (e === "Vary" || e === "vary") return "\0vary";
|
|
346
|
+
break;
|
|
347
|
+
case 6:
|
|
348
|
+
if (e === "Server" || e === "server") return "server";
|
|
349
|
+
if (e === "Cookie" || e === "cookie") return "cookie";
|
|
350
|
+
if (e === "Origin" || e === "origin") return "\0origin";
|
|
351
|
+
if (e === "Expect" || e === "expect") return "\0expect";
|
|
352
|
+
if (e === "Accept" || e === "accept") return "\0accept";
|
|
353
|
+
break;
|
|
354
|
+
case 7:
|
|
355
|
+
if (e === "Referer" || e === "referer") return "referer";
|
|
356
|
+
if (e === "Expires" || e === "expires") return "expires";
|
|
357
|
+
if (e === "Upgrade" || e === "upgrade") return "\0upgrade";
|
|
358
|
+
break;
|
|
359
|
+
case 8:
|
|
360
|
+
if (e === "Location" || e === "location") return "location";
|
|
361
|
+
if (e === "If-Match" || e === "if-match") return "\0if-match";
|
|
362
|
+
break;
|
|
363
|
+
case 10:
|
|
364
|
+
if (e === "User-Agent" || e === "user-agent") return "user-agent";
|
|
365
|
+
if (e === "Set-Cookie" || e === "set-cookie") return "";
|
|
366
|
+
if (e === "Connection" || e === "connection") return "\0connection";
|
|
367
|
+
break;
|
|
368
|
+
case 11:
|
|
369
|
+
if (e === "Retry-After" || e === "retry-after") return "retry-after";
|
|
370
|
+
break;
|
|
371
|
+
case 12:
|
|
372
|
+
if (e === "Content-Type" || e === "content-type") return "content-type";
|
|
373
|
+
if (e === "Max-Forwards" || e === "max-forwards") return "max-forwards";
|
|
374
|
+
break;
|
|
375
|
+
case 13:
|
|
376
|
+
if (e === "Authorization" || e === "authorization") return "authorization";
|
|
377
|
+
if (e === "Last-Modified" || e === "last-modified") return "last-modified";
|
|
378
|
+
if (e === "Cache-Control" || e === "cache-control") return "\0cache-control";
|
|
379
|
+
if (e === "If-None-Match" || e === "if-none-match") return "\0if-none-match";
|
|
380
|
+
break;
|
|
381
|
+
case 14:
|
|
382
|
+
if (e === "Content-Length" || e === "content-length") return "content-length";
|
|
383
|
+
break;
|
|
384
|
+
case 15:
|
|
385
|
+
if (e === "Accept-Encoding" || e === "accept-encoding") return "\0accept-encoding";
|
|
386
|
+
if (e === "Accept-Language" || e === "accept-language") return "\0accept-language";
|
|
387
|
+
if (e === "X-Forwarded-For" || e === "x-forwarded-for") return "\0x-forwarded-for";
|
|
388
|
+
break;
|
|
389
|
+
case 16:
|
|
390
|
+
if (e === "Content-Encoding" || e === "content-encoding") return "\0content-encoding";
|
|
391
|
+
if (e === "X-Forwarded-Host" || e === "x-forwarded-host") return "\0x-forwarded-host";
|
|
392
|
+
break;
|
|
393
|
+
case 17:
|
|
394
|
+
if (e === "If-Modified-Since" || e === "if-modified-since") return "if-modified-since";
|
|
395
|
+
if (e === "Transfer-Encoding" || e === "transfer-encoding") return "\0transfer-encoding";
|
|
396
|
+
if (e === "X-Forwarded-Proto" || e === "x-forwarded-proto") return "\0x-forwarded-proto";
|
|
397
|
+
break;
|
|
398
|
+
case 19:
|
|
399
|
+
if (e === "Proxy-Authorization" || e === "proxy-authorization") return "proxy-authorization";
|
|
400
|
+
if (e === "If-Unmodified-Since" || e === "if-unmodified-since") return "if-unmodified-since";
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
return t ? "\0" + e : matchKnownFields(e.toLowerCase(), !0);
|
|
404
|
+
}
|
|
405
|
+
function onError$1(e, t, n) {
|
|
406
|
+
e.listenerCount("error") === 0 ? n() : n(t);
|
|
407
|
+
}
|
|
408
|
+
function validateString(e, t) {
|
|
409
|
+
if (typeof e != "string") throw new ERR_INVALID_ARG_TYPE(t, "string", e);
|
|
410
|
+
}
|
|
411
|
+
var linkValueRegExp = /^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;
|
|
412
|
+
function validateLinkHeaderFormat(e, t) {
|
|
413
|
+
if (e === void 0 || !linkValueRegExp.exec(e)) throw new ERR_INVALID_ARG_VALUE(t, e, "must be an array or string of format \"</styles.css>; rel=preload; as=style\"");
|
|
414
|
+
}
|
|
415
|
+
function validateLinkHeaderValue(e) {
|
|
416
|
+
if (typeof e == "string") return validateLinkHeaderFormat(e, "hints"), e;
|
|
417
|
+
if (Array.isArray(e)) {
|
|
418
|
+
let t = e.length, n = "";
|
|
419
|
+
if (t === 0) return n;
|
|
420
|
+
for (let r = 0; r < t; r++) {
|
|
421
|
+
let i = e[r];
|
|
422
|
+
validateLinkHeaderFormat(i, "hints"), n += i, r !== t - 1 && (n += ", ");
|
|
423
|
+
}
|
|
424
|
+
return n;
|
|
425
|
+
}
|
|
426
|
+
throw new ERR_INVALID_ARG_VALUE("hints", e, "must be an array or string of format \"</styles.css>; rel=preload; as=style\"");
|
|
427
|
+
}
|
|
428
|
+
function isUint8Array(e) {
|
|
429
|
+
return e != null && e[Symbol.toStringTag] === "Uint8Array";
|
|
430
|
+
}
|
|
431
|
+
const kNeedDrain = Symbol("kNeedDrain"), kOutHeaders = Symbol("kOutHeaders");
|
|
432
|
+
function utcDate() {
|
|
433
|
+
return (/* @__PURE__ */ new Date()).toUTCString();
|
|
434
|
+
}
|
|
435
|
+
function getDefaultHighWaterMark(e) {
|
|
436
|
+
return e ? 16 : 64 * 1024;
|
|
437
|
+
}
|
|
438
|
+
var tokenRegExp = /^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/;
|
|
439
|
+
function checkIsHttpToken(e) {
|
|
440
|
+
return tokenRegExp.test(e);
|
|
441
|
+
}
|
|
442
|
+
var headerCharRegex$1 = /[^\t\x20-\x7e\x80-\xff]/;
|
|
443
|
+
function checkInvalidHeaderChar$1(e) {
|
|
444
|
+
return headerCharRegex$1.test(e);
|
|
445
|
+
}
|
|
446
|
+
const chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;
|
|
447
|
+
var kCorked = Symbol("corked"), kChunkedBuffer = Symbol("kChunkedBuffer"), kChunkedLength = Symbol("kChunkedLength"), kUniqueHeaders = Symbol("kUniqueHeaders"), kBytesWritten = Symbol("kBytesWritten"), kErrored = Symbol("errored"), kHighWaterMark = Symbol("kHighWaterMark"), kRejectNonStandardBodyWrites = Symbol("kRejectNonStandardBodyWrites"), nop = () => {}, RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
|
|
448
|
+
function isCookieField(e) {
|
|
449
|
+
return e.length === 6 && e.toLowerCase() === "cookie";
|
|
450
|
+
}
|
|
451
|
+
function isContentDispositionField(e) {
|
|
452
|
+
return e.length === 19 && e.toLowerCase() === "content-disposition";
|
|
453
|
+
}
|
|
454
|
+
var WrittenDataBuffer = class {
|
|
455
|
+
[kCorked] = 0;
|
|
456
|
+
[kHighWaterMark] = getDefaultHighWaterMark();
|
|
457
|
+
entries = [];
|
|
458
|
+
onWrite;
|
|
459
|
+
constructor(e = {}) {
|
|
460
|
+
this.onWrite = e.onWrite;
|
|
461
|
+
}
|
|
462
|
+
write(e, t, n) {
|
|
463
|
+
return this.entries.push({
|
|
464
|
+
data: e,
|
|
465
|
+
length: e.length,
|
|
466
|
+
encoding: t,
|
|
467
|
+
callback: n,
|
|
468
|
+
written: !1
|
|
469
|
+
}), this._flush(), !0;
|
|
470
|
+
}
|
|
471
|
+
cork() {
|
|
472
|
+
this[kCorked]++;
|
|
473
|
+
}
|
|
474
|
+
uncork() {
|
|
475
|
+
this[kCorked]--, this._flush();
|
|
476
|
+
}
|
|
477
|
+
_flush() {
|
|
478
|
+
if (this[kCorked] <= 0) for (let [e, t] of this.entries.entries()) t.written || (t.written = !0, this.onWrite != null && this.onWrite(e, t), t.callback != null && t.callback.call(void 0));
|
|
479
|
+
}
|
|
480
|
+
get writableLength() {
|
|
481
|
+
return this.entries.reduce((e, t) => e + (t.written && t.length ? t.length : 0), 0);
|
|
482
|
+
}
|
|
483
|
+
get writableHighWaterMark() {
|
|
484
|
+
return this[kHighWaterMark];
|
|
485
|
+
}
|
|
486
|
+
get writableCorked() {
|
|
487
|
+
return this[kCorked];
|
|
488
|
+
}
|
|
489
|
+
}, FetchOutgoingMessage = class extends Writable {
|
|
490
|
+
req;
|
|
491
|
+
outputData;
|
|
492
|
+
outputSize;
|
|
493
|
+
writtenHeaderBytes = 0;
|
|
494
|
+
_last;
|
|
495
|
+
chunkedEncoding;
|
|
496
|
+
shouldKeepAlive;
|
|
497
|
+
maxRequestsOnConnectionReached;
|
|
498
|
+
_defaultKeepAlive;
|
|
499
|
+
useChunkedEncodingByDefault;
|
|
500
|
+
sendDate;
|
|
501
|
+
_removedConnection;
|
|
502
|
+
_removedContLen;
|
|
503
|
+
_removedTE;
|
|
504
|
+
strictContentLength;
|
|
505
|
+
[kBytesWritten];
|
|
506
|
+
_contentLength;
|
|
507
|
+
_hasBody;
|
|
508
|
+
_trailer;
|
|
509
|
+
[kNeedDrain];
|
|
510
|
+
finished;
|
|
511
|
+
_headerSent;
|
|
512
|
+
[kCorked];
|
|
513
|
+
[kChunkedBuffer];
|
|
514
|
+
[kChunkedLength];
|
|
515
|
+
_closed;
|
|
516
|
+
_header;
|
|
517
|
+
[kOutHeaders];
|
|
518
|
+
_keepAliveTimeout;
|
|
519
|
+
_maxRequestsPerSocket;
|
|
520
|
+
_onPendingData;
|
|
521
|
+
[kUniqueHeaders];
|
|
522
|
+
[kErrored];
|
|
523
|
+
[kHighWaterMark];
|
|
524
|
+
[kRejectNonStandardBodyWrites];
|
|
525
|
+
_writtenDataBuffer = new WrittenDataBuffer({ onWrite: this._onDataWritten.bind(this) });
|
|
526
|
+
constructor(e, t) {
|
|
527
|
+
super(), this.req = e, this.outputData = [], this.outputSize = 0, this.destroyed = !1, this._last = !1, this.chunkedEncoding = !1, this.shouldKeepAlive = !0, this.maxRequestsOnConnectionReached = !1, this._defaultKeepAlive = !0, this.useChunkedEncodingByDefault = !0, this.sendDate = !1, this._removedConnection = !1, this._removedContLen = !1, this._removedTE = !1, this.strictContentLength = !1, this[kBytesWritten] = 0, this._contentLength = null, this._hasBody = !0, this._trailer = "", this[kNeedDrain] = !1, this.finished = !1, this._headerSent = !1, this[kCorked] = 0, this[kChunkedBuffer] = [], this[kChunkedLength] = 0, this._closed = !1, this._header = null, this[kOutHeaders] = null, this._keepAliveTimeout = 0, this._onPendingData = nop, this[kErrored] = null, this[kHighWaterMark] = t?.highWaterMark ?? getDefaultHighWaterMark(), this[kRejectNonStandardBodyWrites] = t?.rejectNonStandardBodyWrites ?? !1, this[kUniqueHeaders] = null;
|
|
528
|
+
}
|
|
529
|
+
_renderHeaders() {
|
|
530
|
+
if (this._header) throw new ERR_HTTP_HEADERS_SENT("render");
|
|
531
|
+
let e = this[kOutHeaders], t = {};
|
|
532
|
+
if (e !== null) {
|
|
533
|
+
let n = Object.keys(e);
|
|
534
|
+
for (let r = 0, i = n.length; r < i; r++) {
|
|
535
|
+
let i = n[r];
|
|
536
|
+
t[e[i][0]] = e[i][1];
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return t;
|
|
540
|
+
}
|
|
541
|
+
cork() {
|
|
542
|
+
this[kCorked]++, this._writtenDataBuffer != null && this._writtenDataBuffer.cork();
|
|
543
|
+
}
|
|
544
|
+
uncork() {
|
|
545
|
+
if (this[kCorked]--, this._writtenDataBuffer != null && this._writtenDataBuffer.uncork(), this[kCorked] || this[kChunkedBuffer].length === 0) return;
|
|
546
|
+
let e = this[kChunkedBuffer];
|
|
547
|
+
for (let { data: t, encoding: n, callback: r } of e) this._send(t ?? "", n, r);
|
|
548
|
+
this[kChunkedBuffer].length = 0, this[kChunkedLength] = 0;
|
|
549
|
+
}
|
|
550
|
+
setTimeout(e, t) {
|
|
551
|
+
return this;
|
|
552
|
+
}
|
|
553
|
+
destroy(e) {
|
|
554
|
+
return this.destroyed ? this : (this.destroyed = !0, this[kErrored] = e, this);
|
|
555
|
+
}
|
|
556
|
+
_send(e, t, n, r) {
|
|
557
|
+
if (!this._headerSent) {
|
|
558
|
+
let n = this._header;
|
|
559
|
+
typeof e == "string" && (t === "utf8" || t === "latin1" || !t) ? e = n + e : (this.outputData.unshift({
|
|
560
|
+
data: n,
|
|
561
|
+
encoding: "latin1",
|
|
562
|
+
callback: void 0
|
|
563
|
+
}), this.outputSize += n.length, this._onPendingData(n.length)), this._headerSent = !0, this.writtenHeaderBytes = n.length;
|
|
564
|
+
let [r, ...i] = this._header.split("\r\n"), a = /^HTTP\/1\.1 (?<statusCode>\d+) (?<statusMessage>.*)$/.exec(r);
|
|
565
|
+
if (a == null) throw Error("Unexpected! Status line was " + r);
|
|
566
|
+
let { statusCode: o, statusMessage: s } = a.groups ?? {}, c = parseInt(o, 10), l = [];
|
|
567
|
+
for (let e of i) if (e !== "") {
|
|
568
|
+
let t = e.indexOf(": "), n = e.slice(0, t), r = e.slice(t + 2);
|
|
569
|
+
l.push([n, r]);
|
|
570
|
+
}
|
|
571
|
+
let u = {
|
|
572
|
+
statusCode: c,
|
|
573
|
+
statusMessage: s,
|
|
574
|
+
headers: l
|
|
575
|
+
};
|
|
576
|
+
this.emit("_headersSent", u);
|
|
577
|
+
}
|
|
578
|
+
return this._writeRaw(e, t, n, r);
|
|
579
|
+
}
|
|
580
|
+
_writeRaw(e, t, n, r) {
|
|
581
|
+
return typeof t == "function" && (n = t, t = null), this._writtenDataBuffer == null ? (this.outputData.push({
|
|
582
|
+
data: e,
|
|
583
|
+
encoding: t,
|
|
584
|
+
callback: n
|
|
585
|
+
}), this.outputSize += e.length, this._onPendingData(e.length), this.outputSize < this[kHighWaterMark]) : (this.outputData.length && this._flushOutput(this._writtenDataBuffer), this._writtenDataBuffer.write(e, t, n));
|
|
586
|
+
}
|
|
587
|
+
_onDataWritten(e, t) {
|
|
588
|
+
let n = {
|
|
589
|
+
index: e,
|
|
590
|
+
entry: t
|
|
591
|
+
};
|
|
592
|
+
this.emit("_dataWritten", n);
|
|
593
|
+
}
|
|
594
|
+
_storeHeader(e, t) {
|
|
595
|
+
let n = {
|
|
596
|
+
connection: !1,
|
|
597
|
+
contLen: !1,
|
|
598
|
+
te: !1,
|
|
599
|
+
date: !1,
|
|
600
|
+
expect: !1,
|
|
601
|
+
trailer: !1,
|
|
602
|
+
header: e
|
|
603
|
+
};
|
|
604
|
+
if (t) if (t === this[kOutHeaders]) for (let e in t) {
|
|
605
|
+
let r = t[e];
|
|
606
|
+
processHeader(this, n, r[0], r[1], !1);
|
|
607
|
+
}
|
|
608
|
+
else if (Array.isArray(t)) if (t.length && Array.isArray(t[0])) for (let e = 0; e < t.length; e++) {
|
|
609
|
+
let r = t[e];
|
|
610
|
+
processHeader(this, n, r[0], r[1], !0);
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
if (t.length % 2 != 0) throw new ERR_INVALID_ARG_VALUE("headers", t);
|
|
614
|
+
for (let e = 0; e < t.length; e += 2) processHeader(this, n, t[e], t[e + 1], !0);
|
|
615
|
+
}
|
|
616
|
+
else for (let e in t) t.hasOwnProperty(e) && processHeader(this, n, e, t[e], !0);
|
|
617
|
+
let { header: r } = n;
|
|
618
|
+
if (this.sendDate && !n.date && (r += "Date: " + utcDate() + "\r\n"), this.chunkedEncoding && (this.statusCode === 204 || this.statusCode === 304) && (this.statusCode + "", this.chunkedEncoding = !1, this.shouldKeepAlive = !1), this._removedConnection) this._last = !this.shouldKeepAlive;
|
|
619
|
+
else if (!n.connection) {
|
|
620
|
+
let e = this.shouldKeepAlive && (n.contLen || this.useChunkedEncodingByDefault);
|
|
621
|
+
if (e && this.maxRequestsOnConnectionReached) r += "Connection: close\r\n";
|
|
622
|
+
else if (e) {
|
|
623
|
+
if (r += "Connection: keep-alive\r\n", this._keepAliveTimeout && this._defaultKeepAlive) {
|
|
624
|
+
let e = Math.floor(this._keepAliveTimeout / 1e3), t = "";
|
|
625
|
+
this._maxRequestsPerSocket && ~~this._maxRequestsPerSocket > 0 && (t = `, max=${this._maxRequestsPerSocket}`), r += `Keep-Alive: timeout=${e}${t}\r\n`;
|
|
626
|
+
}
|
|
627
|
+
} else this._last = !0, r += "Connection: close\r\n";
|
|
628
|
+
}
|
|
629
|
+
if (!n.contLen && !n.te && (this._hasBody ? this.useChunkedEncodingByDefault ? !n.trailer && !this._removedContLen && typeof this._contentLength == "number" ? r += "Content-Length: " + this._contentLength + "\r\n" : this._removedTE ? this._last = !0 : (r += "Transfer-Encoding: chunked\r\n", this.chunkedEncoding = !0) : this._last = !0 : this.chunkedEncoding = !1), this.chunkedEncoding !== !0 && n.trailer) throw new ERR_HTTP_TRAILER_INVALID();
|
|
630
|
+
this._header = r + "\r\n", this._headerSent = !1, n.expect && this._send("");
|
|
631
|
+
}
|
|
632
|
+
get _headers() {
|
|
633
|
+
return console.warn("DEP0066: OutgoingMessage.prototype._headers is deprecated"), this.getHeaders();
|
|
634
|
+
}
|
|
635
|
+
set _headers(e) {
|
|
636
|
+
if (console.warn("DEP0066: OutgoingMessage.prototype._headers is deprecated"), e == null) this[kOutHeaders] = null;
|
|
637
|
+
else if (typeof e == "object") {
|
|
638
|
+
let t = this[kOutHeaders] = Object.create(null), n = Object.keys(e);
|
|
639
|
+
for (let r = 0; r < n.length; ++r) {
|
|
640
|
+
let i = n[r];
|
|
641
|
+
t[i.toLowerCase()] = [i, e[i]];
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
get connection() {
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
set connection(e) {
|
|
649
|
+
console.error("No support for OutgoingMessage.connection");
|
|
650
|
+
}
|
|
651
|
+
get socket() {
|
|
652
|
+
return null;
|
|
653
|
+
}
|
|
654
|
+
set socket(e) {
|
|
655
|
+
console.error("No support for OutgoingMessage.socket");
|
|
656
|
+
}
|
|
657
|
+
get _headerNames() {
|
|
658
|
+
console.warn("DEP0066: OutgoingMessage.prototype._headerNames is deprecated");
|
|
659
|
+
let e = this[kOutHeaders];
|
|
660
|
+
if (e !== null) {
|
|
661
|
+
let t = Object.create(null), n = Object.keys(e);
|
|
662
|
+
for (let r = 0; r < n.length; ++r) {
|
|
663
|
+
let i = n[r];
|
|
664
|
+
t[i] = e[i][0];
|
|
665
|
+
}
|
|
666
|
+
return t;
|
|
667
|
+
}
|
|
668
|
+
return null;
|
|
669
|
+
}
|
|
670
|
+
set _headerNames(e) {
|
|
671
|
+
if (console.warn("DEP0066: OutgoingMessage.prototype._headerNames is deprecated"), typeof e == "object" && e) {
|
|
672
|
+
let t = this[kOutHeaders];
|
|
673
|
+
if (!t) return;
|
|
674
|
+
let n = Object.keys(e);
|
|
675
|
+
for (let r = 0; r < n.length; ++r) {
|
|
676
|
+
let i = t[n[r]];
|
|
677
|
+
i && (i[0] = e[n[r]]);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
setHeader(e, t) {
|
|
682
|
+
if (this._header) throw new ERR_HTTP_HEADERS_SENT("set");
|
|
683
|
+
validateHeaderName(e), validateHeaderValue(e, t);
|
|
684
|
+
let n = this[kOutHeaders];
|
|
685
|
+
return n === null && (this[kOutHeaders] = n = { __proto__: null }), n[e.toLowerCase()] = [e, t], this;
|
|
686
|
+
}
|
|
687
|
+
setHeaders(e) {
|
|
688
|
+
if (this._header) throw new ERR_HTTP_HEADERS_SENT("set");
|
|
689
|
+
if (!e || Array.isArray(e) || typeof e.keys != "function" || typeof e.get != "function") throw new ERR_INVALID_ARG_TYPE("headers", ["Headers", "Map"], e);
|
|
690
|
+
let t = [];
|
|
691
|
+
for (let { 0: n, 1: r } of e) {
|
|
692
|
+
if (n === "set-cookie") {
|
|
693
|
+
Array.isArray(r) ? t.push(...r) : t.push(r);
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
this.setHeader(n, r);
|
|
697
|
+
}
|
|
698
|
+
return t.length && this.setHeader("set-cookie", t), this;
|
|
699
|
+
}
|
|
700
|
+
appendHeader(e, t) {
|
|
701
|
+
if (this._header) throw new ERR_HTTP_HEADERS_SENT("append");
|
|
702
|
+
validateHeaderName(e), validateHeaderValue(e, t);
|
|
703
|
+
let n = e.toLowerCase(), r = this[kOutHeaders];
|
|
704
|
+
if (r === null || !r[n]) return this.setHeader(e, t);
|
|
705
|
+
Array.isArray(r[n][1]) || (r[n][1] = [r[n][1]]);
|
|
706
|
+
let i = r[n][1];
|
|
707
|
+
if (Array.isArray(t)) for (let e = 0, n = t.length; e < n; e++) i.push(t[e]);
|
|
708
|
+
else i.push(t);
|
|
709
|
+
return this;
|
|
710
|
+
}
|
|
711
|
+
getHeader(e) {
|
|
712
|
+
validateString(e, "name");
|
|
713
|
+
let t = this[kOutHeaders];
|
|
714
|
+
if (t !== null) return t[e.toLowerCase()]?.[1];
|
|
715
|
+
}
|
|
716
|
+
getHeaderNames() {
|
|
717
|
+
return this[kOutHeaders] === null ? [] : Object.keys(this[kOutHeaders]);
|
|
718
|
+
}
|
|
719
|
+
getRawHeaderNames() {
|
|
720
|
+
let e = this[kOutHeaders];
|
|
721
|
+
if (e === null) return [];
|
|
722
|
+
let t = Object.values(e), n = Array(t.length);
|
|
723
|
+
for (let e = 0, r = t.length; e < r; e++) n[e] = t[e][0];
|
|
724
|
+
return n;
|
|
725
|
+
}
|
|
726
|
+
getHeaders() {
|
|
727
|
+
let e = this[kOutHeaders], t = { __proto__: null };
|
|
728
|
+
if (e) {
|
|
729
|
+
let n = Object.keys(e);
|
|
730
|
+
for (let r = 0; r < n.length; ++r) {
|
|
731
|
+
let i = n[r];
|
|
732
|
+
t[i] = e[i][1];
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return t;
|
|
736
|
+
}
|
|
737
|
+
hasHeader(e) {
|
|
738
|
+
return validateString(e, "name"), this[kOutHeaders] !== null && !!this[kOutHeaders][e.toLowerCase()];
|
|
739
|
+
}
|
|
740
|
+
removeHeader(e) {
|
|
741
|
+
if (validateString(e, "name"), this._header) throw new ERR_HTTP_HEADERS_SENT("remove");
|
|
742
|
+
let t = e.toLowerCase();
|
|
743
|
+
switch (t) {
|
|
744
|
+
case "connection":
|
|
745
|
+
this._removedConnection = !0;
|
|
746
|
+
break;
|
|
747
|
+
case "content-length":
|
|
748
|
+
this._removedContLen = !0;
|
|
749
|
+
break;
|
|
750
|
+
case "transfer-encoding":
|
|
751
|
+
this._removedTE = !0;
|
|
752
|
+
break;
|
|
753
|
+
case "date":
|
|
754
|
+
this.sendDate = !1;
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
this[kOutHeaders] !== null && delete this[kOutHeaders][t];
|
|
758
|
+
}
|
|
759
|
+
_implicitHeader() {
|
|
760
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("_implicitHeader()");
|
|
761
|
+
}
|
|
762
|
+
get headersSent() {
|
|
763
|
+
return !!this._header;
|
|
764
|
+
}
|
|
765
|
+
write(e, t, n) {
|
|
766
|
+
typeof t == "function" && (n = t, t = null);
|
|
767
|
+
let r = write_(this, e, t, n, !1);
|
|
768
|
+
return r || (this[kNeedDrain] = !0), r;
|
|
769
|
+
}
|
|
770
|
+
addTrailers(e) {
|
|
771
|
+
this._trailer = "";
|
|
772
|
+
let t = Array.isArray(e), n = t ? [...e.keys()] : Object.keys(e);
|
|
773
|
+
for (let r = 0, i = n.length; r < i; r++) {
|
|
774
|
+
let i, a;
|
|
775
|
+
if (t) {
|
|
776
|
+
let t = e, o = n[r];
|
|
777
|
+
i = t[o][0], a = t[o][1];
|
|
778
|
+
} else {
|
|
779
|
+
let t = e, o = n[r];
|
|
780
|
+
i = o, a = t[o];
|
|
781
|
+
}
|
|
782
|
+
if (validateHeaderName(i, "Trailer name"), Array.isArray(a) && a.length > 1 && (!this[kUniqueHeaders] || !this[kUniqueHeaders].has(i.toLowerCase()))) for (let e = 0, t = a.length; e < t; e++) {
|
|
783
|
+
if (checkInvalidHeaderChar$1(a[e])) throw `${i}${e}`, new ERR_INVALID_CHAR("trailer content", i);
|
|
784
|
+
this._trailer += i + ": " + a[e] + "\r\n";
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
if (Array.isArray(a) && (a = a.join("; ")), checkInvalidHeaderChar$1(String(a))) throw `${i}`, new ERR_INVALID_CHAR("trailer content", i);
|
|
788
|
+
this._trailer += i + ": " + a + "\r\n";
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
end(e, t, n) {
|
|
793
|
+
if (typeof e == "function" ? (n = e, e = null, t = null) : typeof t == "function" && (n = t, t = null), e) {
|
|
794
|
+
if (this.finished) return onError(this, new ERR_STREAM_WRITE_AFTER_END(), typeof n == "function" ? n : nop), this;
|
|
795
|
+
this._writtenDataBuffer != null && this._writtenDataBuffer.cork(), write_(this, e, t, null, !0);
|
|
796
|
+
} else if (this.finished) return typeof n == "function" && (this.writableFinished ? n(new ERR_STREAM_ALREADY_FINISHED("end")) : this.on("finish", n)), this;
|
|
797
|
+
else this._header || (this._writtenDataBuffer != null && this._writtenDataBuffer.cork(), this._contentLength = 0, this._implicitHeader());
|
|
798
|
+
if (typeof n == "function" && this.once("finish", n), strictContentLength(this) && this[kBytesWritten] !== this._contentLength) throw new ERR_HTTP_CONTENT_LENGTH_MISMATCH(this[kBytesWritten], this._contentLength);
|
|
799
|
+
let r = onFinish.bind(void 0, this);
|
|
800
|
+
return this._hasBody && this.chunkedEncoding || !this._headerSent || this.writableLength || e ? this._send("", "latin1", r) : setTimeout(r, 0), this._writtenDataBuffer != null && this._writtenDataBuffer.uncork(), this[kCorked] = 1, this.uncork(), this.finished = !0, this.outputData.length === 0 && this._writtenDataBuffer != null && this._finish(), this;
|
|
801
|
+
}
|
|
802
|
+
_finish() {
|
|
803
|
+
this.emit("prefinish");
|
|
804
|
+
}
|
|
805
|
+
_flush() {
|
|
806
|
+
if (this._writtenDataBuffer != null) {
|
|
807
|
+
let e = this._flushOutput(this._writtenDataBuffer);
|
|
808
|
+
this.finished ? this._finish() : e && this[kNeedDrain] && (this[kNeedDrain] = !1, this.emit("drain"));
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
_flushOutput(e) {
|
|
812
|
+
for (; this[kCorked];) this[kCorked]--, e.cork();
|
|
813
|
+
let t = this.outputData.length;
|
|
814
|
+
if (t <= 0) return;
|
|
815
|
+
let n = this.outputData;
|
|
816
|
+
e.cork();
|
|
817
|
+
let r;
|
|
818
|
+
for (let i = 0; i < t; i++) {
|
|
819
|
+
let { data: t, encoding: a, callback: o } = n[i];
|
|
820
|
+
n[i].data = null, r = e.write(t ?? "", a, o);
|
|
821
|
+
}
|
|
822
|
+
return e.uncork(), this.outputData = [], this._onPendingData(-this.outputSize), this.outputSize = 0, r;
|
|
823
|
+
}
|
|
824
|
+
flushHeaders() {
|
|
825
|
+
this._header || this._implicitHeader(), this._send("");
|
|
826
|
+
}
|
|
827
|
+
pipe(e) {
|
|
828
|
+
return this.emit("error", new ERR_STREAM_CANNOT_PIPE()), e;
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
function processHeader(e, t, n, r, i) {
|
|
832
|
+
if (i && validateHeaderName(n), isContentDispositionField(n) && e._contentLength) if (Array.isArray(r)) for (let e = 0; e < r.length; e++) r[e] = String(Buffer.from(String(r[e]), "latin1"));
|
|
833
|
+
else r = String(Buffer.from(String(r), "latin1"));
|
|
834
|
+
if (Array.isArray(r)) {
|
|
835
|
+
if ((r.length < 2 || !isCookieField(n)) && (!e[kUniqueHeaders] || !e[kUniqueHeaders].has(n.toLowerCase()))) {
|
|
836
|
+
for (let a = 0; a < r.length; a++) storeHeader(e, t, n, r[a], i);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
r = r.join("; ");
|
|
840
|
+
}
|
|
841
|
+
storeHeader(e, t, n, String(r), i);
|
|
842
|
+
}
|
|
843
|
+
function storeHeader(e, t, n, r, i) {
|
|
844
|
+
i && validateHeaderValue(n, r), t.header += n + ": " + r + "\r\n", matchHeader(e, t, n, r);
|
|
845
|
+
}
|
|
846
|
+
function validateHeaderName(e, t) {
|
|
847
|
+
if (typeof e != "string" || !e || !checkIsHttpToken(e)) throw new ERR_INVALID_HTTP_TOKEN(t || "Header name", e);
|
|
848
|
+
}
|
|
849
|
+
function validateHeaderValue(e, t) {
|
|
850
|
+
if (t === void 0) throw new ERR_HTTP_INVALID_HEADER_VALUE(String(t), e);
|
|
851
|
+
if (checkInvalidHeaderChar$1(String(t))) throw `${e}`, new ERR_INVALID_CHAR("header content", e);
|
|
852
|
+
}
|
|
853
|
+
function matchHeader(e, t, n, r) {
|
|
854
|
+
if (!(n.length < 4 || n.length > 17)) switch (n = n.toLowerCase(), n) {
|
|
855
|
+
case "connection":
|
|
856
|
+
t.connection = !0, e._removedConnection = !1, RE_CONN_CLOSE.exec(r) === null ? e.shouldKeepAlive = !0 : e._last = !0;
|
|
857
|
+
break;
|
|
858
|
+
case "transfer-encoding":
|
|
859
|
+
t.te = !0, e._removedTE = !1, chunkExpression.exec(r) !== null && (e.chunkedEncoding = !0);
|
|
860
|
+
break;
|
|
861
|
+
case "content-length":
|
|
862
|
+
t.contLen = !0, e._contentLength = +r, e._removedContLen = !1;
|
|
863
|
+
break;
|
|
864
|
+
case "date":
|
|
865
|
+
case "expect":
|
|
866
|
+
case "trailer":
|
|
867
|
+
t[n] = !0;
|
|
868
|
+
break;
|
|
869
|
+
case "keep-alive":
|
|
870
|
+
e._defaultKeepAlive = !1;
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
function onError(e, t, n) {
|
|
875
|
+
e.destroyed || setTimeout(emitErrorNt, 0, e, t, n);
|
|
876
|
+
}
|
|
877
|
+
function emitErrorNt(e, t, n) {
|
|
878
|
+
n(t), typeof e.emit == "function" && !e.destroyed && e.emit("error", t);
|
|
879
|
+
}
|
|
880
|
+
function strictContentLength(e) {
|
|
881
|
+
return e.strictContentLength && e._contentLength != null && e._hasBody && !e._removedContLen && !e.chunkedEncoding && !e.hasHeader("transfer-encoding");
|
|
882
|
+
}
|
|
883
|
+
function write_(e, t, n, r, i) {
|
|
884
|
+
if (typeof r != "function" && (r = nop), t === null) throw new ERR_STREAM_NULL_VALUES();
|
|
885
|
+
if (typeof t != "string" && !isUint8Array(t)) throw new ERR_INVALID_ARG_TYPE("chunk", [
|
|
886
|
+
"string",
|
|
887
|
+
"Buffer",
|
|
888
|
+
"Uint8Array"
|
|
889
|
+
], t);
|
|
890
|
+
let a;
|
|
891
|
+
if (e.finished ? a = new ERR_STREAM_WRITE_AFTER_END() : e.destroyed && (a = new ERR_STREAM_DESTROYED("write")), a) return e.destroyed ? setTimeout(r, 0, a) : onError(e, a, r), !1;
|
|
892
|
+
let o;
|
|
893
|
+
if (e.strictContentLength) {
|
|
894
|
+
if (o ??= typeof t == "string" ? Buffer.byteLength(t, n ?? void 0) : t.byteLength, strictContentLength(e) && (i ? e[kBytesWritten] + o !== e._contentLength : e[kBytesWritten] + o > (e._contentLength ?? 0))) throw new ERR_HTTP_CONTENT_LENGTH_MISMATCH(o + e[kBytesWritten], e._contentLength);
|
|
895
|
+
e[kBytesWritten] += o;
|
|
896
|
+
}
|
|
897
|
+
if (e._header || (i && (o ??= typeof t == "string" ? Buffer.byteLength(t, n ?? void 0) : t.byteLength, e._contentLength = o), e._implicitHeader()), !e._hasBody) {
|
|
898
|
+
if (e[kRejectNonStandardBodyWrites]) throw new ERR_HTTP_BODY_NOT_ALLOWED();
|
|
899
|
+
return setTimeout(r, 0), !0;
|
|
900
|
+
}
|
|
901
|
+
!i && e._writtenDataBuffer != null && !e._writtenDataBuffer.writableCorked && (e._writtenDataBuffer.cork(), setTimeout(connectionCorkNT, 0, e._writtenDataBuffer));
|
|
902
|
+
let s;
|
|
903
|
+
return e.chunkedEncoding && t.length !== 0 ? (o ??= typeof t == "string" ? Buffer.byteLength(t, n ?? void 0) : t.byteLength, e[kCorked] && e._headerSent ? (e[kChunkedBuffer].push({
|
|
904
|
+
data: t,
|
|
905
|
+
encoding: n,
|
|
906
|
+
callback: r
|
|
907
|
+
}), e[kChunkedLength] += o, s = e[kChunkedLength] < e[kHighWaterMark]) : s = e._send(t, n, r, o)) : s = e._send(t, n, r, o), "" + s, s;
|
|
908
|
+
}
|
|
909
|
+
function connectionCorkNT(e) {
|
|
910
|
+
e.uncork();
|
|
911
|
+
}
|
|
912
|
+
function onFinish(e) {
|
|
913
|
+
e.emit("finish");
|
|
914
|
+
}
|
|
915
|
+
Object.defineProperties(FetchOutgoingMessage.prototype, {
|
|
916
|
+
errored: { get() {
|
|
917
|
+
return this[kErrored];
|
|
918
|
+
} },
|
|
919
|
+
closed: { get() {
|
|
920
|
+
return this._closed;
|
|
921
|
+
} },
|
|
922
|
+
writableFinished: { get() {
|
|
923
|
+
return this.finished && this.outputSize === 0 && (this._writtenDataBuffer == null || this._writtenDataBuffer.writableLength === 0);
|
|
924
|
+
} },
|
|
925
|
+
writableObjectMode: { get() {
|
|
926
|
+
return !1;
|
|
927
|
+
} },
|
|
928
|
+
writableLength: { get() {
|
|
929
|
+
return this.outputSize + this[kChunkedLength] + (this._writtenDataBuffer == null ? 0 : this._writtenDataBuffer.writableLength);
|
|
930
|
+
} },
|
|
931
|
+
writableHighWaterMark: { get() {
|
|
932
|
+
return this._writtenDataBuffer == null ? this[kHighWaterMark] : this._writtenDataBuffer.writableHighWaterMark;
|
|
933
|
+
} },
|
|
934
|
+
writableCorked: { get() {
|
|
935
|
+
return this[kCorked];
|
|
936
|
+
} },
|
|
937
|
+
writableEnded: { get() {
|
|
938
|
+
return this.finished;
|
|
939
|
+
} },
|
|
940
|
+
writableNeedDrain: { get() {
|
|
941
|
+
return !this.destroyed && !this.finished && this[kNeedDrain];
|
|
942
|
+
} }
|
|
943
|
+
});
|
|
944
|
+
var headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
|
|
945
|
+
function checkInvalidHeaderChar(e) {
|
|
946
|
+
return headerCharRegex.test(e);
|
|
947
|
+
}
|
|
948
|
+
const STATUS_CODES = {
|
|
949
|
+
100: "Continue",
|
|
950
|
+
101: "Switching Protocols",
|
|
951
|
+
102: "Processing",
|
|
952
|
+
103: "Early Hints",
|
|
953
|
+
200: "OK",
|
|
954
|
+
201: "Created",
|
|
955
|
+
202: "Accepted",
|
|
956
|
+
203: "Non-Authoritative Information",
|
|
957
|
+
204: "No Content",
|
|
958
|
+
205: "Reset Content",
|
|
959
|
+
206: "Partial Content",
|
|
960
|
+
207: "Multi-Status",
|
|
961
|
+
208: "Already Reported",
|
|
962
|
+
226: "IM Used",
|
|
963
|
+
300: "Multiple Choices",
|
|
964
|
+
301: "Moved Permanently",
|
|
965
|
+
302: "Found",
|
|
966
|
+
303: "See Other",
|
|
967
|
+
304: "Not Modified",
|
|
968
|
+
305: "Use Proxy",
|
|
969
|
+
307: "Temporary Redirect",
|
|
970
|
+
308: "Permanent Redirect",
|
|
971
|
+
400: "Bad Request",
|
|
972
|
+
401: "Unauthorized",
|
|
973
|
+
402: "Payment Required",
|
|
974
|
+
403: "Forbidden",
|
|
975
|
+
404: "Not Found",
|
|
976
|
+
405: "Method Not Allowed",
|
|
977
|
+
406: "Not Acceptable",
|
|
978
|
+
407: "Proxy Authentication Required",
|
|
979
|
+
408: "Request Timeout",
|
|
980
|
+
409: "Conflict",
|
|
981
|
+
410: "Gone",
|
|
982
|
+
411: "Length Required",
|
|
983
|
+
412: "Precondition Failed",
|
|
984
|
+
413: "Payload Too Large",
|
|
985
|
+
414: "URI Too Long",
|
|
986
|
+
415: "Unsupported Media Type",
|
|
987
|
+
416: "Range Not Satisfiable",
|
|
988
|
+
417: "Expectation Failed",
|
|
989
|
+
418: "I'm a Teapot",
|
|
990
|
+
421: "Misdirected Request",
|
|
991
|
+
422: "Unprocessable Entity",
|
|
992
|
+
423: "Locked",
|
|
993
|
+
424: "Failed Dependency",
|
|
994
|
+
425: "Too Early",
|
|
995
|
+
426: "Upgrade Required",
|
|
996
|
+
428: "Precondition Required",
|
|
997
|
+
429: "Too Many Requests",
|
|
998
|
+
431: "Request Header Fields Too Large",
|
|
999
|
+
451: "Unavailable For Legal Reasons",
|
|
1000
|
+
500: "Internal Server Error",
|
|
1001
|
+
501: "Not Implemented",
|
|
1002
|
+
502: "Bad Gateway",
|
|
1003
|
+
503: "Service Unavailable",
|
|
1004
|
+
504: "Gateway Timeout",
|
|
1005
|
+
505: "HTTP Version Not Supported",
|
|
1006
|
+
506: "Variant Also Negotiates",
|
|
1007
|
+
507: "Insufficient Storage",
|
|
1008
|
+
508: "Loop Detected",
|
|
1009
|
+
509: "Bandwidth Limit Exceeded",
|
|
1010
|
+
510: "Not Extended",
|
|
1011
|
+
511: "Network Authentication Required"
|
|
1012
|
+
};
|
|
1013
|
+
var FetchServerResponse = class e extends FetchOutgoingMessage {
|
|
1014
|
+
static encoder = new TextEncoder();
|
|
1015
|
+
statusCode = 200;
|
|
1016
|
+
statusMessage;
|
|
1017
|
+
_sent100;
|
|
1018
|
+
_expect_continue;
|
|
1019
|
+
[kOutHeaders] = null;
|
|
1020
|
+
constructor(e, t) {
|
|
1021
|
+
super(e, t), e.method === "HEAD" && (this._hasBody = !1), this.sendDate = !0, this._sent100 = !1, this._expect_continue = !1, (e.httpVersionMajor < 1 || e.httpVersionMinor < 1) && (this.useChunkedEncodingByDefault = chunkExpression.exec(String(e.headers.te)) !== null, this.shouldKeepAlive = !1), this.fetchResponse = new Promise((e) => {
|
|
1022
|
+
let t = !1;
|
|
1023
|
+
this.on("finish", () => {
|
|
1024
|
+
t = !0;
|
|
1025
|
+
});
|
|
1026
|
+
let n = [], r = (e) => {
|
|
1027
|
+
t || (n[e.index] = this.dataFromDataWrittenEvent(e));
|
|
1028
|
+
};
|
|
1029
|
+
this.on("_dataWritten", r), this.on("_headersSent", (i) => {
|
|
1030
|
+
this.off("_dataWritten", r);
|
|
1031
|
+
let { statusCode: a, statusMessage: o, headers: s } = i;
|
|
1032
|
+
e(this._toFetchResponse(a, o, s, n, t));
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
dataFromDataWrittenEvent(t) {
|
|
1037
|
+
let { index: n, entry: r } = t, { data: i, encoding: a } = r;
|
|
1038
|
+
if (n === 0) {
|
|
1039
|
+
if (typeof i != "string") throw console.error("First chunk should be string, not sure what happened."), new ERR_INVALID_ARG_TYPE("packet.data", [
|
|
1040
|
+
"string",
|
|
1041
|
+
"Buffer",
|
|
1042
|
+
"Uint8Array"
|
|
1043
|
+
], i);
|
|
1044
|
+
i = i.slice(this.writtenHeaderBytes);
|
|
1045
|
+
}
|
|
1046
|
+
return typeof i == "string" && (i = a === void 0 || a === "utf8" || a === "utf-8" ? e.encoder.encode(i) : Buffer.from(i, a ?? void 0)), i ?? Buffer.from([]);
|
|
1047
|
+
}
|
|
1048
|
+
_finish() {
|
|
1049
|
+
super._finish();
|
|
1050
|
+
}
|
|
1051
|
+
assignSocket(e) {
|
|
1052
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("assignSocket");
|
|
1053
|
+
}
|
|
1054
|
+
detachSocket(e) {
|
|
1055
|
+
throw new ERR_METHOD_NOT_IMPLEMENTED("detachSocket");
|
|
1056
|
+
}
|
|
1057
|
+
writeContinue(e) {
|
|
1058
|
+
this._writeRaw("HTTP/1.1 100 Continue\r\n\r\n", "ascii", e), this._sent100 = !0;
|
|
1059
|
+
}
|
|
1060
|
+
writeProcessing(e) {
|
|
1061
|
+
this._writeRaw("HTTP/1.1 102 Processing\r\n\r\n", "ascii", e);
|
|
1062
|
+
}
|
|
1063
|
+
writeEarlyHints(e, t) {
|
|
1064
|
+
let n = "HTTP/1.1 103 Early Hints\r\n";
|
|
1065
|
+
if (e.link === null || e.link === void 0) return;
|
|
1066
|
+
let r = validateLinkHeaderValue(e.link);
|
|
1067
|
+
if (r.length !== 0) {
|
|
1068
|
+
n += "Link: " + r + "\r\n";
|
|
1069
|
+
for (let t of Object.keys(e)) t !== "link" && (n += t + ": " + e[t] + "\r\n");
|
|
1070
|
+
n += "\r\n", this._writeRaw(n, "ascii", t);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
_implicitHeader() {
|
|
1074
|
+
this.writeHead(this.statusCode);
|
|
1075
|
+
}
|
|
1076
|
+
writeHead(e, t, n) {
|
|
1077
|
+
if (this._header) throw new ERR_HTTP_HEADERS_SENT("write");
|
|
1078
|
+
let r = e;
|
|
1079
|
+
if (e |= 0, e < 100 || e > 999) throw new ERR_HTTP_INVALID_STATUS_CODE(r);
|
|
1080
|
+
typeof t == "string" ? this.statusMessage = t : (this.statusMessage ||= STATUS_CODES[e] || "unknown", n ??= t), this.statusCode = e;
|
|
1081
|
+
let i;
|
|
1082
|
+
if (this[kOutHeaders]) {
|
|
1083
|
+
let e;
|
|
1084
|
+
if (Array.isArray(n)) {
|
|
1085
|
+
if (n.length % 2 != 0) throw new ERR_INVALID_ARG_VALUE("headers", n);
|
|
1086
|
+
for (let t = 0; t < n.length; t += 2) e = n[t + 0], this.removeHeader(String(e));
|
|
1087
|
+
for (let t = 0; t < n.length; t += 2) e = n[t], e && this.appendHeader(String(e), n[t + 1]);
|
|
1088
|
+
} else if (n) {
|
|
1089
|
+
let t = Object.keys(n);
|
|
1090
|
+
for (let r = 0; r < t.length; r++) e = t[r], e && this.setHeader(e, n[e]);
|
|
1091
|
+
}
|
|
1092
|
+
i = this[kOutHeaders];
|
|
1093
|
+
} else i = n;
|
|
1094
|
+
if (checkInvalidHeaderChar(this.statusMessage)) throw new ERR_INVALID_CHAR("statusMessage");
|
|
1095
|
+
let a = `HTTP/1.1 ${e} ${this.statusMessage}\r\n`;
|
|
1096
|
+
(e === 204 || e === 304 || e >= 100 && e <= 199) && (this._hasBody = !1), this._expect_continue && !this._sent100 && (this.shouldKeepAlive = !1);
|
|
1097
|
+
let o = i;
|
|
1098
|
+
return this._storeHeader(a, o ?? null), this;
|
|
1099
|
+
}
|
|
1100
|
+
writeHeader = this.writeHead;
|
|
1101
|
+
fetchResponse;
|
|
1102
|
+
_toFetchResponse(e, t, n, r, i) {
|
|
1103
|
+
let a = new Headers();
|
|
1104
|
+
for (let [e, t] of n) a.append(e, t);
|
|
1105
|
+
let o = this, s = this._hasBody ? new ReadableStream({ start(e) {
|
|
1106
|
+
for (let t of r) e.enqueue(t);
|
|
1107
|
+
i ? e.close() : (o.on("finish", () => {
|
|
1108
|
+
i = !0, e.close();
|
|
1109
|
+
}), o.on("_dataWritten", (t) => {
|
|
1110
|
+
if (i) return;
|
|
1111
|
+
let n = o.dataFromDataWrittenEvent(t);
|
|
1112
|
+
e.enqueue(n);
|
|
1113
|
+
}));
|
|
1114
|
+
} }) : null;
|
|
1115
|
+
if (s != null && typeof FixedLengthStream < "u") {
|
|
1116
|
+
let e = parseInt(a.get("content-length") ?? "", 10);
|
|
1117
|
+
e >= 0 && (s = s.pipeThrough(new FixedLengthStream(e)));
|
|
1118
|
+
}
|
|
1119
|
+
return new Response(s, {
|
|
1120
|
+
status: e,
|
|
1121
|
+
statusText: t,
|
|
1122
|
+
headers: a
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
function toReqRes(e, t) {
|
|
1127
|
+
let { createIncomingMessage: n = () => new FetchIncomingMessage(), createServerResponse: r = (e) => new FetchServerResponse(e), ctx: i } = t ?? {}, a = n(i), o = r(a, i), s = new URL(e.url);
|
|
1128
|
+
a.httpVersionMajor = 1, a.httpVersionMinor = 1, a.httpVersion = "1.1", a.url = s.pathname + s.search, a.upgrade = !1;
|
|
1129
|
+
let c = [];
|
|
1130
|
+
for (let [t, n] of e.headers) c.push(t), c.push(n);
|
|
1131
|
+
return a._addHeaderLines(c, c.length), a.method = e.method, a._stream = e.body, {
|
|
1132
|
+
req: a,
|
|
1133
|
+
res: o
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
function toFetchResponse(e) {
|
|
1137
|
+
if (!(e instanceof FetchServerResponse)) throw Error("toFetchResponse must be called on a ServerResponse generated by toReqRes");
|
|
1138
|
+
return e.fetchResponse;
|
|
1139
|
+
}
|
|
1140
|
+
var serverStarted = !1, setApp = () => {};
|
|
1141
|
+
function bootstrapApp(e) {
|
|
1142
|
+
let o = e.port ?? 3e3;
|
|
1143
|
+
if (serverStarted) setApp(e.app);
|
|
1144
|
+
else {
|
|
1145
|
+
let s = e.app;
|
|
1146
|
+
setApp = (e) => {
|
|
1147
|
+
s = e;
|
|
1148
|
+
}, Bun.serve({
|
|
1149
|
+
async fetch(e) {
|
|
1150
|
+
let o = new URL(e.url), c = decodeURIComponent(o.pathname);
|
|
1151
|
+
if (process.env.NODE_ENV === "development") {
|
|
1152
|
+
let t = __POTOK_DEV__?.vite;
|
|
1153
|
+
if (t) {
|
|
1154
|
+
let n = await new Promise((n) => {
|
|
1155
|
+
let { req: r, res: i } = toReqRes(e), a = i.end.bind(i);
|
|
1156
|
+
i.end = (...e) => {
|
|
1157
|
+
let t = a(...e);
|
|
1158
|
+
return n(toFetchResponse(t)), t;
|
|
1159
|
+
}, t.middlewares(r, i, () => {
|
|
1160
|
+
n(void 0);
|
|
1161
|
+
});
|
|
1162
|
+
});
|
|
1163
|
+
if (n) return n;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
if (/\.[a-z0-9]+$/i.test(c)) {
|
|
1167
|
+
let e = Bun.file(path.join(process.cwd(), "dist", c));
|
|
1168
|
+
if (await e.exists()) return new Response(e, { headers: { "Content-Type": e.type } });
|
|
1169
|
+
}
|
|
1170
|
+
let l = await renderToString(fragment({ children: [s(e), PortalIn({
|
|
1171
|
+
name: "lib-scripts",
|
|
1172
|
+
children: __POTOK_DEV__ ? fragment({ children: [htmlElement({
|
|
1173
|
+
tag: "script",
|
|
1174
|
+
type: "module",
|
|
1175
|
+
src: "/@vite/client"
|
|
1176
|
+
}), htmlElement({
|
|
1177
|
+
tag: "script",
|
|
1178
|
+
type: "module",
|
|
1179
|
+
src: "/src/client.ts"
|
|
1180
|
+
})] }) : htmlElement({
|
|
1181
|
+
tag: "script",
|
|
1182
|
+
type: "module",
|
|
1183
|
+
src: `/${CLIENT_ENTRY_FILE_NAME}.js`
|
|
1184
|
+
})
|
|
1185
|
+
})] }));
|
|
1186
|
+
return new Response(l, { headers: { "Content-Type": "text/html; charset=utf-8" } });
|
|
1187
|
+
},
|
|
1188
|
+
port: o
|
|
1189
|
+
}), serverStarted = !0, console.log(`Приложение запущено на порте ${o}`);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
export { bootstrapApp };
|