elit 3.6.5 → 3.6.7
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/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +6 -0
- package/dist/build.cjs +421 -331
- package/dist/build.d.ts +1 -16
- package/dist/build.js +420 -330
- package/dist/build.mjs +420 -330
- package/dist/chokidar.cjs +219 -182
- package/dist/chokidar.d.ts +25 -10
- package/dist/chokidar.js +217 -182
- package/dist/chokidar.mjs +218 -183
- package/dist/cli.cjs +21608 -20241
- package/dist/cli.d.ts +19 -37
- package/dist/cli.mjs +21262 -19910
- package/dist/config.cjs +357 -350
- package/dist/config.d.ts +19 -240
- package/dist/config.js +520 -515
- package/dist/config.mjs +346 -341
- package/dist/contracts-BeW9k0yZ.d.ts +54 -0
- package/dist/contracts-D7KIS-TK.d.ts +36 -0
- package/dist/coverage.cjs +448 -485
- package/dist/coverage.d.ts +13 -59
- package/dist/coverage.js +447 -484
- package/dist/coverage.mjs +447 -484
- package/dist/database.cjs +819 -828
- package/dist/database.d.ts +8 -24
- package/dist/database.js +818 -829
- package/dist/database.mjs +818 -829
- package/dist/desktop-auto-render.cjs +1700 -1522
- package/dist/desktop-auto-render.d.ts +4 -9
- package/dist/desktop-auto-render.js +1695 -1517
- package/dist/desktop-auto-render.mjs +1696 -1518
- package/dist/desktop.cjs +3 -1
- package/dist/desktop.d.ts +4 -1
- package/dist/desktop.js +1 -1
- package/dist/desktop.mjs +1 -1
- package/dist/dev-build.cjs +830 -0
- package/dist/dev-build.d.ts +53 -0
- package/dist/dev-build.js +3318 -0
- package/dist/dev-build.mjs +797 -0
- package/dist/dom.cjs +717 -590
- package/dist/dom.d.ts +2 -15
- package/dist/dom.js +714 -587
- package/dist/dom.mjs +716 -589
- package/dist/el.cjs +62 -52
- package/dist/el.d.ts +5 -10
- package/dist/el.js +60 -52
- package/dist/el.mjs +60 -52
- package/dist/fs.cjs +72 -63
- package/dist/fs.d.ts +22 -19
- package/dist/fs.js +71 -62
- package/dist/fs.mjs +71 -62
- package/dist/hmr.cjs +40 -14
- package/dist/hmr.d.ts +11 -23
- package/dist/hmr.js +38 -14
- package/dist/hmr.mjs +38 -14
- package/dist/http.cjs +251 -99
- package/dist/http.d.ts +38 -104
- package/dist/http.js +249 -99
- package/dist/http.mjs +249 -99
- package/dist/https.cjs +524 -228
- package/dist/https.d.ts +44 -36
- package/dist/https.js +520 -226
- package/dist/https.mjs +522 -228
- package/dist/index.cjs +7502 -7690
- package/dist/index.d.ts +8 -3
- package/dist/index.js +7486 -7676
- package/dist/index.mjs +7497 -7686
- package/dist/mime-types.cjs +10 -4
- package/dist/mime-types.d.ts +8 -11
- package/dist/mime-types.js +9 -3
- package/dist/mime-types.mjs +9 -3
- package/dist/native.cjs +8616 -8869
- package/dist/native.d.ts +7 -8
- package/dist/native.js +8682 -8935
- package/dist/native.mjs +8615 -8868
- package/dist/path.cjs +83 -77
- package/dist/path.d.ts +29 -29
- package/dist/path.js +82 -76
- package/dist/path.mjs +82 -76
- package/dist/pm.cjs +3300 -0
- package/dist/pm.d.ts +256 -0
- package/dist/pm.js +5638 -0
- package/dist/pm.mjs +3196 -0
- package/dist/preview-build.cjs +712 -0
- package/dist/preview-build.d.ts +59 -0
- package/dist/preview-build.js +3194 -0
- package/dist/preview-build.mjs +676 -0
- package/dist/render-context.cjs +13 -2
- package/dist/render-context.d.ts +9 -31
- package/dist/render-context.js +11 -2
- package/dist/render-context.mjs +11 -2
- package/dist/router.cjs +787 -645
- package/dist/router.d.ts +8 -12
- package/dist/router.js +786 -644
- package/dist/router.mjs +786 -644
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/server.cjs +3315 -2603
- package/dist/server.d.ts +49 -4
- package/dist/server.js +7611 -2834
- package/dist/server.mjs +3317 -2607
- package/dist/smtp-server.cjs +128 -0
- package/dist/smtp-server.d.ts +27 -0
- package/dist/smtp-server.js +4199 -0
- package/dist/smtp-server.mjs +100 -0
- package/dist/state-DvEkDehk.d.ts +195 -0
- package/dist/state.cjs +768 -658
- package/dist/state.d.ts +11 -69
- package/dist/state.js +760 -650
- package/dist/state.mjs +767 -657
- package/dist/style.cjs +1011 -968
- package/dist/style.d.ts +13 -127
- package/dist/style.js +1009 -970
- package/dist/style.mjs +1011 -971
- package/dist/test-reporter.cjs +332 -316
- package/dist/test-reporter.d.ts +28 -33
- package/dist/test-reporter.js +328 -312
- package/dist/test-reporter.mjs +328 -312
- package/dist/test-runtime.cjs +927 -968
- package/dist/test-runtime.d.ts +24 -99
- package/dist/test-runtime.js +922 -965
- package/dist/test-runtime.mjs +922 -965
- package/dist/test.cjs +4428 -4273
- package/dist/test.d.ts +2 -8
- package/dist/test.js +4307 -4154
- package/dist/test.mjs +4419 -4267
- package/dist/types-BONVzPtp.d.ts +59 -0
- package/dist/types-BR4wMiVx.d.ts +32 -0
- package/dist/types-C4gKykuG.d.ts +23 -0
- package/dist/types-CIhpN1-K.d.ts +64 -0
- package/dist/types-Ckj8md_j.d.ts +84 -0
- package/dist/types-CpjQTAkX.d.ts +24 -0
- package/dist/types-D0LjrYjS.d.ts +14 -0
- package/dist/types-DAisuVr5.d.ts +75 -0
- package/dist/types-tJn88E1N.d.ts +242 -0
- package/dist/types.d.ts +71 -226
- package/dist/universal.cjs +1 -1
- package/dist/universal.d.ts +1 -5
- package/dist/universal.js +1 -1
- package/dist/universal.mjs +1 -1
- package/dist/websocket-XfyK23zD.d.ts +119 -0
- package/dist/ws.cjs +129 -108
- package/dist/ws.d.ts +21 -131
- package/dist/ws.js +128 -109
- package/dist/ws.mjs +128 -109
- package/dist/wss.cjs +757 -479
- package/dist/wss.d.ts +31 -28
- package/dist/wss.js +755 -479
- package/dist/wss.mjs +758 -482
- package/package.json +16 -1
- package/vendor/epaint-0.31.1/src/image.rs +418 -0
- package/dist/server-CcBFc2F5.d.ts +0 -449
package/dist/http.mjs
CHANGED
|
@@ -6,23 +6,88 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
// src/http.ts
|
|
10
|
-
|
|
9
|
+
// src/server/http/agent.ts
|
|
10
|
+
var Agent = class {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
11
15
|
|
|
12
|
-
// src/
|
|
13
|
-
|
|
14
|
-
if (typeof Deno !== "undefined") return "deno";
|
|
15
|
-
if (typeof Bun !== "undefined") return "bun";
|
|
16
|
-
return "node";
|
|
17
|
-
})();
|
|
18
|
-
var isNode = runtime === "node";
|
|
19
|
-
var isBun = runtime === "bun";
|
|
20
|
-
var isDeno = runtime === "deno";
|
|
16
|
+
// src/server/http/client-request.ts
|
|
17
|
+
import { EventEmitter } from "events";
|
|
21
18
|
|
|
22
|
-
// src/http.ts
|
|
19
|
+
// src/server/http/utils.ts
|
|
23
20
|
function queueCallback(callback) {
|
|
24
21
|
if (callback) queueMicrotask(callback);
|
|
25
22
|
}
|
|
23
|
+
function getRequestPath(url) {
|
|
24
|
+
if (!url) return "";
|
|
25
|
+
try {
|
|
26
|
+
const urlObj = new URL(url);
|
|
27
|
+
return urlObj.pathname + urlObj.search;
|
|
28
|
+
} catch {
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function headersToRecord(headers) {
|
|
33
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
34
|
+
headers.forEach((value, key) => {
|
|
35
|
+
result[key] = value;
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function headersToRawHeaders(headers) {
|
|
40
|
+
const rawHeaders = [];
|
|
41
|
+
headers.forEach((value, key) => {
|
|
42
|
+
rawHeaders.push(key, value);
|
|
43
|
+
});
|
|
44
|
+
return rawHeaders;
|
|
45
|
+
}
|
|
46
|
+
function normalizeRequestBodyChunk(chunk, encoding = "utf8") {
|
|
47
|
+
if (typeof chunk === "string") {
|
|
48
|
+
if (encoding !== "utf8" && typeof Buffer !== "undefined") {
|
|
49
|
+
return Buffer.from(chunk, encoding);
|
|
50
|
+
}
|
|
51
|
+
return chunk;
|
|
52
|
+
}
|
|
53
|
+
if (chunk instanceof Uint8Array) {
|
|
54
|
+
return chunk;
|
|
55
|
+
}
|
|
56
|
+
if (chunk instanceof ArrayBuffer) {
|
|
57
|
+
return new Uint8Array(chunk);
|
|
58
|
+
}
|
|
59
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
60
|
+
return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
61
|
+
}
|
|
62
|
+
return new TextEncoder().encode(String(chunk));
|
|
63
|
+
}
|
|
64
|
+
function buildRequestBody(chunks) {
|
|
65
|
+
if (chunks.length === 0) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
if (chunks.length === 1) {
|
|
69
|
+
return chunks[0];
|
|
70
|
+
}
|
|
71
|
+
if (chunks.every((chunk) => typeof chunk === "string")) {
|
|
72
|
+
return chunks.join("");
|
|
73
|
+
}
|
|
74
|
+
const encoder = new TextEncoder();
|
|
75
|
+
const bodyParts = chunks.map((chunk) => typeof chunk === "string" ? encoder.encode(chunk) : chunk);
|
|
76
|
+
const totalLength = bodyParts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
77
|
+
const body = new Uint8Array(totalLength);
|
|
78
|
+
let offset = 0;
|
|
79
|
+
for (const part of bodyParts) {
|
|
80
|
+
body.set(part, offset);
|
|
81
|
+
offset += part.byteLength;
|
|
82
|
+
}
|
|
83
|
+
return body;
|
|
84
|
+
}
|
|
85
|
+
function isFetchResponse(value) {
|
|
86
|
+
return typeof value?.status === "number" && typeof value?.statusText === "string" && typeof value?.headers?.forEach === "function";
|
|
87
|
+
}
|
|
88
|
+
function isNodeIncomingMessage(value) {
|
|
89
|
+
return typeof value?.on === "function" && typeof value?.headers === "object" && (typeof value?.httpVersion === "string" || value?.socket !== void 0);
|
|
90
|
+
}
|
|
26
91
|
function headersToInit(headers) {
|
|
27
92
|
const result = {};
|
|
28
93
|
for (const key in headers) {
|
|
@@ -47,17 +112,73 @@ function closeAndEmit(server, callback) {
|
|
|
47
112
|
server.emit("close");
|
|
48
113
|
if (callback) queueMicrotask(() => callback());
|
|
49
114
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
http = __require("http");
|
|
58
|
-
https = __require("https");
|
|
115
|
+
|
|
116
|
+
// src/server/http/client-request.ts
|
|
117
|
+
var ClientRequest = class extends EventEmitter {
|
|
118
|
+
constructor(_url, _options = {}) {
|
|
119
|
+
super();
|
|
120
|
+
this._bodyChunks = [];
|
|
121
|
+
this._ended = false;
|
|
59
122
|
}
|
|
60
|
-
|
|
123
|
+
_setNativeRequest(nativeRequest) {
|
|
124
|
+
this._nativeRequest = nativeRequest;
|
|
125
|
+
}
|
|
126
|
+
_setExecutor(executor) {
|
|
127
|
+
this._executor = executor;
|
|
128
|
+
}
|
|
129
|
+
write(chunk, encoding, callback) {
|
|
130
|
+
if (this._ended) {
|
|
131
|
+
throw new Error("Cannot write after end");
|
|
132
|
+
}
|
|
133
|
+
if (typeof encoding === "function") {
|
|
134
|
+
callback = encoding;
|
|
135
|
+
encoding = void 0;
|
|
136
|
+
}
|
|
137
|
+
if (this._nativeRequest) {
|
|
138
|
+
const actualEncoding2 = typeof encoding === "string" ? encoding : void 0;
|
|
139
|
+
return this._nativeRequest.write(chunk, actualEncoding2, callback);
|
|
140
|
+
}
|
|
141
|
+
const actualEncoding = typeof encoding === "string" ? encoding : "utf8";
|
|
142
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, actualEncoding));
|
|
143
|
+
queueCallback(callback);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
end(chunk, encoding, callback) {
|
|
147
|
+
if (typeof chunk === "function") {
|
|
148
|
+
callback = chunk;
|
|
149
|
+
chunk = void 0;
|
|
150
|
+
encoding = void 0;
|
|
151
|
+
} else if (typeof encoding === "function") {
|
|
152
|
+
callback = encoding;
|
|
153
|
+
encoding = void 0;
|
|
154
|
+
}
|
|
155
|
+
if (this._ended) {
|
|
156
|
+
queueCallback(callback);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this._ended = true;
|
|
160
|
+
if (this._nativeRequest) {
|
|
161
|
+
const actualEncoding = typeof encoding === "string" ? encoding : void 0;
|
|
162
|
+
if (chunk !== void 0) {
|
|
163
|
+
this._nativeRequest.end(chunk, actualEncoding, callback);
|
|
164
|
+
} else {
|
|
165
|
+
this._nativeRequest.end(callback);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (chunk !== void 0) {
|
|
170
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
|
|
171
|
+
}
|
|
172
|
+
const executor = this._executor;
|
|
173
|
+
const body = buildRequestBody(this._bodyChunks);
|
|
174
|
+
if (executor) {
|
|
175
|
+
Promise.resolve().then(() => executor(body)).catch((error) => this.emit("error", error));
|
|
176
|
+
}
|
|
177
|
+
queueCallback(callback);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/server/http/constants.ts
|
|
61
182
|
var METHODS = [
|
|
62
183
|
"GET",
|
|
63
184
|
"POST",
|
|
@@ -125,13 +246,23 @@ var STATUS_CODES = {
|
|
|
125
246
|
510: "Not Extended",
|
|
126
247
|
511: "Network Authentication Required"
|
|
127
248
|
};
|
|
128
|
-
|
|
129
|
-
|
|
249
|
+
|
|
250
|
+
// src/server/http/incoming-message.ts
|
|
251
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
252
|
+
var IncomingMessage = class extends EventEmitter2 {
|
|
253
|
+
constructor(req, requestMethod) {
|
|
130
254
|
super();
|
|
131
255
|
this.httpVersion = "1.1";
|
|
132
256
|
this.rawHeaders = [];
|
|
133
257
|
this._req = req;
|
|
134
|
-
if (
|
|
258
|
+
if (isFetchResponse(req)) {
|
|
259
|
+
this.method = requestMethod || "GET";
|
|
260
|
+
this.url = getRequestPath(req.url);
|
|
261
|
+
this.headers = headersToRecord(req.headers);
|
|
262
|
+
this.statusCode = req.status;
|
|
263
|
+
this.statusMessage = req.statusText;
|
|
264
|
+
this.rawHeaders = headersToRawHeaders(req.headers);
|
|
265
|
+
} else if (isNodeIncomingMessage(req)) {
|
|
135
266
|
this.method = req.method;
|
|
136
267
|
this.url = req.url;
|
|
137
268
|
this.headers = req.headers;
|
|
@@ -142,14 +273,13 @@ var IncomingMessage = class extends EventEmitter {
|
|
|
142
273
|
this.socket = req.socket;
|
|
143
274
|
} else {
|
|
144
275
|
this.method = req.method;
|
|
145
|
-
|
|
146
|
-
this.
|
|
147
|
-
this.
|
|
148
|
-
this.rawHeaders = [];
|
|
276
|
+
this.url = getRequestPath(req.url);
|
|
277
|
+
this.headers = headersToRecord(req.headers);
|
|
278
|
+
this.rawHeaders = headersToRawHeaders(req.headers);
|
|
149
279
|
}
|
|
150
280
|
}
|
|
151
281
|
async text() {
|
|
152
|
-
if (
|
|
282
|
+
if (isNodeIncomingMessage(this._req)) {
|
|
153
283
|
return new Promise((resolve, reject) => {
|
|
154
284
|
const chunks = [];
|
|
155
285
|
this._req.on("data", (chunk) => chunks.push(chunk));
|
|
@@ -160,14 +290,80 @@ var IncomingMessage = class extends EventEmitter {
|
|
|
160
290
|
return this._req.text();
|
|
161
291
|
}
|
|
162
292
|
async json() {
|
|
163
|
-
if (
|
|
293
|
+
if (isNodeIncomingMessage(this._req)) {
|
|
164
294
|
const text = await this.text();
|
|
165
295
|
return JSON.parse(text);
|
|
166
296
|
}
|
|
167
297
|
return this._req.json();
|
|
168
298
|
}
|
|
169
299
|
};
|
|
170
|
-
|
|
300
|
+
|
|
301
|
+
// src/shares/runtime.ts
|
|
302
|
+
var runtime = (() => {
|
|
303
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
304
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
305
|
+
return "node";
|
|
306
|
+
})();
|
|
307
|
+
var isNode = runtime === "node";
|
|
308
|
+
var isBun = runtime === "bun";
|
|
309
|
+
var isDeno = runtime === "deno";
|
|
310
|
+
|
|
311
|
+
// src/server/http/node-modules.ts
|
|
312
|
+
var http;
|
|
313
|
+
var https;
|
|
314
|
+
if (isNode && typeof process !== "undefined") {
|
|
315
|
+
try {
|
|
316
|
+
http = __require("http");
|
|
317
|
+
https = __require("https");
|
|
318
|
+
} catch {
|
|
319
|
+
http = __require("http");
|
|
320
|
+
https = __require("https");
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/server/http/request-api.ts
|
|
325
|
+
function request(url, options, callback) {
|
|
326
|
+
const urlString = typeof url === "string" ? url : url.toString();
|
|
327
|
+
const req = new ClientRequest(urlString, options);
|
|
328
|
+
if (isNode) {
|
|
329
|
+
const urlObj = new URL(urlString);
|
|
330
|
+
const client = urlObj.protocol === "https:" ? https : http;
|
|
331
|
+
const nodeReq = client.request(urlString, {
|
|
332
|
+
method: options?.method || "GET",
|
|
333
|
+
headers: options?.headers,
|
|
334
|
+
timeout: options?.timeout,
|
|
335
|
+
signal: options?.signal
|
|
336
|
+
}, (res) => {
|
|
337
|
+
const incomingMessage = new IncomingMessage(res);
|
|
338
|
+
if (callback) callback(incomingMessage);
|
|
339
|
+
req.emit("response", incomingMessage);
|
|
340
|
+
});
|
|
341
|
+
req._setNativeRequest(nodeReq);
|
|
342
|
+
nodeReq.on("error", (error) => req.emit("error", error));
|
|
343
|
+
} else {
|
|
344
|
+
req._setExecutor(async (body) => {
|
|
345
|
+
const response = await fetch(urlString, {
|
|
346
|
+
method: options?.method || "GET",
|
|
347
|
+
headers: options?.headers,
|
|
348
|
+
body,
|
|
349
|
+
signal: options?.signal
|
|
350
|
+
});
|
|
351
|
+
const incomingMessage = new IncomingMessage(response, options?.method || "GET");
|
|
352
|
+
if (callback) callback(incomingMessage);
|
|
353
|
+
req.emit("response", incomingMessage);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
return req;
|
|
357
|
+
}
|
|
358
|
+
function get(url, options, callback) {
|
|
359
|
+
const req = request(url, { ...options, method: "GET" }, callback);
|
|
360
|
+
req.end();
|
|
361
|
+
return req;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// src/server/http/response.ts
|
|
365
|
+
import { EventEmitter as EventEmitter3 } from "events";
|
|
366
|
+
var ServerResponse = class extends EventEmitter3 {
|
|
171
367
|
constructor(_req, nodeRes) {
|
|
172
368
|
super();
|
|
173
369
|
this.statusCode = 200;
|
|
@@ -300,7 +496,6 @@ var ServerResponse = class extends EventEmitter {
|
|
|
300
496
|
_setResolver(resolve) {
|
|
301
497
|
this._resolve = resolve;
|
|
302
498
|
}
|
|
303
|
-
// Express.js-like methods
|
|
304
499
|
json(data, statusCode = 200) {
|
|
305
500
|
if (!this.headersSent) {
|
|
306
501
|
this.setHeader("Content-Type", "application/json");
|
|
@@ -324,7 +519,15 @@ var ServerResponse = class extends EventEmitter {
|
|
|
324
519
|
return this;
|
|
325
520
|
}
|
|
326
521
|
};
|
|
327
|
-
|
|
522
|
+
|
|
523
|
+
// src/server/http/runtime.ts
|
|
524
|
+
function getRuntime() {
|
|
525
|
+
return runtime;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// src/server/http/server-runtime.ts
|
|
529
|
+
import { EventEmitter as EventEmitter4 } from "events";
|
|
530
|
+
var Server = class extends EventEmitter4 {
|
|
328
531
|
constructor(requestListener) {
|
|
329
532
|
super();
|
|
330
533
|
this._bunWebSocketServers = /* @__PURE__ */ new Set();
|
|
@@ -399,6 +602,8 @@ var Server = class extends EventEmitter {
|
|
|
399
602
|
const urlObj = new URL(req.url);
|
|
400
603
|
const pathname = urlObj.pathname;
|
|
401
604
|
const requestUrl = urlObj.pathname + urlObj.search;
|
|
605
|
+
const incomingHeaders = headersToRecord(req.headers);
|
|
606
|
+
const rawHeaders = headersToRawHeaders(req.headers);
|
|
402
607
|
const upgradeHeader = req.headers.get("upgrade");
|
|
403
608
|
if (upgradeHeader && upgradeHeader.toLowerCase() === "websocket") {
|
|
404
609
|
const matchingWebSocketServer = Array.from(this._bunWebSocketServers).find((wsServer) => {
|
|
@@ -435,9 +640,9 @@ var Server = class extends EventEmitter {
|
|
|
435
640
|
const incomingMessage = {
|
|
436
641
|
method: req.method,
|
|
437
642
|
url: requestUrl,
|
|
438
|
-
headers:
|
|
643
|
+
headers: incomingHeaders,
|
|
439
644
|
httpVersion: "1.1",
|
|
440
|
-
rawHeaders
|
|
645
|
+
rawHeaders,
|
|
441
646
|
_req: req,
|
|
442
647
|
text: () => req.text(),
|
|
443
648
|
json: () => req.json()
|
|
@@ -496,6 +701,8 @@ var Server = class extends EventEmitter {
|
|
|
496
701
|
};
|
|
497
702
|
if (self.requestListener) {
|
|
498
703
|
self.requestListener(incomingMessage, serverResponse);
|
|
704
|
+
} else {
|
|
705
|
+
self.emit("request", incomingMessage, serverResponse);
|
|
499
706
|
}
|
|
500
707
|
if (responseReady) {
|
|
501
708
|
return new Response(body, {
|
|
@@ -570,9 +777,11 @@ var Server = class extends EventEmitter {
|
|
|
570
777
|
return createAddress(0, addr, "unix");
|
|
571
778
|
}
|
|
572
779
|
return addr;
|
|
573
|
-
}
|
|
780
|
+
}
|
|
781
|
+
if (isBun) {
|
|
574
782
|
return createAddress(this.nativeServer.port, this.nativeServer.hostname);
|
|
575
|
-
}
|
|
783
|
+
}
|
|
784
|
+
if (isDeno) {
|
|
576
785
|
const addr = this.nativeServer.addr;
|
|
577
786
|
return createAddress(addr.port, addr.hostname);
|
|
578
787
|
}
|
|
@@ -582,70 +791,11 @@ var Server = class extends EventEmitter {
|
|
|
582
791
|
return this._listening;
|
|
583
792
|
}
|
|
584
793
|
};
|
|
585
|
-
var ClientRequest = class extends EventEmitter {
|
|
586
|
-
constructor(_url, _options = {}) {
|
|
587
|
-
super();
|
|
588
|
-
}
|
|
589
|
-
write(_chunk) {
|
|
590
|
-
return true;
|
|
591
|
-
}
|
|
592
|
-
end(callback) {
|
|
593
|
-
queueCallback(callback);
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
var Agent = class {
|
|
597
|
-
constructor(options) {
|
|
598
|
-
this.options = options;
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
794
|
function createServer(optionsOrListener, requestListener) {
|
|
602
795
|
return new Server(typeof optionsOrListener === "function" ? optionsOrListener : requestListener);
|
|
603
796
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const req = new ClientRequest(urlString, options);
|
|
607
|
-
if (isNode) {
|
|
608
|
-
const urlObj = new URL(urlString);
|
|
609
|
-
const client = urlObj.protocol === "https:" ? https : http;
|
|
610
|
-
const nodeReq = client.request(urlString, {
|
|
611
|
-
method: options?.method || "GET",
|
|
612
|
-
headers: options?.headers,
|
|
613
|
-
timeout: options?.timeout,
|
|
614
|
-
signal: options?.signal
|
|
615
|
-
}, (res) => {
|
|
616
|
-
const incomingMessage = new IncomingMessage(res);
|
|
617
|
-
if (callback) callback(incomingMessage);
|
|
618
|
-
req.emit("response", incomingMessage);
|
|
619
|
-
});
|
|
620
|
-
nodeReq.on("error", (error) => req.emit("error", error));
|
|
621
|
-
nodeReq.end();
|
|
622
|
-
} else {
|
|
623
|
-
queueMicrotask(async () => {
|
|
624
|
-
try {
|
|
625
|
-
const response = await fetch(urlString, {
|
|
626
|
-
method: options?.method || "GET",
|
|
627
|
-
headers: options?.headers,
|
|
628
|
-
signal: options?.signal
|
|
629
|
-
});
|
|
630
|
-
const fetchRequest = new Request(urlString);
|
|
631
|
-
const incomingMessage = new IncomingMessage(fetchRequest);
|
|
632
|
-
incomingMessage.statusCode = response.status;
|
|
633
|
-
incomingMessage.statusMessage = response.statusText;
|
|
634
|
-
if (callback) callback(incomingMessage);
|
|
635
|
-
req.emit("response", incomingMessage);
|
|
636
|
-
} catch (error) {
|
|
637
|
-
req.emit("error", error);
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
return req;
|
|
642
|
-
}
|
|
643
|
-
function get(url, options, callback) {
|
|
644
|
-
return request(url, { ...options, method: "GET" }, callback);
|
|
645
|
-
}
|
|
646
|
-
function getRuntime() {
|
|
647
|
-
return runtime;
|
|
648
|
-
}
|
|
797
|
+
|
|
798
|
+
// src/server/http/index.ts
|
|
649
799
|
var http_default = {
|
|
650
800
|
createServer,
|
|
651
801
|
request,
|