@maiyunnet/kebab 9.29.6 → 10.0.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/abox/proxy.js +24 -2
- package/abox/response.js +36 -17
- package/abox/session-login.js +1 -13
- package/doc/kebab-rag.md +1522 -1034
- package/index.d.ts +12 -1
- package/index.js +1 -1
- package/lib/ai.d.ts +4 -0
- package/lib/ai.js +32 -16
- package/lib/cookie.d.ts +2 -0
- package/lib/cookie.js +47 -45
- package/lib/core.d.ts +26 -0
- package/lib/core.js +36 -13
- package/lib/cron.js +1 -8
- package/lib/crypto.js +20 -6
- package/lib/db/conn.js +1 -0
- package/lib/fs.js +78 -31
- package/lib/kv.d.ts +182 -79
- package/lib/kv.js +518 -214
- package/lib/s3.d.ts +2 -0
- package/lib/s3.js +14 -27
- package/lib/session.d.ts +7 -0
- package/lib/session.js +23 -2
- package/lib/socket.d.ts +4 -1
- package/lib/socket.js +1 -0
- package/lib/sql.d.ts +0 -5
- package/lib/sql.js +48 -12
- package/lib/text.d.ts +10 -5
- package/lib/text.js +22 -12
- package/lib/turnstile.d.ts +6 -0
- package/lib/turnstile.js +16 -9
- package/lib/undici.d.ts +7 -1
- package/lib/undici.js +72 -36
- package/lib/ws.d.ts +1 -1
- package/lib/ws.js +85 -128
- package/lib/zip.js +46 -45
- package/package.json +2 -2
- package/sys/child.js +178 -146
- package/sys/cmd.js +196 -197
- package/sys/ctr.d.ts +14 -14
- package/sys/ctr.js +145 -59
- package/sys/master.js +111 -80
- package/sys/mod.d.ts +8 -2
- package/sys/mod.js +23 -11
- package/sys/monitor/files.d.ts +2 -1
- package/sys/monitor/files.js +77 -21
- package/sys/monitor/watchdog.d.ts +7 -0
- package/sys/monitor/watchdog.js +311 -203
- package/sys/monitor.d.ts +59 -54
- package/sys/monitor.js +742 -681
- package/sys/route.d.ts +4 -4
- package/sys/route.js +93 -52
- package/www/example/ctr/test.js +8 -8
package/abox/proxy.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const excludedHeaders = new Set([
|
|
2
2
|
'host', 'connection', 'keep-alive', 'http-code', 'http-url',
|
|
3
3
|
'transfer-encoding', 'upgrade', 'proxy-connection',
|
|
4
|
+
'te', 'trailer', 'proxy-authenticate', 'proxy-authorization',
|
|
4
5
|
]);
|
|
5
6
|
const privateHeaders = new Set([
|
|
6
7
|
'forwarded', 'via', 'x-real-ip', 'true-client-ip', 'client-ip', 'x-client-ip',
|
|
@@ -10,8 +11,22 @@ const privateHeaders = new Set([
|
|
|
10
11
|
export function filterProxyHeaders(headers, res, filter) {
|
|
11
12
|
const result = {};
|
|
12
13
|
const sent = res?.headersSent ?? false;
|
|
14
|
+
const dynamicHopByHop = new Set();
|
|
13
15
|
for (const name in headers) {
|
|
14
|
-
if (
|
|
16
|
+
if (name.toLowerCase() === 'connection') {
|
|
17
|
+
const raw = headers[name];
|
|
18
|
+
const text = Array.isArray(raw) ? raw.join(',') : String(raw ?? '');
|
|
19
|
+
for (const part of text.split(',')) {
|
|
20
|
+
const token = part.trim().toLowerCase();
|
|
21
|
+
if (token) {
|
|
22
|
+
dynamicHopByHop.add(token);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const name in headers) {
|
|
28
|
+
const lower = name.toLowerCase();
|
|
29
|
+
if (excludedHeaders.has(lower) || dynamicHopByHop.has(lower) || name.includes(':') || name.includes('(')) {
|
|
15
30
|
continue;
|
|
16
31
|
}
|
|
17
32
|
const value = headers[name];
|
|
@@ -32,7 +47,14 @@ export function filterProxyHeaders(headers, res, filter) {
|
|
|
32
47
|
export function buildProxyHeaders(req, opt = {}) {
|
|
33
48
|
const headers = filterProxyHeaders(req.headers, undefined, opt.filter);
|
|
34
49
|
if (opt.proxyMode === undefined || opt.proxyMode === 'passthrough') {
|
|
35
|
-
|
|
50
|
+
const merged = {};
|
|
51
|
+
for (const name in headers) {
|
|
52
|
+
merged[name.toLowerCase()] = headers[name];
|
|
53
|
+
}
|
|
54
|
+
for (const name in opt.headers) {
|
|
55
|
+
merged[name.toLowerCase()] = opt.headers[name];
|
|
56
|
+
}
|
|
57
|
+
return merged;
|
|
36
58
|
}
|
|
37
59
|
const result = {};
|
|
38
60
|
for (const name in headers) {
|
package/abox/response.js
CHANGED
|
@@ -4,6 +4,31 @@ export function pipeResponse(parts, response, compress, onInputDone) {
|
|
|
4
4
|
const sources = parts.filter((part) => part instanceof stream.Readable);
|
|
5
5
|
let failure;
|
|
6
6
|
let inputDone = false;
|
|
7
|
+
const h2Stream = response.stream;
|
|
8
|
+
const isClosed = () => {
|
|
9
|
+
if (response.destroyed || response.writableEnded || response.closed) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return !!(h2Stream && (h2Stream.destroyed || h2Stream.writableEnded || h2Stream.closed));
|
|
13
|
+
};
|
|
14
|
+
const stopSources = () => {
|
|
15
|
+
for (const source of sources) {
|
|
16
|
+
if (!source.destroyed) {
|
|
17
|
+
source.destroy();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const finishInput = () => {
|
|
22
|
+
if (!inputDone) {
|
|
23
|
+
inputDone = true;
|
|
24
|
+
onInputDone?.();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
if (isClosed()) {
|
|
28
|
+
stopSources();
|
|
29
|
+
finishInput();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
7
32
|
const combined = stream.Readable.from((async function* () {
|
|
8
33
|
for (const part of parts) {
|
|
9
34
|
if (failure) {
|
|
@@ -19,13 +44,6 @@ export function pipeResponse(parts, response, compress, onInputDone) {
|
|
|
19
44
|
}
|
|
20
45
|
}
|
|
21
46
|
})());
|
|
22
|
-
const stopSources = () => {
|
|
23
|
-
for (const source of sources) {
|
|
24
|
-
if (!source.destroyed) {
|
|
25
|
-
source.destroy();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
47
|
const onError = (error) => {
|
|
30
48
|
failure ??= error;
|
|
31
49
|
if (!inputDone) {
|
|
@@ -38,22 +56,23 @@ export function pipeResponse(parts, response, compress, onInputDone) {
|
|
|
38
56
|
source.once('close', () => source.off('error', onError));
|
|
39
57
|
}
|
|
40
58
|
response.once('close', stopSources);
|
|
41
|
-
|
|
42
|
-
if (!inputDone) {
|
|
43
|
-
inputDone = true;
|
|
44
|
-
onInputDone?.();
|
|
45
|
-
}
|
|
46
|
-
};
|
|
59
|
+
h2Stream?.once('close', stopSources);
|
|
47
60
|
combined.once('end', finishInput);
|
|
48
61
|
const done = () => {
|
|
49
62
|
stopSources();
|
|
50
63
|
response.off('close', stopSources);
|
|
64
|
+
h2Stream?.off('close', stopSources);
|
|
51
65
|
finishInput();
|
|
52
66
|
};
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
try {
|
|
68
|
+
if (compress) {
|
|
69
|
+
stream.pipeline(combined, compress, response, done);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
stream.pipeline(combined, response, done);
|
|
73
|
+
}
|
|
55
74
|
}
|
|
56
|
-
|
|
57
|
-
|
|
75
|
+
catch {
|
|
76
|
+
done();
|
|
58
77
|
}
|
|
59
78
|
}
|
package/abox/session-login.js
CHANGED
|
@@ -150,19 +150,7 @@ export class Store {
|
|
|
150
150
|
async _run(args) {
|
|
151
151
|
if (!this._valid)
|
|
152
152
|
return false;
|
|
153
|
-
|
|
154
|
-
const pipeline = await this._kv.pipeline();
|
|
155
|
-
if (pipeline === false)
|
|
156
|
-
return false;
|
|
157
|
-
pipeline.eval(script, [this._pre], args);
|
|
158
|
-
const result = await pipeline.exec();
|
|
159
|
-
if (result.length !== 1 || result[0] instanceof Error)
|
|
160
|
-
return false;
|
|
161
|
-
return result[0];
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
153
|
+
return this._kv.eval(script, [this._pre], args);
|
|
166
154
|
}
|
|
167
155
|
async create(token, identity, options) {
|
|
168
156
|
if (!this._valid || !tokenValid(token))
|