fulmine.js 5.19.2 → 5.19.4
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/package.json +2 -1
- package/src/adopt.js +20 -26
- package/src/application.js +63 -73
- package/src/cli.js +48 -48
- package/src/cluster.js +18 -27
- package/src/compression.js +141 -112
- package/src/declarative.js +611 -540
- package/src/hot-settings.js +80 -0
- package/src/index.js +11 -17
- package/src/lazy-readable.js +131 -0
- package/src/lazy-writable.js +97 -0
- package/src/middlewares.js +153 -130
- package/src/nest.js +22 -36
- package/src/node-shim.js +19 -16
- package/src/optimizer.js +600 -0
- package/src/options.d.ts +9 -4
- package/src/parse-query.js +3 -3
- package/src/request-utils.js +307 -0
- package/src/request.js +147 -548
- package/src/response-utils.js +88 -0
- package/src/response.js +228 -535
- package/src/route.js +7 -8
- package/src/router-utils.js +998 -0
- package/src/router.js +166 -2170
- package/src/server-shape.js +40 -51
- package/src/server-timing.js +32 -33
- package/src/socket.js +208 -0
- package/src/testing.js +43 -45
- package/src/usage.js +25 -25
- package/src/utils.js +165 -78
- package/src/verify.js +22 -31
- package/src/view.js +6 -8
- package/src/walk.js +581 -0
- package/src/websocket.js +34 -26
- package/src/work.js +22 -28
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 dimden.dev
|
|
3
|
+
Copyright 2026 Nigro Simone
|
|
4
|
+
|
|
5
|
+
This file is derived from Ultimate Express and has been modified.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const http = require("http");
|
|
21
|
+
const statuses = require("statuses");
|
|
22
|
+
const { EventEmitter } = require("events");
|
|
23
|
+
|
|
24
|
+
const outgoingMessage = new http.OutgoingMessage();
|
|
25
|
+
const symbols = Object.getOwnPropertySymbols(outgoingMessage);
|
|
26
|
+
// if a future node renames it, fall back to a private symbol rather than writing a property
|
|
27
|
+
// literally named "undefined", which is what indexing with undefined would do
|
|
28
|
+
const kOutHeaders = symbols.find((s) => s.toString() === "Symbol(kOutHeaders)") ?? Symbol("kOutHeaders");
|
|
29
|
+
// node's emitters tombstone a removed listener's slot instead of deleting it when this flag is set,
|
|
30
|
+
// which keeps _events in a stable shape. EventEmitter.init sets it and never runs for the lazily
|
|
31
|
+
// materialized response, so it is set by hand. A future rename degrades to the delete
|
|
32
|
+
const kShapeMode =
|
|
33
|
+
Object.getOwnPropertySymbols(new EventEmitter()).find((s) => s.toString() === "Symbol(shapeMode)") ??
|
|
34
|
+
Symbol("shapeMode");
|
|
35
|
+
// names setHeader has validated and lowercased, so the constant names middleware writes per
|
|
36
|
+
// request are one Map hit. Insert-only after validation, bounded; only setHeader may insert,
|
|
37
|
+
// the never-throwing readers keep their plain toLowerCase
|
|
38
|
+
const VALIDATED_HEADER_NAMES = new Map();
|
|
39
|
+
// The names and values that recur on every response, kept as Buffers for the uWS crossing: a Buffer
|
|
40
|
+
// is memcpy'd as it is, a string pays a UTF-8 scan and copy per call. A header that is not here
|
|
41
|
+
// crosses as the string it was. Names must stay lowercase, as writeHeaders receives them.
|
|
42
|
+
const HEADER_NAME_BUF = { __proto__: null };
|
|
43
|
+
const HEADER_VALUE_BUF = { __proto__: null };
|
|
44
|
+
for (const s of ["connection", "keep-alive", "content-type", "vary", "x-powered-by", "content-encoding"]) {
|
|
45
|
+
HEADER_NAME_BUF[s] = Buffer.from(s);
|
|
46
|
+
}
|
|
47
|
+
for (const s of [
|
|
48
|
+
"keep-alive",
|
|
49
|
+
"timeout=10",
|
|
50
|
+
"close",
|
|
51
|
+
"Fulmine",
|
|
52
|
+
"Accept-Encoding",
|
|
53
|
+
"text/html; charset=utf-8",
|
|
54
|
+
"text/plain; charset=utf-8",
|
|
55
|
+
"application/json; charset=utf-8",
|
|
56
|
+
"application/octet-stream",
|
|
57
|
+
"gzip",
|
|
58
|
+
"br",
|
|
59
|
+
"deflate",
|
|
60
|
+
"zstd"
|
|
61
|
+
]) {
|
|
62
|
+
HEADER_VALUE_BUF[s] = Buffer.from(s);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// One status line per code, built on first use: the default path, with no custom reason phrase,
|
|
66
|
+
// paid a template string and a trim per request for a line that never changes. Bounded to real
|
|
67
|
+
// HTTP codes so a wild writeHead value cannot grow the array or flip it into dictionary mode.
|
|
68
|
+
const STATUS_LINES = [];
|
|
69
|
+
/**
|
|
70
|
+
* @param {number} code
|
|
71
|
+
* @param {string|undefined} text an explicit reason phrase, which bypasses the cache
|
|
72
|
+
* @returns {string} the uWS status line, e.g. "200 OK"
|
|
73
|
+
*/
|
|
74
|
+
function statusLine(code, text) {
|
|
75
|
+
if (text === undefined && Number.isInteger(code) && code >= 100 && code <= 999) {
|
|
76
|
+
return STATUS_LINES[code] ?? (STATUS_LINES[code] = code + " " + (statuses.message[code] ?? "unknown"));
|
|
77
|
+
}
|
|
78
|
+
return `${code} ${text ?? statuses.message[code] ?? "unknown"}`.trim();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
kOutHeaders,
|
|
83
|
+
kShapeMode,
|
|
84
|
+
VALIDATED_HEADER_NAMES,
|
|
85
|
+
HEADER_NAME_BUF,
|
|
86
|
+
HEADER_VALUE_BUF,
|
|
87
|
+
statusLine
|
|
88
|
+
};
|