@maiyunnet/kebab 9.24.0 → 9.25.1
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/request.d.ts +2 -0
- package/abox/request.js +13 -0
- package/doc/kebab-rag.md +58 -55
- package/index.d.ts +10 -6
- package/index.js +1 -1
- package/package.json +1 -1
- package/sys/child.js +0 -6
- package/sys/route.js +15 -5
- package/www/example/ctr/test.d.ts +3 -0
- package/www/example/ctr/test.js +66 -37
- package/www/example/ws/handler.js +7 -1
- package/www/example/ws/mproxy.js +5 -1
- package/www/example/ws/rproxy.js +7 -1
package/abox/request.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function getPublicProtocol(req, fallback) {
|
|
2
|
+
if (fallback !== 'http:' && fallback !== 'https:') {
|
|
3
|
+
return fallback;
|
|
4
|
+
}
|
|
5
|
+
const xForwardedProto = req.headers['x-forwarded-proto'];
|
|
6
|
+
if (typeof xForwardedProto === 'string' && xForwardedProto.length <= 4096) {
|
|
7
|
+
const first = xForwardedProto.split(',', 1)[0].trim();
|
|
8
|
+
if (/^(?:http|https)$/iu.test(first)) {
|
|
9
|
+
return first.toLowerCase() + ':';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
package/doc/kebab-rag.md
CHANGED
|
@@ -527,7 +527,7 @@ Defined in: [index.ts:183](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
527
527
|
|
|
528
528
|
> **ctrPath**: `string`
|
|
529
529
|
|
|
530
|
-
Defined in: [index.ts:
|
|
530
|
+
Defined in: [index.ts:219](https://github.com/maiyunnet/kebab/blob/master/index.ts#L219)
|
|
531
531
|
|
|
532
532
|
***
|
|
533
533
|
|
|
@@ -535,7 +535,7 @@ Defined in: [index.ts:215](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
535
535
|
|
|
536
536
|
> **dataPath**: `string`
|
|
537
537
|
|
|
538
|
-
Defined in: [index.ts:
|
|
538
|
+
Defined in: [index.ts:221](https://github.com/maiyunnet/kebab/blob/master/index.ts#L221)
|
|
539
539
|
|
|
540
540
|
***
|
|
541
541
|
|
|
@@ -543,9 +543,9 @@ Defined in: [index.ts:217](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
543
543
|
|
|
544
544
|
> **host**: `string`
|
|
545
545
|
|
|
546
|
-
Defined in: [index.ts:
|
|
546
|
+
Defined in: [index.ts:201](https://github.com/maiyunnet/kebab/blob/master/index.ts#L201)
|
|
547
547
|
|
|
548
|
-
|
|
548
|
+
请求头中的主机地址,如 example.com、example.com:8443 或 [::1]:8080;不额外补端口
|
|
549
549
|
|
|
550
550
|
***
|
|
551
551
|
|
|
@@ -553,9 +553,9 @@ Defined in: [index.ts:200](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
553
553
|
|
|
554
554
|
> **hostCanonical**: `string`
|
|
555
555
|
|
|
556
|
-
Defined in: [index.ts:
|
|
556
|
+
Defined in: [index.ts:207](https://github.com/maiyunnet/kebab/blob/master/index.ts#L207)
|
|
557
557
|
|
|
558
|
-
|
|
558
|
+
用于生成网址的主机地址,仅省略 HTTPS 的 443 和 HTTP 的 80 端口,如 example.com:443 → example.com;保留其他端口和 IPv6 方括号
|
|
559
559
|
|
|
560
560
|
***
|
|
561
561
|
|
|
@@ -563,9 +563,9 @@ Defined in: [index.ts:206](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
563
563
|
|
|
564
564
|
> **hostname**: `string`
|
|
565
565
|
|
|
566
|
-
Defined in: [index.ts:
|
|
566
|
+
Defined in: [index.ts:203](https://github.com/maiyunnet/kebab/blob/master/index.ts#L203)
|
|
567
567
|
|
|
568
|
-
|
|
568
|
+
主机名,如 example.com 或 ::1,不含端口或 IPv6 方括号
|
|
569
569
|
|
|
570
570
|
***
|
|
571
571
|
|
|
@@ -573,9 +573,9 @@ Defined in: [index.ts:202](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
573
573
|
|
|
574
574
|
> **hostport**: `number`
|
|
575
575
|
|
|
576
|
-
Defined in: [index.ts:
|
|
576
|
+
Defined in: [index.ts:205](https://github.com/maiyunnet/kebab/blob/master/index.ts#L205)
|
|
577
577
|
|
|
578
|
-
|
|
578
|
+
请求地址中的端口,如 8443;未指定时 HTTPS 为 443、HTTP 为 80,不取本机监听端口
|
|
579
579
|
|
|
580
580
|
***
|
|
581
581
|
|
|
@@ -583,7 +583,9 @@ Defined in: [index.ts:204](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
583
583
|
|
|
584
584
|
> **https**: `boolean`
|
|
585
585
|
|
|
586
|
-
Defined in: [index.ts:
|
|
586
|
+
Defined in: [index.ts:199](https://github.com/maiyunnet/kebab/blob/master/index.ts#L199)
|
|
587
|
+
|
|
588
|
+
请求到达 Kebab 时是否使用 HTTPS;通过 HTTP 回源时为 false
|
|
587
589
|
|
|
588
590
|
***
|
|
589
591
|
|
|
@@ -607,7 +609,7 @@ Defined in: [index.ts:195](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
607
609
|
|
|
608
610
|
> **modPath**: `string`
|
|
609
611
|
|
|
610
|
-
Defined in: [index.ts:
|
|
612
|
+
Defined in: [index.ts:218](https://github.com/maiyunnet/kebab/blob/master/index.ts#L218)
|
|
611
613
|
|
|
612
614
|
***
|
|
613
615
|
|
|
@@ -645,7 +647,7 @@ Defined in: [index.ts:189](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
645
647
|
|
|
646
648
|
> **rootPath**: `string`
|
|
647
649
|
|
|
648
|
-
Defined in: [index.ts:
|
|
650
|
+
Defined in: [index.ts:217](https://github.com/maiyunnet/kebab/blob/master/index.ts#L217)
|
|
649
651
|
|
|
650
652
|
***
|
|
651
653
|
|
|
@@ -669,7 +671,7 @@ Defined in: [index.ts:190](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
669
671
|
|
|
670
672
|
> **uri**: [`IUrlParse`](IUrlParse.md)
|
|
671
673
|
|
|
672
|
-
Defined in: [index.ts:
|
|
674
|
+
Defined in: [index.ts:213](https://github.com/maiyunnet/kebab/blob/master/index.ts#L213)
|
|
673
675
|
|
|
674
676
|
***
|
|
675
677
|
|
|
@@ -677,7 +679,7 @@ Defined in: [index.ts:209](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
677
679
|
|
|
678
680
|
> **urlBase**: `string`
|
|
679
681
|
|
|
680
|
-
Defined in: [index.ts:
|
|
682
|
+
Defined in: [index.ts:226](https://github.com/maiyunnet/kebab/blob/master/index.ts#L226)
|
|
681
683
|
|
|
682
684
|
***
|
|
683
685
|
|
|
@@ -685,7 +687,7 @@ Defined in: [index.ts:222](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
685
687
|
|
|
686
688
|
> **urlFull**: `string`
|
|
687
689
|
|
|
688
|
-
Defined in: [index.ts:
|
|
690
|
+
Defined in: [index.ts:228](https://github.com/maiyunnet/kebab/blob/master/index.ts#L228)
|
|
689
691
|
|
|
690
692
|
***
|
|
691
693
|
|
|
@@ -693,9 +695,10 @@ Defined in: [index.ts:224](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
693
695
|
|
|
694
696
|
> **urlOrigin**: `string`
|
|
695
697
|
|
|
696
|
-
Defined in: [index.ts:
|
|
698
|
+
Defined in: [index.ts:212](https://github.com/maiyunnet/kebab/blob/master/index.ts#L212)
|
|
697
699
|
|
|
698
|
-
|
|
700
|
+
网址的协议与 hostCanonical,如 https://example.com:8443
|
|
701
|
+
协议可取自 X-Forwarded-Proto,无有效值时使用实际连接协议;不能用它判断实际 TLS 状态。
|
|
699
702
|
|
|
700
703
|
***
|
|
701
704
|
|
|
@@ -703,7 +706,7 @@ Defined in: [index.ts:208](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
703
706
|
|
|
704
707
|
> **urlStc**: `string`
|
|
705
708
|
|
|
706
|
-
Defined in: [index.ts:
|
|
709
|
+
Defined in: [index.ts:227](https://github.com/maiyunnet/kebab/blob/master/index.ts#L227)
|
|
707
710
|
|
|
708
711
|
***
|
|
709
712
|
|
|
@@ -711,7 +714,7 @@ Defined in: [index.ts:223](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
711
714
|
|
|
712
715
|
> **urlStcFull**: `string`
|
|
713
716
|
|
|
714
|
-
Defined in: [index.ts:
|
|
717
|
+
Defined in: [index.ts:229](https://github.com/maiyunnet/kebab/blob/master/index.ts#L229)
|
|
715
718
|
|
|
716
719
|
***
|
|
717
720
|
|
|
@@ -719,7 +722,7 @@ Defined in: [index.ts:225](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
719
722
|
|
|
720
723
|
> **viewPath**: `string`
|
|
721
724
|
|
|
722
|
-
Defined in: [index.ts:
|
|
725
|
+
Defined in: [index.ts:220](https://github.com/maiyunnet/kebab/blob/master/index.ts#L220)
|
|
723
726
|
|
|
724
727
|
***
|
|
725
728
|
|
|
@@ -735,7 +738,7 @@ Defined in: [index.ts:196](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
735
738
|
|
|
736
739
|
> **wsPath**: `string`
|
|
737
740
|
|
|
738
|
-
Defined in: [index.ts:
|
|
741
|
+
Defined in: [index.ts:222](https://github.com/maiyunnet/kebab/blob/master/index.ts#L222)
|
|
739
742
|
|
|
740
743
|
index/interfaces/IConfigDb.md
|
|
741
744
|
---
|
|
@@ -1295,7 +1298,7 @@ index/interfaces/IPostFile.md
|
|
|
1295
1298
|
|
|
1296
1299
|
# Interface: IPostFile
|
|
1297
1300
|
|
|
1298
|
-
Defined in: [index.ts:
|
|
1301
|
+
Defined in: [index.ts:241](https://github.com/maiyunnet/kebab/blob/master/index.ts#L241)
|
|
1299
1302
|
|
|
1300
1303
|
上传的文件信息对象
|
|
1301
1304
|
|
|
@@ -1305,7 +1308,7 @@ Defined in: [index.ts:237](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
1305
1308
|
|
|
1306
1309
|
> `readonly` **name**: `string`
|
|
1307
1310
|
|
|
1308
|
-
Defined in: [index.ts:
|
|
1311
|
+
Defined in: [index.ts:242](https://github.com/maiyunnet/kebab/blob/master/index.ts#L242)
|
|
1309
1312
|
|
|
1310
1313
|
***
|
|
1311
1314
|
|
|
@@ -1313,7 +1316,7 @@ Defined in: [index.ts:238](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
1313
1316
|
|
|
1314
1317
|
> `readonly` **origin**: `string`
|
|
1315
1318
|
|
|
1316
|
-
Defined in: [index.ts:
|
|
1319
|
+
Defined in: [index.ts:243](https://github.com/maiyunnet/kebab/blob/master/index.ts#L243)
|
|
1317
1320
|
|
|
1318
1321
|
***
|
|
1319
1322
|
|
|
@@ -1321,7 +1324,7 @@ Defined in: [index.ts:239](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
1321
1324
|
|
|
1322
1325
|
> `readonly` **path**: `string`
|
|
1323
1326
|
|
|
1324
|
-
Defined in: [index.ts:
|
|
1327
|
+
Defined in: [index.ts:245](https://github.com/maiyunnet/kebab/blob/master/index.ts#L245)
|
|
1325
1328
|
|
|
1326
1329
|
***
|
|
1327
1330
|
|
|
@@ -1329,7 +1332,7 @@ Defined in: [index.ts:241](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
1329
1332
|
|
|
1330
1333
|
> `readonly` **size**: `number`
|
|
1331
1334
|
|
|
1332
|
-
Defined in: [index.ts:
|
|
1335
|
+
Defined in: [index.ts:244](https://github.com/maiyunnet/kebab/blob/master/index.ts#L244)
|
|
1333
1336
|
|
|
1334
1337
|
index/interfaces/IUrlParse.md
|
|
1335
1338
|
---
|
|
@@ -1443,7 +1446,7 @@ index/interfaces/IVhost.md
|
|
|
1443
1446
|
|
|
1444
1447
|
# Interface: IVhost
|
|
1445
1448
|
|
|
1446
|
-
Defined in: [index.ts:
|
|
1449
|
+
Defined in: [index.ts:233](https://github.com/maiyunnet/kebab/blob/master/index.ts#L233)
|
|
1447
1450
|
|
|
1448
1451
|
虚拟机配置对象
|
|
1449
1452
|
|
|
@@ -1453,7 +1456,7 @@ Defined in: [index.ts:229](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
1453
1456
|
|
|
1454
1457
|
> `readonly` **domains**: `string`[]
|
|
1455
1458
|
|
|
1456
|
-
Defined in: [index.ts:
|
|
1459
|
+
Defined in: [index.ts:235](https://github.com/maiyunnet/kebab/blob/master/index.ts#L235)
|
|
1457
1460
|
|
|
1458
1461
|
***
|
|
1459
1462
|
|
|
@@ -1461,7 +1464,7 @@ Defined in: [index.ts:231](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
1461
1464
|
|
|
1462
1465
|
> `readonly` `optional` **name?**: `string`
|
|
1463
1466
|
|
|
1464
|
-
Defined in: [index.ts:
|
|
1467
|
+
Defined in: [index.ts:234](https://github.com/maiyunnet/kebab/blob/master/index.ts#L234)
|
|
1465
1468
|
|
|
1466
1469
|
***
|
|
1467
1470
|
|
|
@@ -1469,7 +1472,7 @@ Defined in: [index.ts:230](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
1469
1472
|
|
|
1470
1473
|
> `readonly` `optional` **remark?**: `string`
|
|
1471
1474
|
|
|
1472
|
-
Defined in: [index.ts:
|
|
1475
|
+
Defined in: [index.ts:237](https://github.com/maiyunnet/kebab/blob/master/index.ts#L237)
|
|
1473
1476
|
|
|
1474
1477
|
***
|
|
1475
1478
|
|
|
@@ -1477,7 +1480,7 @@ Defined in: [index.ts:233](https://github.com/maiyunnet/kebab/blob/master/index.
|
|
|
1477
1480
|
|
|
1478
1481
|
> `readonly` **root**: `string`
|
|
1479
1482
|
|
|
1480
|
-
Defined in: [index.ts:
|
|
1483
|
+
Defined in: [index.ts:236](https://github.com/maiyunnet/kebab/blob/master/index.ts#L236)
|
|
1481
1484
|
|
|
1482
1485
|
index.md
|
|
1483
1486
|
---
|
|
@@ -1756,7 +1759,7 @@ index/variables/VER.md
|
|
|
1756
1759
|
|
|
1757
1760
|
# Variable: VER
|
|
1758
1761
|
|
|
1759
|
-
> `const` **VER**: `"9.
|
|
1762
|
+
> `const` **VER**: `"9.25.1"` = `'9.25.1'`
|
|
1760
1763
|
|
|
1761
1764
|
Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
|
|
1762
1765
|
|
|
@@ -138172,7 +138175,7 @@ sys/route/functions/clearKebabConfigs.md
|
|
|
138172
138175
|
|
|
138173
138176
|
> **clearKebabConfigs**(): `void`
|
|
138174
138177
|
|
|
138175
|
-
Defined in: [sys/route.ts:
|
|
138178
|
+
Defined in: [sys/route.ts:40](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L40)
|
|
138176
138179
|
|
|
138177
138180
|
清空缓存的项目配置,下次请求时重新读取文件
|
|
138178
138181
|
|
|
@@ -138193,7 +138196,7 @@ sys/route/functions/getFormData.md
|
|
|
138193
138196
|
|
|
138194
138197
|
> **getFormData**(`req`, `events?`, `limits?`): `Promise`\<`false` \| \{ `files`: `Record`\<`string`, [`IPostFile`](../../../index/interfaces/IPostFile.md) \| [`IPostFile`](../../../index/interfaces/IPostFile.md)[]\>; `post`: `Record`\<`string`, [`Json`](../../../index/type-aliases/Json.md)\>; \}\>
|
|
138195
138198
|
|
|
138196
|
-
Defined in: [sys/route.ts:
|
|
138199
|
+
Defined in: [sys/route.ts:1105](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1105)
|
|
138197
138200
|
|
|
138198
138201
|
获取 formdata 的 post
|
|
138199
138202
|
|
|
@@ -138236,7 +138239,7 @@ sys/route/functions/getPost.md
|
|
|
138236
138239
|
|
|
138237
138240
|
> **getPost**(`req`): `Promise`\<`false` \| \{ `input`: `string`; `post`: `Record`\<`string`, `any`\>; `raw`: `Record`\<`string`, `any`\>; \}\>
|
|
138238
138241
|
|
|
138239
|
-
Defined in: [sys/route.ts:
|
|
138242
|
+
Defined in: [sys/route.ts:940](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L940)
|
|
138240
138243
|
|
|
138241
138244
|
获取 post 对象(通常已自动获取),如果是文件上传(formdata)的情况则不获取
|
|
138242
138245
|
|
|
@@ -138267,7 +138270,7 @@ sys/route/functions/run.md
|
|
|
138267
138270
|
|
|
138268
138271
|
> **run**(`data`): `Promise`\<`boolean`\>
|
|
138269
138272
|
|
|
138270
|
-
Defined in: [sys/route.ts:
|
|
138273
|
+
Defined in: [sys/route.ts:111](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L111)
|
|
138271
138274
|
|
|
138272
138275
|
若为动态路径则执行此函数,此函数不进行判断 kebab.json 是否存在
|
|
138273
138276
|
|
|
@@ -138354,7 +138357,7 @@ sys/route/functions/unlinkUploadFiles.md
|
|
|
138354
138357
|
|
|
138355
138358
|
> **unlinkUploadFiles**(`cctr`): `Promise`\<`void`\>
|
|
138356
138359
|
|
|
138357
|
-
Defined in: [sys/route.ts:
|
|
138360
|
+
Defined in: [sys/route.ts:898](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L898)
|
|
138358
138361
|
|
|
138359
138362
|
删除本次请求所有已上传的临时文件
|
|
138360
138363
|
|
|
@@ -138383,7 +138386,7 @@ sys/route/functions/waitCtr.md
|
|
|
138383
138386
|
|
|
138384
138387
|
> **waitCtr**(`cctr`): `Promise`\<`void`\>
|
|
138385
138388
|
|
|
138386
|
-
Defined in: [sys/route.ts:
|
|
138389
|
+
Defined in: [sys/route.ts:918](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L918)
|
|
138387
138390
|
|
|
138388
138391
|
等待异步任务结束,并删除临时文件,如果结束后还有事务没关闭,则会在本函数中打印控制台并且写入 log 文件
|
|
138389
138392
|
此时其实已经给客户端返回了,此处等待不消耗客户端的等待时间
|
|
@@ -138437,7 +138440,7 @@ sys/route/interfaces/IFormDataError.md
|
|
|
138437
138440
|
|
|
138438
138441
|
# Interface: IFormDataError
|
|
138439
138442
|
|
|
138440
|
-
Defined in: [sys/route.ts:
|
|
138443
|
+
Defined in: [sys/route.ts:1060](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1060)
|
|
138441
138444
|
|
|
138442
138445
|
解析上传数据时的失败原因,只提供错误码和限制值,不带临时路径或异常对象
|
|
138443
138446
|
|
|
@@ -138447,7 +138450,7 @@ Defined in: [sys/route.ts:1047](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138447
138450
|
|
|
138448
138451
|
> **code**: `"INVALID_BOUNDARY"` \| `"FILE_TOO_LARGE"` \| `"TOTAL_TOO_LARGE"` \| `"FIELD_TOO_LARGE"` \| `"HEADER_TOO_LARGE"` \| `"TOO_MANY_PARTS"` \| `"FILE_TYPE"` \| `"TIMEOUT"` \| `"TEMP_FILE_ERROR"` \| `"REQUEST_ERROR"` \| `"REQUEST_ABORTED"`
|
|
138449
138452
|
|
|
138450
|
-
Defined in: [sys/route.ts:
|
|
138453
|
+
Defined in: [sys/route.ts:1061](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1061)
|
|
138451
138454
|
|
|
138452
138455
|
***
|
|
138453
138456
|
|
|
@@ -138455,7 +138458,7 @@ Defined in: [sys/route.ts:1048](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138455
138458
|
|
|
138456
138459
|
> `optional` **limit?**: `number`
|
|
138457
138460
|
|
|
138458
|
-
Defined in: [sys/route.ts:
|
|
138461
|
+
Defined in: [sys/route.ts:1065](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1065)
|
|
138459
138462
|
|
|
138460
138463
|
超出的限制值:大小用字节,超时用毫秒,字段和文件数量用个
|
|
138461
138464
|
|
|
@@ -138470,7 +138473,7 @@ sys/route/interfaces/IFormDataEvents.md
|
|
|
138470
138473
|
|
|
138471
138474
|
# Interface: IFormDataEvents
|
|
138472
138475
|
|
|
138473
|
-
Defined in: [sys/route.ts:
|
|
138476
|
+
Defined in: [sys/route.ts:1069](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1069)
|
|
138474
138477
|
|
|
138475
138478
|
multipart 文件处理及失败通知
|
|
138476
138479
|
|
|
@@ -138480,7 +138483,7 @@ multipart 文件处理及失败通知
|
|
|
138480
138483
|
|
|
138481
138484
|
> `optional` **onerror?**: (`error`) => `void`
|
|
138482
138485
|
|
|
138483
|
-
Defined in: [sys/route.ts:
|
|
138486
|
+
Defined in: [sys/route.ts:1077](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1077)
|
|
138484
138487
|
|
|
138485
138488
|
首次失败时调用一次,getFormData 返回 false;若连接已断开,可能无法回复客户端
|
|
138486
138489
|
|
|
@@ -138500,7 +138503,7 @@ Defined in: [sys/route.ts:1064](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138500
138503
|
|
|
138501
138504
|
> `optional` **onfiledata?**: (`chunk`) => `void`
|
|
138502
138505
|
|
|
138503
|
-
Defined in: [sys/route.ts:
|
|
138506
|
+
Defined in: [sys/route.ts:1073](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1073)
|
|
138504
138507
|
|
|
138505
138508
|
文件上传时触发,仅 start 返回 true 时触发
|
|
138506
138509
|
|
|
@@ -138520,7 +138523,7 @@ Defined in: [sys/route.ts:1060](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138520
138523
|
|
|
138521
138524
|
> `optional` **onfileend?**: () => `void`
|
|
138522
138525
|
|
|
138523
|
-
Defined in: [sys/route.ts:
|
|
138526
|
+
Defined in: [sys/route.ts:1075](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1075)
|
|
138524
138527
|
|
|
138525
138528
|
文件上传结束时触发,仅 start 返回 true 时触发
|
|
138526
138529
|
|
|
@@ -138534,7 +138537,7 @@ Defined in: [sys/route.ts:1062](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138534
138537
|
|
|
138535
138538
|
> `optional` **onfilestart?**: (`name`) => `boolean` \| `undefined`
|
|
138536
138539
|
|
|
138537
|
-
Defined in: [sys/route.ts:
|
|
138540
|
+
Defined in: [sys/route.ts:1071](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1071)
|
|
138538
138541
|
|
|
138539
138542
|
文件开始上传时触发,返回 true 则跳过该文件的保存
|
|
138540
138543
|
|
|
@@ -138559,7 +138562,7 @@ sys/route/interfaces/IFormDataLimits.md
|
|
|
138559
138562
|
|
|
138560
138563
|
# Interface: IFormDataLimits
|
|
138561
138564
|
|
|
138562
|
-
Defined in: [sys/route.ts:
|
|
138565
|
+
Defined in: [sys/route.ts:1081](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1081)
|
|
138563
138566
|
|
|
138564
138567
|
multipart 上传限制
|
|
138565
138568
|
|
|
@@ -138569,7 +138572,7 @@ multipart 上传限制
|
|
|
138569
138572
|
|
|
138570
138573
|
> `optional` **allowedExts?**: `string`[]
|
|
138571
138574
|
|
|
138572
|
-
Defined in: [sys/route.ts:
|
|
138575
|
+
Defined in: [sys/route.ts:1085](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1085)
|
|
138573
138576
|
|
|
138574
138577
|
允许的文件扩展名(含点号),如 ['.jpg', '.png', '.pdf']
|
|
138575
138578
|
|
|
@@ -138579,7 +138582,7 @@ Defined in: [sys/route.ts:1072](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138579
138582
|
|
|
138580
138583
|
> `optional` **maxFieldSize?**: `number`
|
|
138581
138584
|
|
|
138582
|
-
Defined in: [sys/route.ts:
|
|
138585
|
+
Defined in: [sys/route.ts:1087](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1087)
|
|
138583
138586
|
|
|
138584
138587
|
单个字段(非文件)最大字节数,默认 1 MB
|
|
138585
138588
|
|
|
@@ -138589,7 +138592,7 @@ Defined in: [sys/route.ts:1074](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138589
138592
|
|
|
138590
138593
|
> `optional` **maxFileSize?**: `number`
|
|
138591
138594
|
|
|
138592
|
-
Defined in: [sys/route.ts:
|
|
138595
|
+
Defined in: [sys/route.ts:1083](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1083)
|
|
138593
138596
|
|
|
138594
138597
|
单个文件最大字节数
|
|
138595
138598
|
|
|
@@ -138599,7 +138602,7 @@ Defined in: [sys/route.ts:1070](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138599
138602
|
|
|
138600
138603
|
> `optional` **maxHeaderSize?**: `number`
|
|
138601
138604
|
|
|
138602
|
-
Defined in: [sys/route.ts:
|
|
138605
|
+
Defined in: [sys/route.ts:1091](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1091)
|
|
138603
138606
|
|
|
138604
138607
|
每个字段或文件的 multipart 头部最多多少字节,默认 16 KB
|
|
138605
138608
|
|
|
@@ -138609,7 +138612,7 @@ Defined in: [sys/route.ts:1078](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138609
138612
|
|
|
138610
138613
|
> `optional` **maxParts?**: `number`
|
|
138611
138614
|
|
|
138612
|
-
Defined in: [sys/route.ts:
|
|
138615
|
+
Defined in: [sys/route.ts:1093](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1093)
|
|
138613
138616
|
|
|
138614
138617
|
multipart 字段与文件总数量,默认 1000
|
|
138615
138618
|
|
|
@@ -138619,7 +138622,7 @@ multipart 字段与文件总数量,默认 1000
|
|
|
138619
138622
|
|
|
138620
138623
|
> `optional` **maxTotalSize?**: `number`
|
|
138621
138624
|
|
|
138622
|
-
Defined in: [sys/route.ts:
|
|
138625
|
+
Defined in: [sys/route.ts:1089](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1089)
|
|
138623
138626
|
|
|
138624
138627
|
整体请求最大字节数,不设置或设为 0 则不限制
|
|
138625
138628
|
|
|
@@ -138629,6 +138632,6 @@ Defined in: [sys/route.ts:1076](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138629
138632
|
|
|
138630
138633
|
> `optional` **timeout?**: `number`
|
|
138631
138634
|
|
|
138632
|
-
Defined in: [sys/route.ts:
|
|
138635
|
+
Defined in: [sys/route.ts:1095](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1095)
|
|
138633
138636
|
|
|
138634
138637
|
整体请求超时时间(毫秒),默认 5 分钟,设为 0 禁用超时
|
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
6
6
|
*/
|
|
7
7
|
/** --- 当前系统版本号 --- */
|
|
8
|
-
export declare const VER = "9.
|
|
8
|
+
export declare const VER = "9.25.1";
|
|
9
9
|
/** --- 框架根目录,以 / 结尾 --- */
|
|
10
10
|
export declare const ROOT_PATH: string;
|
|
11
11
|
/** --- 框架的 LIB,以 / 结尾 --- */
|
|
@@ -155,16 +155,20 @@ export interface IConfigConst {
|
|
|
155
155
|
'mobile': boolean;
|
|
156
156
|
'wechat': boolean;
|
|
157
157
|
'miniprogram': '' | 'wechat';
|
|
158
|
+
/** --- 请求到达 Kebab 时是否使用 HTTPS;通过 HTTP 回源时为 false --- */
|
|
158
159
|
'https': boolean;
|
|
159
|
-
/** ---
|
|
160
|
+
/** --- 请求头中的主机地址,如 example.com、example.com:8443 或 [::1]:8080;不额外补端口 --- */
|
|
160
161
|
'host': string;
|
|
161
|
-
/** ---
|
|
162
|
+
/** --- 主机名,如 example.com 或 ::1,不含端口或 IPv6 方括号 --- */
|
|
162
163
|
'hostname': string;
|
|
163
|
-
/** ---
|
|
164
|
+
/** --- 请求地址中的端口,如 8443;未指定时 HTTPS 为 443、HTTP 为 80,不取本机监听端口 --- */
|
|
164
165
|
'hostport': number;
|
|
165
|
-
/** ---
|
|
166
|
+
/** --- 用于生成网址的主机地址,仅省略 HTTPS 的 443 和 HTTP 的 80 端口,如 example.com:443 → example.com;保留其他端口和 IPv6 方括号 --- */
|
|
166
167
|
'hostCanonical': string;
|
|
167
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* --- 网址的协议与 hostCanonical,如 https://example.com:8443 ---
|
|
170
|
+
* 协议可取自 X-Forwarded-Proto,无有效值时使用实际连接协议;不能用它判断实际 TLS 状态。
|
|
171
|
+
*/
|
|
168
172
|
'urlOrigin': string;
|
|
169
173
|
'uri': IUrlParse;
|
|
170
174
|
'rootPath': string;
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '9.
|
|
9
|
+
export const VER = '9.25.1';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/package.json
CHANGED
package/sys/child.js
CHANGED
|
@@ -235,12 +235,6 @@ async function requestHandler(req, res, https) {
|
|
|
235
235
|
res.end('403 Forbidden');
|
|
236
236
|
return;
|
|
237
237
|
}
|
|
238
|
-
const hostInfo = lText.parseHost(host);
|
|
239
|
-
host = hostInfo.hostname;
|
|
240
|
-
if (lText.isIPv6(host)) {
|
|
241
|
-
host = `[${host}]`;
|
|
242
|
-
}
|
|
243
|
-
host = host + ':' + (req.socket.localPort ?? (https ? '443' : '80'));
|
|
244
238
|
const uri = lText.parseUrl(`http${https ? 's' : ''}://${host}${req.url ?? ''}`);
|
|
245
239
|
/** --- 当前的 vhost 配置文件 --- */
|
|
246
240
|
const vhost = await getVhostByHostname(uri.hostname ?? '');
|
package/sys/route.js
CHANGED
|
@@ -16,6 +16,14 @@ import * as lWs from '#kebab/lib/ws.js';
|
|
|
16
16
|
import * as lLang from '#kebab/lib/lang.js';
|
|
17
17
|
import * as sCtr from './ctr.js';
|
|
18
18
|
import * as kebab from '#kebab/index.js';
|
|
19
|
+
import { getPublicProtocol as getPublicProtocolImpl } from '#kebab/abox/request.js';
|
|
20
|
+
/**
|
|
21
|
+
* --- 只用于推导公开 URL;不改变真实 TLS 状态,也不验证转发头来源 ---
|
|
22
|
+
* @param req HTTP 或 HTTP/2 请求
|
|
23
|
+
* @param fallback 实际连接协议;X-Forwarded-Proto 首项不是有效的 http/https 时使用
|
|
24
|
+
* @returns 对外 URL 协议;ws/wss 保持原值
|
|
25
|
+
*/
|
|
26
|
+
const getPublicProtocol = getPublicProtocolImpl;
|
|
19
27
|
/** --- 已加载的项目配置,按 kebab.json 的文件路径缓存,已补齐全局默认值 --- */
|
|
20
28
|
let kebabConfigs = {};
|
|
21
29
|
/**
|
|
@@ -133,16 +141,18 @@ export async function run(data) {
|
|
|
133
141
|
}
|
|
134
142
|
// --- 复制一份 set,后面改资源地址时就不会改动原来的配置 ---
|
|
135
143
|
config.set = { ...config.set };
|
|
136
|
-
/** ---
|
|
144
|
+
/** --- 公开 URL 协议仅用于生成地址,不改变原请求协议和 TLS 状态 --- */
|
|
145
|
+
const publicProtocol = getPublicProtocol(data.req, data.uri.protocol ?? '');
|
|
146
|
+
/** --- host 不带公开协议的默认端口(HTTP 的 80、HTTPS 的 443)--- */
|
|
137
147
|
let hostCanonical = data.uri.host ?? '';
|
|
138
|
-
if (
|
|
148
|
+
if (publicProtocol === 'https:' && Number(data.uri.port) === 443) {
|
|
139
149
|
hostCanonical = lText.parseHost(hostCanonical).rawHostname;
|
|
140
150
|
}
|
|
141
|
-
else if (
|
|
151
|
+
else if (publicProtocol === 'http:' && Number(data.uri.port) === 80) {
|
|
142
152
|
hostCanonical = lText.parseHost(hostCanonical).rawHostname;
|
|
143
153
|
}
|
|
144
|
-
/** ---
|
|
145
|
-
const urlOrigin = `${
|
|
154
|
+
/** --- 网址开头的公开协议和 host,如 https://example.com --- */
|
|
155
|
+
const urlOrigin = `${publicProtocol}//${hostCanonical}`;
|
|
146
156
|
config.const = {
|
|
147
157
|
'path': data.path,
|
|
148
158
|
'qs': data.uri.query ?? '',
|
|
@@ -2,7 +2,10 @@ import * as fs from 'fs';
|
|
|
2
2
|
import * as kebab from '#kebab/index.js';
|
|
3
3
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
4
4
|
export default class extends sCtr.Ctr {
|
|
5
|
+
/** --- 示例自调用的地址,使用当前连接的协议和监听端口 --- */
|
|
5
6
|
private _internalUrl;
|
|
7
|
+
/** --- 将示例域名解析到当前服务,避免绕回公网或容器外部 --- */
|
|
8
|
+
private _internalAddress;
|
|
6
9
|
onLoad(): Array<string | number> | boolean;
|
|
7
10
|
onReady(): boolean;
|
|
8
11
|
onUnload(rtn: string | boolean | kebab.DbValue[]): string | boolean | kebab.DbValue[];
|
package/www/example/ctr/test.js
CHANGED
|
@@ -39,21 +39,24 @@ const valibotInputSchema = v.strictObject({
|
|
|
39
39
|
'count': v.pipe(v.string(), v.toNumber(), v.integer()),
|
|
40
40
|
});
|
|
41
41
|
export default class extends sCtr.Ctr {
|
|
42
|
+
/** --- 示例自调用的地址,使用当前连接的协议和监听端口 --- */
|
|
42
43
|
_internalUrl = '';
|
|
44
|
+
/** --- 将示例域名解析到当前服务,避免绕回公网或容器外部 --- */
|
|
45
|
+
_internalAddress = '';
|
|
43
46
|
onLoad() {
|
|
44
47
|
if (this._config.const.hostname !== '127.0.0.1' && this._config.const.hostname !== '172.17.0.1' &&
|
|
45
48
|
this._config.const.hostname !== 'localhost' && !this._config.const.hostname.endsWith('.local.brc-app.com') &&
|
|
46
49
|
!this._config.const.hostname.startsWith('192.168.')) {
|
|
47
50
|
return [0, 'Please use 127.0.0.1 or local to access the file (' + this._config.const.host + ').'];
|
|
48
51
|
}
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
this._internalUrl = 'http' + (this._config.const.https ? 's' : '') + '://' + realIp + this._config.const.urlBase;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
this._internalUrl = this._config.const.urlFull;
|
|
52
|
+
const socket = this._req.socket;
|
|
53
|
+
if (!socket.localAddress || !socket.localPort) {
|
|
54
|
+
return [0, 'Request socket is unavailable.'];
|
|
56
55
|
}
|
|
56
|
+
const url = new URL(this._config.const.urlBase, `http${this._config.const.https ? 's' : ''}://${this._config.const.host}`);
|
|
57
|
+
url.port = socket.localPort.toString();
|
|
58
|
+
this._internalUrl = url.href;
|
|
59
|
+
this._internalAddress = socket.localAddress;
|
|
57
60
|
return true;
|
|
58
61
|
}
|
|
59
62
|
onReady() {
|
|
@@ -2093,8 +2096,8 @@ echo[echo.length - 1] = echo[echo.length - 1].slice(0, -4);</pre>`);
|
|
|
2093
2096
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
2094
2097
|
content: <pre>${(await res.getContent())?.toString() ?? 'null'}</pre>
|
|
2095
2098
|
error: ${JSON.stringify(res.error)}`);
|
|
2096
|
-
const res2 = await lUndici.get(this._internalUrl + 'test?abc');
|
|
2097
|
-
echo.push(`<pre>lUndici.get('${this._internalUrl}test?abc');</pre>
|
|
2099
|
+
const res2 = await lUndici.get(this._internalUrl + 'test?abc', { 'hosts': this._internalAddress });
|
|
2100
|
+
echo.push(`<pre>lUndici.get('${this._internalUrl}test?abc', { 'hosts': this._internalAddress });</pre>
|
|
2098
2101
|
headers: <pre>${JSON.stringify(res2.headers, null, 4)}</pre>
|
|
2099
2102
|
content: <pre>${(await res2.getContent())?.toString().slice(0, 500) ?? 'null'}</pre>
|
|
2100
2103
|
error: ${JSON.stringify(res2.error)}`);
|
|
@@ -2112,8 +2115,8 @@ error: ${JSON.stringify(res.error)}
|
|
|
2112
2115
|
}
|
|
2113
2116
|
async undiciPost() {
|
|
2114
2117
|
const echo = [];
|
|
2115
|
-
const res = await lUndici.post(this._internalUrl + 'test/undiciPost1', { 'a': '1', 'b': '2', 'c': ['1', '2', '3'] });
|
|
2116
|
-
echo.push(`<pre>lUndici.post('${this._internalUrl}test/undiciPost1', { 'a': '1', 'b': '2', 'c': ['1', '2', '3'] });</pre>
|
|
2118
|
+
const res = await lUndici.post(this._internalUrl + 'test/undiciPost1', { 'a': '1', 'b': '2', 'c': ['1', '2', '3'] }, { 'hosts': this._internalAddress });
|
|
2119
|
+
echo.push(`<pre>lUndici.post('${this._internalUrl}test/undiciPost1', { 'a': '1', 'b': '2', 'c': ['1', '2', '3'] }, { 'hosts': this._internalAddress });</pre>
|
|
2117
2120
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
2118
2121
|
content: <pre>${(await res.getContent())?.toString() ?? 'null'}</pre>
|
|
2119
2122
|
error: ${JSON.stringify(res.error)}`);
|
|
@@ -2124,8 +2127,8 @@ error: ${JSON.stringify(res.error)}`);
|
|
|
2124
2127
|
}
|
|
2125
2128
|
async undiciPostString() {
|
|
2126
2129
|
const echo = [];
|
|
2127
|
-
const res = await lUndici.post(this._internalUrl + 'test/undiciPostString1', 'HeiHei');
|
|
2128
|
-
echo.push(`<pre>lUndici.post('${this._internalUrl}test/undiciPostString1', 'HeiHei');</pre>
|
|
2130
|
+
const res = await lUndici.post(this._internalUrl + 'test/undiciPostString1', 'HeiHei', { 'hosts': this._internalAddress });
|
|
2131
|
+
echo.push(`<pre>lUndici.post('${this._internalUrl}test/undiciPostString1', 'HeiHei', { 'hosts': this._internalAddress });</pre>
|
|
2129
2132
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
2130
2133
|
content: <pre>${(await res.getContent())?.toString() ?? 'null'}</pre>
|
|
2131
2134
|
error: ${JSON.stringify(res.error)}`);
|
|
@@ -2136,8 +2139,9 @@ error: ${JSON.stringify(res.error)}`);
|
|
|
2136
2139
|
}
|
|
2137
2140
|
async undiciOpen() {
|
|
2138
2141
|
const echo = [];
|
|
2139
|
-
const res = await lUndici.open(this._internalUrl + 'test/undiciPost1')
|
|
2140
|
-
|
|
2142
|
+
const res = await lUndici.open(this._internalUrl + 'test/undiciPost1')
|
|
2143
|
+
.hosts(this._internalAddress).post().data({ 'a': '2', 'b': '0', 'c': ['0', '1', '3'] }).request();
|
|
2144
|
+
echo.push(`<pre>lUndici.open('${this._internalUrl}test/undiciPost1').hosts(this._internalAddress).post().data({ 'a': '2', 'b': '0', 'c': ['0', '1', '3'] }).request();</pre>
|
|
2141
2145
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
2142
2146
|
content: <pre>${(await res.getContent())?.toString() ?? 'null'}</pre>
|
|
2143
2147
|
error: ${JSON.stringify(res.error)}`);
|
|
@@ -2177,13 +2181,13 @@ error: ${JSON.stringify(res.error)}`);
|
|
|
2177
2181
|
await fd.putFile('file', kebab.LIB_PATH + 'net/cacert.pem');
|
|
2178
2182
|
await fd.putFile('multiple', kebab.LIB_PATH + 'net/cacert.pem');
|
|
2179
2183
|
await fd.putFile('multiple', kebab.LIB_PATH + 'net/cacert.pem');
|
|
2180
|
-
const res = await lUndici.post(this._internalUrl + 'test/undici-upload1', fd);
|
|
2184
|
+
const res = await lUndici.post(this._internalUrl + 'test/undici-upload1', fd, { 'hosts': this._internalAddress });
|
|
2181
2185
|
echo.push(`<pre>const fd = lUndici.getFormData();
|
|
2182
2186
|
fd.putString('a', '1');
|
|
2183
2187
|
await fd.putFile('file', kebab.LIB_PATH + 'net/cacert.pem');
|
|
2184
2188
|
await fd.putFile('multiple', kebab.LIB_PATH + 'net/cacert.pem');
|
|
2185
2189
|
await fd.putFile('multiple', kebab.LIB_PATH + 'net/cacert.pem');
|
|
2186
|
-
lUndici.post('${this._internalUrl}test/undici-upload1', fd);</pre>
|
|
2190
|
+
lUndici.post('${this._internalUrl}test/undici-upload1', fd, { 'hosts': this._internalAddress });</pre>
|
|
2187
2191
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
2188
2192
|
content: <pre>${(await res.getContent())?.toString() ?? 'null'}</pre>
|
|
2189
2193
|
error: ${JSON.stringify(res.error)}`);
|
|
@@ -2199,19 +2203,23 @@ error: ${JSON.stringify(res.error)}`);
|
|
|
2199
2203
|
const echo = [];
|
|
2200
2204
|
const cookie = {};
|
|
2201
2205
|
let res = await lUndici.get(this._internalUrl + 'test/undici-cookie1', {
|
|
2206
|
+
'hosts': this._internalAddress,
|
|
2202
2207
|
'cookie': cookie
|
|
2203
2208
|
});
|
|
2204
2209
|
echo.push(`<pre>const cookie = {};
|
|
2205
2210
|
lUndici.get(this._internalUrl + 'test/undici-cookie1', {
|
|
2211
|
+
'hosts': this._internalAddress,
|
|
2206
2212
|
'cookie': cookie
|
|
2207
2213
|
});</pre>
|
|
2208
2214
|
headers: <pre>${lText.htmlescape(JSON.stringify(res.headers, null, 4))}</pre>
|
|
2209
2215
|
content: <pre>${(await res.getContent())?.toString() ?? 'null'}</pre>
|
|
2210
2216
|
cookie: <pre>${JSON.stringify(cookie, null, 4)}</pre><hr>`);
|
|
2211
2217
|
res = await lUndici.get(this._internalUrl + 'test/undici-cookie2', {
|
|
2218
|
+
'hosts': this._internalAddress,
|
|
2212
2219
|
'cookie': cookie
|
|
2213
2220
|
});
|
|
2214
2221
|
echo.push(`<pre>lUndici.get(this._internalUrl + 'test/undici-cookie2', {
|
|
2222
|
+
'hosts': this._internalAddress,
|
|
2215
2223
|
'cookie': cookie
|
|
2216
2224
|
});</pre>
|
|
2217
2225
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
@@ -2219,11 +2227,13 @@ content: <pre>${(await res.getContent())?.toString() ?? 'null'}</pre>`);
|
|
|
2219
2227
|
lCookie.setCookie(cookie, 'custom1', 'abc1', this._config.const.host);
|
|
2220
2228
|
lCookie.setCookie(cookie, 'custom2', 'abc2', '172.17.0.1');
|
|
2221
2229
|
res = await lUndici.get(this._internalUrl + 'test/undici-cookie2', {
|
|
2230
|
+
'hosts': this._internalAddress,
|
|
2222
2231
|
'cookie': cookie
|
|
2223
2232
|
});
|
|
2224
2233
|
echo.push(`<pre>lCookie.setCookie(cookie, 'custom1', 'abc1', ${this._config.const.host});
|
|
2225
2234
|
lCookie.setCookie(cookie, 'custom2', 'abc2', '172.17.0.1');
|
|
2226
2235
|
lUndici.get(this._internalUrl + 'test/undici-cookie2', {
|
|
2236
|
+
'hosts': this._internalAddress,
|
|
2227
2237
|
'cookie': cookie
|
|
2228
2238
|
});</pre>
|
|
2229
2239
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
@@ -2356,12 +2366,14 @@ error: ${JSON.stringify(res.error)}`);
|
|
|
2356
2366
|
'a': '1',
|
|
2357
2367
|
'b': '2'
|
|
2358
2368
|
}, {
|
|
2369
|
+
'hosts': this._internalAddress,
|
|
2359
2370
|
'follow': 5
|
|
2360
2371
|
});
|
|
2361
2372
|
echo.push(`<pre>lUndici.post(this._internalUrl + 'test/undici-follow1', {
|
|
2362
2373
|
'a': '1',
|
|
2363
2374
|
'b': '2'
|
|
2364
2375
|
}, {
|
|
2376
|
+
'hosts': this._internalAddress,
|
|
2365
2377
|
'follow': 5
|
|
2366
2378
|
});</pre>
|
|
2367
2379
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
@@ -2405,11 +2417,13 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2405
2417
|
const url = `${this._internalUrl}test/undici-retry-source`;
|
|
2406
2418
|
const time = Date.now();
|
|
2407
2419
|
const res = await lUndici.get(url, {
|
|
2420
|
+
'hosts': this._internalAddress,
|
|
2408
2421
|
'retry': 1,
|
|
2409
2422
|
'log': false,
|
|
2410
2423
|
});
|
|
2411
2424
|
const content = await res.getContent();
|
|
2412
2425
|
return `<pre>const res = await lUndici.get('${url}', {
|
|
2426
|
+
'hosts': this._internalAddress,
|
|
2413
2427
|
'retry': 1,
|
|
2414
2428
|
'log': false,
|
|
2415
2429
|
});
|
|
@@ -2443,15 +2457,16 @@ error: <pre>${lText.htmlescape(res.error ? lText.stringifyError(res.error) : 'nu
|
|
|
2443
2457
|
}
|
|
2444
2458
|
async undiciHosts() {
|
|
2445
2459
|
const echo = [];
|
|
2446
|
-
const
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2460
|
+
const url = new URL('test', this._internalUrl);
|
|
2461
|
+
// --- TLS 保留当前域名以校验证书;HTTP 演示替换域名解析 ---
|
|
2462
|
+
if (!this._config.const.https) {
|
|
2463
|
+
url.hostname = 'nodejs.org';
|
|
2464
|
+
}
|
|
2465
|
+
const res = await lUndici.get(url.href, {
|
|
2466
|
+
'hosts': this._internalAddress,
|
|
2450
2467
|
});
|
|
2451
|
-
echo.push(`<pre>lUndici.get('
|
|
2452
|
-
'hosts': {
|
|
2453
|
-
'nodejs.org': '127.0.0.1'
|
|
2454
|
-
}
|
|
2468
|
+
echo.push(`<pre>lUndici.get('${url.href}', {
|
|
2469
|
+
'hosts': '${this._internalAddress}',
|
|
2455
2470
|
});</pre>
|
|
2456
2471
|
headers: <pre>${JSON.stringify(res.headers, null, 4)}</pre>
|
|
2457
2472
|
content: <pre>${lText.htmlescape((await res.getContent())?.toString() ?? '')}</pre>
|
|
@@ -2463,6 +2478,7 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2463
2478
|
const res = await lUndici.postJson(this._internalUrl + 'test/undici-mproxy2', {
|
|
2464
2479
|
'abc': 'ok',
|
|
2465
2480
|
}, {
|
|
2481
|
+
'hosts': this._internalAddress,
|
|
2466
2482
|
'mproxy': {
|
|
2467
2483
|
'url': this._internalUrl + 'test/undici-mproxy1',
|
|
2468
2484
|
'auth': '123456',
|
|
@@ -2470,6 +2486,7 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2470
2486
|
}
|
|
2471
2487
|
});
|
|
2472
2488
|
echo.push(`<pre>lUndici.postJson('${this._internalUrl}test/undici-mproxy2', {
|
|
2489
|
+
'hosts': this._internalAddress,
|
|
2473
2490
|
'mproxy': {
|
|
2474
2491
|
'url': '${this._internalUrl}test/undici-mproxy1',
|
|
2475
2492
|
'auth': '123456',
|
|
@@ -2484,7 +2501,7 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2484
2501
|
async undiciMproxy1() {
|
|
2485
2502
|
const data = lUndici.mproxyData(this);
|
|
2486
2503
|
lCore.debug('Got data', data);
|
|
2487
|
-
const rtn = await lUndici.mproxy(this, '123456');
|
|
2504
|
+
const rtn = await lUndici.mproxy(this, '123456', { 'hosts': this._internalAddress });
|
|
2488
2505
|
if (rtn > 0) {
|
|
2489
2506
|
return false;
|
|
2490
2507
|
}
|
|
@@ -2533,6 +2550,7 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2533
2550
|
const echo = [];
|
|
2534
2551
|
try {
|
|
2535
2552
|
const res = await lUndici.fetch(this._internalUrl + 'test/undici-fetch1', {
|
|
2553
|
+
'hosts': this._internalAddress,
|
|
2536
2554
|
'method': 'POST',
|
|
2537
2555
|
'headers': {
|
|
2538
2556
|
'content-type': 'application/json',
|
|
@@ -2540,6 +2558,7 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2540
2558
|
'body': JSON.stringify({ 'test': '123' }),
|
|
2541
2559
|
});
|
|
2542
2560
|
echo.push(`<pre>lUndici.fetch('${this._internalUrl}test/undici-fetch1', {
|
|
2561
|
+
'hosts': this._internalAddress,
|
|
2543
2562
|
'method': 'POST',
|
|
2544
2563
|
'headers': {
|
|
2545
2564
|
'content-type': 'application/json',
|
|
@@ -2555,6 +2574,7 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2555
2574
|
echo.push(`mproxy:`);
|
|
2556
2575
|
try {
|
|
2557
2576
|
const res = await lUndici.fetch(this._internalUrl + 'test/undici-fetch1', {
|
|
2577
|
+
'hosts': this._internalAddress,
|
|
2558
2578
|
'method': 'POST',
|
|
2559
2579
|
'headers': {
|
|
2560
2580
|
'content-type': 'application/json',
|
|
@@ -2567,6 +2587,7 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2567
2587
|
},
|
|
2568
2588
|
});
|
|
2569
2589
|
echo.push(`<pre>lUndici.fetch('${this._internalUrl}test/undici-fetch1', {
|
|
2590
|
+
'hosts': this._internalAddress,
|
|
2570
2591
|
'method': 'POST',
|
|
2571
2592
|
'headers': {
|
|
2572
2593
|
'content-type': 'application/json',
|
|
@@ -2593,15 +2614,16 @@ error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
|
2593
2614
|
}
|
|
2594
2615
|
async undiciGetResponseJson() {
|
|
2595
2616
|
const echo = [];
|
|
2596
|
-
const json = await lUndici.getResponseJson(this._internalUrl + 'test/undici-get-response-json1');
|
|
2597
|
-
echo.push(`<pre>const json = await lUndici.getResponseJson('${this._internalUrl}test/undici-get-response-json1');</pre>
|
|
2617
|
+
const json = await lUndici.getResponseJson(this._internalUrl + 'test/undici-get-response-json1', { 'hosts': this._internalAddress });
|
|
2618
|
+
echo.push(`<pre>const json = await lUndici.getResponseJson('${this._internalUrl}test/undici-get-response-json1', { 'hosts': this._internalAddress });</pre>
|
|
2598
2619
|
result: <pre>${lText.htmlescape(JSON.stringify(json, null, 4))}</pre><hr>`);
|
|
2599
|
-
const json2 = await lUndici.getResponseJson(this._internalUrl + 'test/undici-get-response-json2');
|
|
2600
|
-
echo.push(`<pre>const json2 = await lUndici.getResponseJson('${this._internalUrl}test/undici-get-response-json2');</pre>
|
|
2620
|
+
const json2 = await lUndici.getResponseJson(this._internalUrl + 'test/undici-get-response-json2', { 'hosts': this._internalAddress });
|
|
2621
|
+
echo.push(`<pre>const json2 = await lUndici.getResponseJson('${this._internalUrl}test/undici-get-response-json2', { 'hosts': this._internalAddress });</pre>
|
|
2601
2622
|
result: <pre>${lText.htmlescape(JSON.stringify(json2, null, 4))}</pre><hr>`);
|
|
2602
2623
|
/** --- JSON 重试验证方法的执行次数 --- */
|
|
2603
2624
|
let retryJsonHandlerCount = 0;
|
|
2604
2625
|
const json3 = await lUndici.getResponseJson(this._internalUrl + 'test/undici-get-response-json1', {
|
|
2626
|
+
'hosts': this._internalAddress,
|
|
2605
2627
|
'retryJson': 1,
|
|
2606
2628
|
'retryJsonHandler': (value) => {
|
|
2607
2629
|
++retryJsonHandlerCount;
|
|
@@ -2610,6 +2632,7 @@ result: <pre>${lText.htmlescape(JSON.stringify(json2, null, 4))}</pre><hr>`);
|
|
|
2610
2632
|
});
|
|
2611
2633
|
echo.push(`<pre>let retryJsonHandlerCount = 0;
|
|
2612
2634
|
const json3 = await lUndici.getResponseJson('${this._internalUrl}test/undici-get-response-json1', {
|
|
2635
|
+
'hosts': this._internalAddress,
|
|
2613
2636
|
'retryJson': 1,
|
|
2614
2637
|
'retryJsonHandler': (value) => {
|
|
2615
2638
|
++retryJsonHandlerCount;
|
|
@@ -3718,18 +3741,24 @@ setInterval(() => {
|
|
|
3718
3741
|
return echo + '<br>' + this._getEnd();
|
|
3719
3742
|
}
|
|
3720
3743
|
async wsClient() {
|
|
3721
|
-
const
|
|
3722
|
-
|
|
3744
|
+
const url = new URL('test', this._internalUrl);
|
|
3745
|
+
url.protocol = this._config.const.https ? 'wss:' : 'ws:';
|
|
3746
|
+
if (this._get['ac'] === 'hosts' && !this._config.const.https) {
|
|
3747
|
+
url.hostname = 'www.maiyun.net';
|
|
3748
|
+
}
|
|
3749
|
+
const proxyUrl = new URL('mproxy', this._internalUrl);
|
|
3750
|
+
proxyUrl.protocol = url.protocol;
|
|
3751
|
+
const ws = await lWs.connect(url.href, {
|
|
3752
|
+
'hosts': this._internalAddress,
|
|
3723
3753
|
'mproxy': this._get['ac'] === 'mproxy' ? {
|
|
3724
|
-
'url':
|
|
3725
|
-
'auth': '123456'
|
|
3754
|
+
'url': proxyUrl.href,
|
|
3755
|
+
'auth': '123456',
|
|
3726
3756
|
} : undefined,
|
|
3727
|
-
'hosts': (this._get['ac'] === 'hosts') ? '127.0.0.1' : undefined
|
|
3728
3757
|
});
|
|
3729
3758
|
if (!ws) {
|
|
3730
|
-
return
|
|
3759
|
+
return `<div>Connect "${url.href}" failed.</div><br>` + this._getEnd();
|
|
3731
3760
|
}
|
|
3732
|
-
const echo = [
|
|
3761
|
+
const echo = [`<div>Connected "${url.href}".</div>`];
|
|
3733
3762
|
// --- 绑定事件 ---
|
|
3734
3763
|
await new Promise((resolve) => {
|
|
3735
3764
|
(async () => {
|
|
@@ -4,8 +4,14 @@ import * as lWs from '#kebab/lib/ws.js';
|
|
|
4
4
|
export default class extends sCtr.Ctr {
|
|
5
5
|
async onLoad() {
|
|
6
6
|
lCore.debug('WebSocket handle test onLoad.');
|
|
7
|
+
const socket = this._req.socket;
|
|
8
|
+
if (!socket.localAddress || !socket.localPort) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const url = new URL('test', `ws${this._config.const.uri.protocol === 'wss:' ? 's' : ''}://${this._config.const.host}${this._config.const.urlBase}`);
|
|
12
|
+
url.port = socket.localPort.toString();
|
|
7
13
|
if (this._config.const.path === 'rproxy2') {
|
|
8
|
-
await lWs.rproxy(this,
|
|
14
|
+
await lWs.rproxy(this, url.href, { 'hosts': socket.localAddress });
|
|
9
15
|
}
|
|
10
16
|
return false;
|
|
11
17
|
}
|
package/www/example/ws/mproxy.js
CHANGED
|
@@ -4,7 +4,11 @@ import * as lCore from '#kebab/lib/core.js';
|
|
|
4
4
|
export default class extends sCtr.Ctr {
|
|
5
5
|
async onLoad() {
|
|
6
6
|
lCore.debug('WebSocket mproxy test onLoad.');
|
|
7
|
-
const
|
|
7
|
+
const address = this._req.socket.localAddress;
|
|
8
|
+
if (!address) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const rtn = await lWs.mproxy(this, '123456', { 'hosts': address });
|
|
8
12
|
if (rtn > 0) {
|
|
9
13
|
return false;
|
|
10
14
|
}
|
package/www/example/ws/rproxy.js
CHANGED
|
@@ -4,7 +4,13 @@ import * as lWs from '#kebab/lib/ws.js';
|
|
|
4
4
|
export default class extends sCtr.Ctr {
|
|
5
5
|
async onLoad() {
|
|
6
6
|
lCore.debug('WebSocket rproxy test onLoad.');
|
|
7
|
-
|
|
7
|
+
const socket = this._req.socket;
|
|
8
|
+
if (!socket.localAddress || !socket.localPort) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const url = new URL('test', `ws${this._config.const.uri.protocol === 'wss:' ? 's' : ''}://${this._config.const.host}${this._config.const.urlBase}`);
|
|
12
|
+
url.port = socket.localPort.toString();
|
|
13
|
+
if (await lWs.rproxy(this, url.href, { 'hosts': socket.localAddress })) {
|
|
8
14
|
return false;
|
|
9
15
|
}
|
|
10
16
|
return true;
|