@maiyunnet/kebab 9.26.2 → 9.26.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/abox/proxy.d.ts +9 -0
- package/abox/proxy.js +62 -0
- package/doc/kebab-rag.md +436 -200
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/fs.js +1 -1
- package/lib/undici/proxy.d.ts +36 -0
- package/lib/undici/proxy.js +21 -0
- package/lib/undici.d.ts +10 -6
- package/lib/undici.js +11 -41
- package/lib/ws.d.ts +4 -1
- package/lib/ws.js +3 -3
- package/package.json +1 -1
- package/sys/child.js +6 -14
- package/sys/ctr.js +1 -1
- package/sys/route.js +10 -11
- package/www/example/ctr/test.js +2 -2
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
6
6
|
*/
|
|
7
7
|
/** --- 当前系统版本号 --- */
|
|
8
|
-
export const VER = '9.26.
|
|
8
|
+
export const VER = '9.26.4';
|
|
9
9
|
// --- 服务端用的路径 ---
|
|
10
10
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
11
11
|
/** --- /xxx/xxx --- */
|
package/lib/fs.js
CHANGED
|
@@ -414,7 +414,7 @@ async function* readFileRanges(path, ranges, headers, footer) {
|
|
|
414
414
|
export async function readToResponse(path, req, res, stat) {
|
|
415
415
|
stat ??= await stats(path);
|
|
416
416
|
if (!stat) {
|
|
417
|
-
const content = '<h1>404 Not found</h1
|
|
417
|
+
const content = '<h1>404 Not found</h1>';
|
|
418
418
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
419
419
|
lCore.writeHead(res, 404);
|
|
420
420
|
res.end(req.method === 'HEAD' ? '' : content);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type * as http from 'http';
|
|
2
|
+
import type * as http2 from 'http2';
|
|
3
|
+
import type { THttpHeaders } from '#kebab/lib/undici.js';
|
|
4
|
+
/** --- undici 和 ws 共用请求头模式,mproxy 仅支持 passthrough 和 request --- */
|
|
5
|
+
export interface IProxyHeaderOptions {
|
|
6
|
+
/**
|
|
7
|
+
* --- 默认 passthrough 透传;request 使用目标 Host 并清理代理来源头;reverse 保留外部 Host 并生成来源头 ---
|
|
8
|
+
* passthrough 使用目标 Host,保留通过基础过滤的来路头,不自动生成来源头。
|
|
9
|
+
* request/reverse 均清理传入的 Forwarded、X-Forwarded-*、Via、X-Real-IP 及 CDN 来源头。
|
|
10
|
+
* reverse 的协议和 IP 仅取实际连接,不信任来路代理头;可信代理信息由业务验证后通过 headers 覆盖。
|
|
11
|
+
*/
|
|
12
|
+
'proxyMode'?: 'passthrough' | 'request' | 'reverse';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* --- 过滤代理请求或响应的基础头部,不处理来源信息 ---
|
|
16
|
+
* @param headers 待过滤的头部
|
|
17
|
+
* @param res 传入时直接设置响应头并返回空对象,响应头已发送时不再写入
|
|
18
|
+
* @param filter 业务过滤,返回 true 则保留
|
|
19
|
+
* @returns 过滤后的头部,不修改输入
|
|
20
|
+
*/
|
|
21
|
+
export declare const filterProxyHeaders: (headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse, filter?: (h: string) => boolean) => Record<string, string | string[]>;
|
|
22
|
+
/**
|
|
23
|
+
* --- 构造上游请求头,依次执行基础过滤、业务 filter、模式处理及 headers 覆盖 ---
|
|
24
|
+
* 保留 Cookie、Authorization、Origin、Referer 的业务语义,不保证请求无法被识别为代理。
|
|
25
|
+
* 来源头包括 Forwarded、Via、X-Real-IP、X-Forwarded-*、CF-*、EO-*、True-Client-IP、Client-IP、
|
|
26
|
+
* X-Client-IP、Fastly-Client-IP、X-Cluster-Client-IP、X-Envoy-External-Address、X-Original-Forwarded-For、
|
|
27
|
+
* X-Original-Host、X-Original-URL、X-Rewrite-URL;业务可通过 filter 补充过滤,headers 覆盖优先级最高。
|
|
28
|
+
* reverse 输出 Host、X-Forwarded-Host、X-Forwarded-Proto、X-Forwarded-For、X-Real-IP。
|
|
29
|
+
* @param req 原始 HTTP 或 WebSocket 握手请求
|
|
30
|
+
* @param opt 模式、业务过滤及显式覆盖的头部
|
|
31
|
+
* @returns 独立的上游请求头对象,不修改输入
|
|
32
|
+
*/
|
|
33
|
+
export declare const getProxyHeaders: (req: http.IncomingMessage | http2.Http2ServerRequest, opt?: IProxyHeaderOptions & {
|
|
34
|
+
'headers'?: http.IncomingHttpHeaders;
|
|
35
|
+
filter?: (h: string) => boolean;
|
|
36
|
+
}) => http.IncomingHttpHeaders;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { buildProxyHeaders, filterProxyHeaders as filterProxyHeadersImpl } from '#kebab/abox/proxy.js';
|
|
2
|
+
/**
|
|
3
|
+
* --- 过滤代理请求或响应的基础头部,不处理来源信息 ---
|
|
4
|
+
* @param headers 待过滤的头部
|
|
5
|
+
* @param res 传入时直接设置响应头并返回空对象,响应头已发送时不再写入
|
|
6
|
+
* @param filter 业务过滤,返回 true 则保留
|
|
7
|
+
* @returns 过滤后的头部,不修改输入
|
|
8
|
+
*/
|
|
9
|
+
export const filterProxyHeaders = filterProxyHeadersImpl;
|
|
10
|
+
/**
|
|
11
|
+
* --- 构造上游请求头,依次执行基础过滤、业务 filter、模式处理及 headers 覆盖 ---
|
|
12
|
+
* 保留 Cookie、Authorization、Origin、Referer 的业务语义,不保证请求无法被识别为代理。
|
|
13
|
+
* 来源头包括 Forwarded、Via、X-Real-IP、X-Forwarded-*、CF-*、EO-*、True-Client-IP、Client-IP、
|
|
14
|
+
* X-Client-IP、Fastly-Client-IP、X-Cluster-Client-IP、X-Envoy-External-Address、X-Original-Forwarded-For、
|
|
15
|
+
* X-Original-Host、X-Original-URL、X-Rewrite-URL;业务可通过 filter 补充过滤,headers 覆盖优先级最高。
|
|
16
|
+
* reverse 输出 Host、X-Forwarded-Host、X-Forwarded-Proto、X-Forwarded-For、X-Real-IP。
|
|
17
|
+
* @param req 原始 HTTP 或 WebSocket 握手请求
|
|
18
|
+
* @param opt 模式、业务过滤及显式覆盖的头部
|
|
19
|
+
* @returns 独立的上游请求头对象,不修改输入
|
|
20
|
+
*/
|
|
21
|
+
export const getProxyHeaders = buildProxyHeaders;
|
package/lib/undici.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as http2 from 'http2';
|
|
|
5
5
|
import * as kebab from '#kebab/index.js';
|
|
6
6
|
import * as lCookie from '#kebab/lib/cookie.js';
|
|
7
7
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
8
|
+
import * as lProxy from '#kebab/lib/undici/proxy.js';
|
|
8
9
|
import * as lFd from './undici/formdata.js';
|
|
9
10
|
import * as lRequest from './undici/request.js';
|
|
10
11
|
import * as lResponse from './undici/response.js';
|
|
@@ -89,12 +90,13 @@ export declare function request(u: string, data?: Record<string, kebab.Json> | B
|
|
|
89
90
|
*/
|
|
90
91
|
export declare function getFormData(): lFd.FormData;
|
|
91
92
|
/**
|
|
92
|
-
* ---
|
|
93
|
-
* @param headers
|
|
94
|
-
* @param res
|
|
95
|
-
* @param filter
|
|
93
|
+
* --- 过滤代理请求或响应的基础头部,不生成或清理来源信息 ---
|
|
94
|
+
* @param headers 待过滤的头部
|
|
95
|
+
* @param res 传入时直接设置响应头并返回空对象,响应头已发送时不再写入
|
|
96
|
+
* @param filter 业务过滤,返回 true 则保留
|
|
97
|
+
* @returns 过滤后的头部,不修改输入
|
|
96
98
|
*/
|
|
97
|
-
export declare
|
|
99
|
+
export declare const filterProxyHeaders: (headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse, filter?: (h: string) => boolean) => Record<string, string | string[]>;
|
|
98
100
|
/**
|
|
99
101
|
* --- 正向 mproxy 代理,注意提前处理不要自动处理 post 数据,读取 get 的 url 为实际请求地址 ---
|
|
100
102
|
* --- get: url, auth ---
|
|
@@ -171,6 +173,8 @@ export interface IRequestOptions {
|
|
|
171
173
|
}
|
|
172
174
|
/** --- 正向代理请求的传入参数选项 --- */
|
|
173
175
|
export interface IMproxyOptions {
|
|
176
|
+
/** --- 默认 passthrough 保留已有来源头;request 清理来源头;两者均使用目标 Host --- */
|
|
177
|
+
'proxyMode'?: 'passthrough' | 'request';
|
|
174
178
|
/** --- 秒数,默认 300 秒 --- */
|
|
175
179
|
'timeout'?: number;
|
|
176
180
|
'follow'?: number;
|
|
@@ -188,7 +192,7 @@ export interface IMproxyOptions {
|
|
|
188
192
|
'reuse'?: string | undici.ProxyAgent | undici.Agent;
|
|
189
193
|
}
|
|
190
194
|
/** --- 反向代理请求的传入参数选项 --- */
|
|
191
|
-
export interface IRproxyOptions {
|
|
195
|
+
export interface IRproxyOptions extends lProxy.IProxyHeaderOptions {
|
|
192
196
|
/** --- 秒数,默认 300 秒 --- */
|
|
193
197
|
'timeout'?: number;
|
|
194
198
|
'follow'?: number;
|
package/lib/undici.js
CHANGED
|
@@ -7,6 +7,7 @@ import * as lCrypto from '#kebab/lib/crypto.js';
|
|
|
7
7
|
import * as lCore from '#kebab/lib/core.js';
|
|
8
8
|
import * as lCookie from '#kebab/lib/cookie.js';
|
|
9
9
|
import * as lZlib from '#kebab/lib/zlib.js';
|
|
10
|
+
import * as lProxy from '#kebab/lib/undici/proxy.js';
|
|
10
11
|
// --- 自己 ---
|
|
11
12
|
import * as lFd from './undici/formdata.js';
|
|
12
13
|
import * as lRequest from './undici/request.js';
|
|
@@ -576,45 +577,14 @@ export async function request(u, data, opt = {}) {
|
|
|
576
577
|
export function getFormData() {
|
|
577
578
|
return new lFd.FormData();
|
|
578
579
|
}
|
|
579
|
-
/** --- proxy 要剔除的基础头部 --- */
|
|
580
|
-
const proxyContinueHeaders = [
|
|
581
|
-
'host', 'connection', 'keep-alive', 'http-code', 'http-url',
|
|
582
|
-
'transfer-encoding', 'upgrade', 'proxy-connection'
|
|
583
|
-
];
|
|
584
580
|
/**
|
|
585
|
-
* ---
|
|
586
|
-
* @param headers
|
|
587
|
-
* @param res
|
|
588
|
-
* @param filter
|
|
581
|
+
* --- 过滤代理请求或响应的基础头部,不生成或清理来源信息 ---
|
|
582
|
+
* @param headers 待过滤的头部
|
|
583
|
+
* @param res 传入时直接设置响应头并返回空对象,响应头已发送时不再写入
|
|
584
|
+
* @param filter 业务过滤,返回 true 则保留
|
|
585
|
+
* @returns 过滤后的头部,不修改输入
|
|
589
586
|
*/
|
|
590
|
-
export
|
|
591
|
-
const heads = {};
|
|
592
|
-
// --- HTTP/2 下响应已发送则跳过 setHeader,避免 ERR_HTTP2_HEADERS_SENT ---
|
|
593
|
-
const sent = res ? res.headersSent : false;
|
|
594
|
-
for (const h in headers) {
|
|
595
|
-
if (proxyContinueHeaders.includes(h)) {
|
|
596
|
-
continue;
|
|
597
|
-
}
|
|
598
|
-
if (h.includes(':') || h.includes('(')) {
|
|
599
|
-
continue;
|
|
600
|
-
}
|
|
601
|
-
const v = headers[h];
|
|
602
|
-
if (v === undefined) {
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
if (filter && !filter(h)) {
|
|
606
|
-
continue;
|
|
607
|
-
}
|
|
608
|
-
if (res) {
|
|
609
|
-
if (!sent) {
|
|
610
|
-
res.setHeader(h, v);
|
|
611
|
-
}
|
|
612
|
-
continue;
|
|
613
|
-
}
|
|
614
|
-
heads[h] = v;
|
|
615
|
-
}
|
|
616
|
-
return heads;
|
|
617
|
-
}
|
|
587
|
+
export const filterProxyHeaders = lProxy.filterProxyHeaders;
|
|
618
588
|
/**
|
|
619
589
|
* --- 正向 mproxy 代理,注意提前处理不要自动处理 post 数据,读取 get 的 url 为实际请求地址 ---
|
|
620
590
|
* --- get: url, auth ---
|
|
@@ -640,7 +610,7 @@ export async function mproxy(ctr, auth, opt = {}) {
|
|
|
640
610
|
opt.headers ??= {};
|
|
641
611
|
/** --- 传来的 hosts --- */
|
|
642
612
|
const hosts = lText.parseJson(get['hosts']);
|
|
643
|
-
const headers =
|
|
613
|
+
const headers = lProxy.getProxyHeaders(req, opt);
|
|
644
614
|
// --- 发起请求 ---
|
|
645
615
|
const rres = await request(get['url'], req, {
|
|
646
616
|
...opt,
|
|
@@ -658,7 +628,7 @@ export async function mproxy(ctr, auth, opt = {}) {
|
|
|
658
628
|
// --- HTTP/2 下响应可能已被客户端取消,跳过头部设置避免崩溃 ---
|
|
659
629
|
if (!res.headersSent) {
|
|
660
630
|
if (rres.headers) {
|
|
661
|
-
|
|
631
|
+
filterProxyHeaders(rres.headers, res, opt.filter);
|
|
662
632
|
}
|
|
663
633
|
lCore.writeHead(res, rres.headers?.['http-code'] ?? 200);
|
|
664
634
|
await new Promise(resolve => {
|
|
@@ -728,7 +698,7 @@ export async function rproxy(ctr, route, opt = {}) {
|
|
|
728
698
|
const lpath = path.slice(key.length);
|
|
729
699
|
opt.method = req.method ?? 'GET';
|
|
730
700
|
opt.headers ??= {};
|
|
731
|
-
const headers =
|
|
701
|
+
const headers = lProxy.getProxyHeaders(req, opt);
|
|
732
702
|
// --- 拼接代理目标 URL ---
|
|
733
703
|
let proxyUrl = route[key] + lpath;
|
|
734
704
|
// --- 自定义 GET 查询参数(直接替换整个 query string) ---
|
|
@@ -755,7 +725,7 @@ export async function rproxy(ctr, route, opt = {}) {
|
|
|
755
725
|
// --- HTTP/2 下响应可能已被客户端取消,跳过头部设置避免崩溃 ---
|
|
756
726
|
if (!res.headersSent) {
|
|
757
727
|
if (rres.headers) {
|
|
758
|
-
|
|
728
|
+
filterProxyHeaders(rres.headers, res, opt.filter);
|
|
759
729
|
}
|
|
760
730
|
/** --- 上游已压缩则不再压缩,避免双重压缩导致乱码 --- */
|
|
761
731
|
const upstreamEncoded = !!(rres.headers?.['content-encoding']);
|
package/lib/ws.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as kebab from '#kebab/index.js';
|
|
|
9
9
|
import * as lUndici from '#kebab/lib/undici.js';
|
|
10
10
|
import * as lCookie from '#kebab/lib/cookie.js';
|
|
11
11
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
12
|
+
import * as lProxy from '#kebab/lib/undici/proxy.js';
|
|
12
13
|
/** --- 一般用 SIMPLE --- */
|
|
13
14
|
export declare enum EFrameReceiveMode {
|
|
14
15
|
STANDARD = 0,
|
|
@@ -65,6 +66,8 @@ export interface ISocketCloseInfo {
|
|
|
65
66
|
}
|
|
66
67
|
/** --- 正向代理请求的传入参数选项 --- */
|
|
67
68
|
export interface IMproxyOptions {
|
|
69
|
+
/** --- 默认 passthrough 保留已有来源头;request 清理来源头;两者均使用目标 Host --- */
|
|
70
|
+
'proxyMode'?: 'passthrough' | 'request';
|
|
68
71
|
/** --- 秒数 --- */
|
|
69
72
|
'timeout'?: number;
|
|
70
73
|
/** --- 自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host --- */
|
|
@@ -79,7 +82,7 @@ export interface IMproxyOptions {
|
|
|
79
82
|
'masking'?: boolean;
|
|
80
83
|
}
|
|
81
84
|
/** --- 反向代理请求的传入参数选项 --- */
|
|
82
|
-
export interface IRproxyOptions {
|
|
85
|
+
export interface IRproxyOptions extends lProxy.IProxyHeaderOptions {
|
|
83
86
|
/** --- 秒数 --- */
|
|
84
87
|
'timeout'?: number;
|
|
85
88
|
/** --- 自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host --- */
|
package/lib/ws.js
CHANGED
|
@@ -3,8 +3,8 @@ import * as net from 'net';
|
|
|
3
3
|
import WebSocket, { WebSocketServer } from 'ws';
|
|
4
4
|
import * as lCore from '#kebab/lib/core.js';
|
|
5
5
|
import * as lText from '#kebab/lib/text.js';
|
|
6
|
-
import * as lUndici from '#kebab/lib/undici.js';
|
|
7
6
|
import * as lCookie from '#kebab/lib/cookie.js';
|
|
7
|
+
import * as lProxy from '#kebab/lib/undici/proxy.js';
|
|
8
8
|
/** --- 一般用 SIMPLE --- */
|
|
9
9
|
export var EFrameReceiveMode;
|
|
10
10
|
(function (EFrameReceiveMode) {
|
|
@@ -778,7 +778,7 @@ export async function mproxy(ctr, auth, opt = {}) {
|
|
|
778
778
|
return -1;
|
|
779
779
|
}
|
|
780
780
|
opt.headers ??= {};
|
|
781
|
-
const headers =
|
|
781
|
+
const headers = lProxy.getProxyHeaders(req, opt);
|
|
782
782
|
// --- 发起请求 ---
|
|
783
783
|
/** --- 远程端的双向 socket --- */
|
|
784
784
|
const rsocket = await connect(get['url'], {
|
|
@@ -802,7 +802,7 @@ export async function rproxy(ctr, url, opt = {}) {
|
|
|
802
802
|
/** --- 请求端产生的双向 socket --- */
|
|
803
803
|
const socket = ctr.getPrototype('_socket');
|
|
804
804
|
opt.headers ??= {};
|
|
805
|
-
const headers =
|
|
805
|
+
const headers = lProxy.getProxyHeaders(req, opt);
|
|
806
806
|
// --- 发起请求 ---
|
|
807
807
|
/** --- 远程端的双向 socket --- */
|
|
808
808
|
/** --- 目标连接的握手错误 --- */
|
package/package.json
CHANGED
package/sys/child.js
CHANGED
|
@@ -49,8 +49,6 @@ const hbTimer = setInterval(function () {
|
|
|
49
49
|
const certList = new Map();
|
|
50
50
|
/** --- servername → certList mapKey 索引缓存 --- */
|
|
51
51
|
let certHostIndex = {};
|
|
52
|
-
/** --- 默认证书 --- */
|
|
53
|
-
let defaultSc;
|
|
54
52
|
/** --- 最后一次加载证书到内存的时间 --- */
|
|
55
53
|
let certLastLoad = 0;
|
|
56
54
|
/** --- 当前的虚拟主机配置列表 - 读取于 conf/vhost/*.json --- */
|
|
@@ -135,10 +133,6 @@ async function run() {
|
|
|
135
133
|
certHostIndex[servername] = mapKey;
|
|
136
134
|
return;
|
|
137
135
|
}
|
|
138
|
-
if (defaultSc) {
|
|
139
|
-
cb(null, defaultSc);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
136
|
lCore.display(`[CHILD][SNICallback] CERT NOT FOUND for servername: ${servername}`);
|
|
143
137
|
const err = new Error('CERT NOT FOUND');
|
|
144
138
|
cb(err);
|
|
@@ -227,15 +221,14 @@ async function requestHandler(req, res, https) {
|
|
|
227
221
|
// --- 已经开始输出的,需要用户自行处理 ---
|
|
228
222
|
return;
|
|
229
223
|
}
|
|
230
|
-
const content = '<h1>504 Gateway Timeout</h1
|
|
224
|
+
const content = '<h1>504 Gateway Timeout</h1>';
|
|
231
225
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
232
226
|
lCore.writeHead(res, 504);
|
|
233
227
|
res.end(content);
|
|
234
228
|
}
|
|
235
229
|
};
|
|
236
230
|
timer.timer = setTimeout(timer.callback, timer.timeout);
|
|
237
|
-
|
|
238
|
-
res.setHeader('Server', 'Kebab/' + kebab.VER);
|
|
231
|
+
res.setHeader('Server', 'Kebab');
|
|
239
232
|
res.setHeader('expires', 'Mon, 26 Jul 1994 05:00:00 GMT');
|
|
240
233
|
res.setHeader('cache-control', 'no-store');
|
|
241
234
|
// --- 停止中:通知 HTTP/1.1 客户端不要复用此连接(HTTP/2 由 GOAWAY 帧处理) ---
|
|
@@ -284,7 +277,7 @@ async function requestHandler(req, res, https) {
|
|
|
284
277
|
/** --- 'abc' / 'def.json' --- */
|
|
285
278
|
let stat = await lFs.stats(vhost.real + now + item);
|
|
286
279
|
if (!stat) {
|
|
287
|
-
const content = '<h1>404 Not found</h1
|
|
280
|
+
const content = '<h1>404 Not found</h1>';
|
|
288
281
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
289
282
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
290
283
|
lCore.writeHead(res, 404);
|
|
@@ -325,7 +318,7 @@ async function requestHandler(req, res, https) {
|
|
|
325
318
|
'cookie': {},
|
|
326
319
|
'headers': {},
|
|
327
320
|
}, '[CHILD][requestHandler][E0]' + lText.stringifyError(e), '-error');
|
|
328
|
-
const content = '<h1>500 Server Error</h1
|
|
321
|
+
const content = '<h1>500 Server Error</h1>';
|
|
329
322
|
if (!res.headersSent) {
|
|
330
323
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
331
324
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
@@ -368,7 +361,7 @@ async function requestHandler(req, res, https) {
|
|
|
368
361
|
}
|
|
369
362
|
catch (e) {
|
|
370
363
|
lCore.log({}, '[CHILD][requestHandler][E1]' + lText.stringifyError(e), '-error');
|
|
371
|
-
const content = '<h1>500 Server Error</h1
|
|
364
|
+
const content = '<h1>500 Server Error</h1>';
|
|
372
365
|
if (!res.headersSent) {
|
|
373
366
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
374
367
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
@@ -391,7 +384,7 @@ async function requestHandler(req, res, https) {
|
|
|
391
384
|
return;
|
|
392
385
|
}
|
|
393
386
|
}
|
|
394
|
-
const content = '<h1>403 Forbidden</h1
|
|
387
|
+
const content = '<h1>403 Forbidden</h1>';
|
|
395
388
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
396
389
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
397
390
|
lCore.writeHead(res, 403);
|
|
@@ -584,7 +577,6 @@ async function reloadCert() {
|
|
|
584
577
|
}
|
|
585
578
|
}
|
|
586
579
|
}
|
|
587
|
-
defaultSc = certList.size > 0 ? certList.values().next().value.sc : undefined;
|
|
588
580
|
certHostIndex = {};
|
|
589
581
|
}
|
|
590
582
|
/**
|
package/sys/ctr.js
CHANGED
|
@@ -345,7 +345,7 @@ export class Ctr {
|
|
|
345
345
|
lCore.debug(`[CTR][_loadReactPage] ${message}`);
|
|
346
346
|
lCore.log(this, `[CTR][_loadReactPage] ${detail}`, '-error');
|
|
347
347
|
this._httpCode = 500;
|
|
348
|
-
return '<h1>500 Server Error</h1
|
|
348
|
+
return '<h1>500 Server Error</h1>';
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
351
|
* --- 设置校验错误返回值 ---
|
package/sys/route.js
CHANGED
|
@@ -37,7 +37,7 @@ export function clearKebabConfigs() {
|
|
|
37
37
|
* @param res 响应对象
|
|
38
38
|
*/
|
|
39
39
|
function respond500(res) {
|
|
40
|
-
const content = '<h1>500 Server Error</h1
|
|
40
|
+
const content = '<h1>500 Server Error</h1>';
|
|
41
41
|
if (!res.headersSent) {
|
|
42
42
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
43
43
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
@@ -65,9 +65,8 @@ function setInputValue(target, key, value) {
|
|
|
65
65
|
* --- 输出 404 错误响应 ---
|
|
66
66
|
* @param res 响应对象
|
|
67
67
|
* @param config 配置对象(用于检查 #404 路由)
|
|
68
|
-
* @param path 请求路径
|
|
69
68
|
*/
|
|
70
|
-
function respond404(res, config
|
|
69
|
+
function respond404(res, config) {
|
|
71
70
|
if (config?.route?.['#404']) {
|
|
72
71
|
if (!res.headersSent) {
|
|
73
72
|
res.setHeader('location', lText.urlResolve(config.const.urlBase, config.route['#404']));
|
|
@@ -78,7 +77,7 @@ function respond404(res, config, path) {
|
|
|
78
77
|
}
|
|
79
78
|
return;
|
|
80
79
|
}
|
|
81
|
-
const content = '
|
|
80
|
+
const content = '<h1>404 Not found</h1>';
|
|
82
81
|
if (!res.headersSent) {
|
|
83
82
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
84
83
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
@@ -98,7 +97,7 @@ export async function run(data) {
|
|
|
98
97
|
const configContent = await lFs.getContent(data.rootPath + 'kebab.json', 'utf8');
|
|
99
98
|
if (!configContent) {
|
|
100
99
|
if (data.res) {
|
|
101
|
-
const content = '<h1>500
|
|
100
|
+
const content = '<h1>500 Server Error</h1>';
|
|
102
101
|
data.res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
103
102
|
data.res.setHeader('content-length', Buffer.byteLength(content));
|
|
104
103
|
lCore.writeHead(data.res, 500);
|
|
@@ -260,7 +259,7 @@ export async function run(data) {
|
|
|
260
259
|
// --- 若文件名为保留的 middle 将不允许进行 ---
|
|
261
260
|
if (pathLeft.startsWith('middle')) {
|
|
262
261
|
if (data.res) {
|
|
263
|
-
respond404(data.res, config
|
|
262
|
+
respond404(data.res, config);
|
|
264
263
|
}
|
|
265
264
|
else {
|
|
266
265
|
data.socket?.destroy();
|
|
@@ -514,7 +513,7 @@ export async function run(data) {
|
|
|
514
513
|
const filePath = config.const.ctrPath + pathLeft + '.js';
|
|
515
514
|
if (!await lFs.isFile(filePath)) {
|
|
516
515
|
// --- 指定的控制器不存在 ---
|
|
517
|
-
respond404(data.res, config
|
|
516
|
+
respond404(data.res, config);
|
|
518
517
|
return true;
|
|
519
518
|
}
|
|
520
519
|
// --- 加载控制器文件 ---
|
|
@@ -553,11 +552,11 @@ export async function run(data) {
|
|
|
553
552
|
});
|
|
554
553
|
// --- 按实际调用名检查,框架基类及 Object 原型的成员不能作为 action ---
|
|
555
554
|
if (pathRight.startsWith('_') || pathRight in sCtr.Ctr.prototype) {
|
|
556
|
-
respond404(data.res, config
|
|
555
|
+
respond404(data.res, config);
|
|
557
556
|
return true;
|
|
558
557
|
}
|
|
559
558
|
if ((cctr[pathRight] === undefined) || (typeof cctr[pathRight] !== 'function')) {
|
|
560
|
-
respond404(data.res, config
|
|
559
|
+
respond404(data.res, config);
|
|
561
560
|
return true;
|
|
562
561
|
}
|
|
563
562
|
// --- 执行 onLoad 方法 ---
|
|
@@ -694,7 +693,7 @@ export async function run(data) {
|
|
|
694
693
|
lCore.writeHead(data.res, 500);
|
|
695
694
|
}
|
|
696
695
|
if (!data.res.writableEnded) {
|
|
697
|
-
data.res.end('<h1>500 Internal server error</h1
|
|
696
|
+
data.res.end('<h1>500 Internal server error</h1>');
|
|
698
697
|
}
|
|
699
698
|
}
|
|
700
699
|
else {
|
|
@@ -801,7 +800,7 @@ export async function run(data) {
|
|
|
801
800
|
lCore.writeHead(data.res, 500);
|
|
802
801
|
}
|
|
803
802
|
if (!data.res.writableEnded) {
|
|
804
|
-
data.res.end('<h1>500 Internal server error</h1
|
|
803
|
+
data.res.end('<h1>500 Internal server error</h1>');
|
|
805
804
|
}
|
|
806
805
|
}
|
|
807
806
|
await waitCtr(cctr ?? middle);
|
package/www/example/ctr/test.js
CHANGED
|
@@ -2540,10 +2540,10 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2540
2540
|
'authorization': ''
|
|
2541
2541
|
};
|
|
2542
2542
|
echo.push(`origin:<pre>${JSON.stringify(headers, null, 4)}</pre>`);
|
|
2543
|
-
const filtered = lUndici.
|
|
2543
|
+
const filtered = lUndici.filterProxyHeaders(headers, undefined, h => {
|
|
2544
2544
|
return !['x-', 'eo-'].some(i => h.startsWith(i));
|
|
2545
2545
|
});
|
|
2546
|
-
echo.push(`const filtered = lUndici.
|
|
2546
|
+
echo.push(`const filtered = lUndici.filterProxyHeaders(headers);<pre>${JSON.stringify(filtered, null, 4)}</pre>`);
|
|
2547
2547
|
return echo.join('') + this._getEnd();
|
|
2548
2548
|
}
|
|
2549
2549
|
async undiciFetch() {
|