@maiyunnet/kebab 3.1.18 → 3.1.19

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/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "3.1.18";
8
+ export declare const VER = "3.1.19";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  export declare const LIB_PATH: string;
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '3.1.18';
9
+ export const VER = '3.1.19';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/net.d.ts CHANGED
@@ -74,11 +74,12 @@ export declare function resetCookieSession(cookie: Record<string, ICookie>): voi
74
74
  */
75
75
  export declare function getFormData(): fd.FormData;
76
76
  /**
77
- * --- 剔除不代理的 header ---
77
+ * --- 剔除不代理的 header,返回新的 header ---
78
78
  * @param headers 剔除前的 header
79
79
  * @param res 直接设置头部而不返回,可置空
80
+ * @param filter 返回 true 则留下
80
81
  */
81
- export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse): Record<string, string | string[]>;
82
+ export declare function filterProxyHeaders(headers: http.IncomingHttpHeaders | http2.IncomingHttpHeaders | THttpHeaders, res?: http2.Http2ServerResponse | http.ServerResponse, filter?: (h: string) => boolean): Record<string, string | string[]>;
82
83
  /**
83
84
  * --- 正向 mproxy 代理,注意提前处理不要自动处理 post 数据,读取 get 的 url 为实际请求地址 ---
84
85
  * --- get: url, auth ---
@@ -129,6 +130,8 @@ export interface IMproxyOptions {
129
130
  'hosts'?: Record<string, string>;
130
131
  'local'?: string;
131
132
  'headers'?: THttpHeaders;
133
+ /** --- 过滤 header,返回 true 则留下 --- */
134
+ filter?: (h: string) => boolean;
132
135
  /** --- 默认为 default --- */
133
136
  'reuse'?: string;
134
137
  }
@@ -140,6 +143,8 @@ export interface IRproxyOptions {
140
143
  'hosts'?: Record<string, string>;
141
144
  'local'?: string;
142
145
  'headers'?: THttpHeaders;
146
+ /** --- 过滤 header,返回 true 则留下 --- */
147
+ filter?: (h: string) => boolean;
143
148
  /** --- 正向 mproxy 代理,url 如 https://xxx/abc --- */
144
149
  'mproxy'?: {
145
150
  'url': string;
package/lib/net.js CHANGED
@@ -434,11 +434,12 @@ const proxyContinueHeaders = [
434
434
  'transfer-encoding'
435
435
  ];
436
436
  /**
437
- * --- 剔除不代理的 header ---
437
+ * --- 剔除不代理的 header,返回新的 header ---
438
438
  * @param headers 剔除前的 header
439
439
  * @param res 直接设置头部而不返回,可置空
440
+ * @param filter 返回 true 则留下
440
441
  */
441
- export function filterProxyHeaders(headers, res) {
442
+ export function filterProxyHeaders(headers, res, filter) {
442
443
  const heads = {};
443
444
  for (const h in headers) {
444
445
  if (proxyContinueHeaders.includes(h)) {
@@ -451,6 +452,9 @@ export function filterProxyHeaders(headers, res) {
451
452
  if (v === undefined) {
452
453
  continue;
453
454
  }
455
+ if (filter && !filter(h)) {
456
+ continue;
457
+ }
454
458
  if (res) {
455
459
  res.setHeader(h, v);
456
460
  continue;
@@ -482,14 +486,14 @@ export async function mproxy(ctr, auth, opt = {}) {
482
486
  }
483
487
  opt.method = req.method ?? 'GET';
484
488
  opt.headers ??= {};
485
- Object.assign(opt.headers, filterProxyHeaders(req.headers));
489
+ Object.assign(filterProxyHeaders(req.headers, undefined, opt.filter), opt.headers);
486
490
  // --- 发起请求 ---
487
491
  const rres = await request(get['url'], req, opt);
488
492
  if (rres.error) {
489
493
  return -2;
490
494
  }
491
495
  if (rres.headers) {
492
- filterProxyHeaders(rres.headers, res);
496
+ filterProxyHeaders(rres.headers, res, opt.filter);
493
497
  }
494
498
  res.writeHead(rres.headers?.['http-code'] ?? 200);
495
499
  await new Promise((resolve) => {
@@ -539,14 +543,14 @@ export async function rproxy(ctr, route, opt = {}) {
539
543
  const lpath = path.slice(key.length);
540
544
  opt.method = req.method ?? 'GET';
541
545
  opt.headers ??= {};
542
- Object.assign(opt.headers, filterProxyHeaders(req.headers));
546
+ Object.assign(filterProxyHeaders(req.headers, undefined, opt.filter), opt.headers);
543
547
  // --- 发起请求 ---
544
548
  const rres = await request(route[key] + lpath, req, opt);
545
549
  if (rres.error) {
546
550
  return false;
547
551
  }
548
552
  if (rres.headers) {
549
- filterProxyHeaders(rres.headers, res);
553
+ filterProxyHeaders(rres.headers, res, opt.filter);
550
554
  }
551
555
  res.writeHead(rres.headers?.['http-code'] ?? 200);
552
556
  await new Promise((resolve) => {
package/lib/ws.d.ts CHANGED
@@ -49,6 +49,8 @@ export interface IMproxyOptions {
49
49
  'hosts'?: Record<string, string>;
50
50
  'local'?: string;
51
51
  'headers'?: lNet.THttpHeaders;
52
+ /** --- 过滤 header,返回 true 则留下 --- */
53
+ filter?: (h: string) => boolean;
52
54
  /** --- 小帧模式,默认 false --- */
53
55
  'mode'?: EFrameReceiveMode;
54
56
  /** --- 加密模式,默认 true --- */
@@ -61,6 +63,8 @@ export interface IRproxyOptions {
61
63
  'hosts'?: Record<string, string>;
62
64
  'local'?: string;
63
65
  'headers'?: lNet.THttpHeaders;
66
+ /** --- 过滤 header,返回 true 则留下 --- */
67
+ filter?: (h: string) => boolean;
64
68
  /** --- 小帧模式,默认 false --- */
65
69
  'mode'?: EFrameReceiveMode;
66
70
  /** --- 加密模式,默认 true --- */
package/lib/ws.js CHANGED
@@ -366,7 +366,7 @@ export async function mproxy(ctr, auth, opt = {}) {
366
366
  return -1;
367
367
  }
368
368
  opt.headers ??= {};
369
- Object.assign(opt.headers, lNet.filterProxyHeaders(req.headers));
369
+ Object.assign(lNet.filterProxyHeaders(req.headers, undefined, opt.filter), opt.headers);
370
370
  // --- 发起请求 ---
371
371
  /** --- 远程端的双向 socket --- */
372
372
  const rsocket = await connect(get['url'], opt);
@@ -387,7 +387,7 @@ export async function rproxy(ctr, url, opt = {}) {
387
387
  /** --- 请求端产生的双向 socket --- */
388
388
  const socket = ctr.getPrototype('_socket');
389
389
  opt.headers ??= {};
390
- Object.assign(opt.headers, lNet.filterProxyHeaders(req.headers));
390
+ Object.assign(lNet.filterProxyHeaders(req.headers, undefined, opt.filter), opt.headers);
391
391
  // --- 发起请求 ---
392
392
  /** --- 远程端的双向 socket --- */
393
393
  const rsocket = await connect(url, opt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "3.1.18",
3
+ "version": "3.1.19",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [