@maiyunnet/kebab 9.17.2 → 9.17.3
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/doc/kebab-rag.md +92 -64
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/socket.js +46 -19
- package/lib/undici/response.d.ts +1 -1
- package/lib/undici.js +10 -0
- package/lib/ws.d.ts +15 -0
- package/lib/ws.js +103 -33
- package/package.json +1 -1
package/doc/kebab-rag.md
CHANGED
|
@@ -1428,7 +1428,7 @@ index/variables/VER.md
|
|
|
1428
1428
|
|
|
1429
1429
|
# Variable: VER
|
|
1430
1430
|
|
|
1431
|
-
> `const` **VER**: `"9.17.
|
|
1431
|
+
> `const` **VER**: `"9.17.3"` = `'9.17.3'`
|
|
1432
1432
|
|
|
1433
1433
|
Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
|
|
1434
1434
|
|
|
@@ -125272,7 +125272,7 @@ lib/undici/functions/mproxyData.md
|
|
|
125272
125272
|
|
|
125273
125273
|
> **mproxyData**(`ctr`): `any`
|
|
125274
125274
|
|
|
125275
|
-
Defined in: [lib/undici.ts:
|
|
125275
|
+
Defined in: [lib/undici.ts:741](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L741)
|
|
125276
125276
|
|
|
125277
125277
|
获取 mproxy 的附加数据
|
|
125278
125278
|
|
|
@@ -125575,7 +125575,7 @@ lib/undici/functions/rproxy.md
|
|
|
125575
125575
|
|
|
125576
125576
|
> **rproxy**(`ctr`, `route`, `opt?`): `Promise`\<`boolean`\>
|
|
125577
125577
|
|
|
125578
|
-
Defined in: [lib/undici.ts:
|
|
125578
|
+
Defined in: [lib/undici.ts:771](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L771)
|
|
125579
125579
|
|
|
125580
125580
|
反向代理,将本服务器的某个路由反代到其他网址
|
|
125581
125581
|
|
|
@@ -125664,7 +125664,7 @@ lib/undici/interfaces/IMproxyOptions.md
|
|
|
125664
125664
|
|
|
125665
125665
|
# Interface: IMproxyOptions
|
|
125666
125666
|
|
|
125667
|
-
Defined in: [lib/undici.ts:
|
|
125667
|
+
Defined in: [lib/undici.ts:902](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L902)
|
|
125668
125668
|
|
|
125669
125669
|
正向代理请求的传入参数选项
|
|
125670
125670
|
|
|
@@ -125674,7 +125674,7 @@ Defined in: [lib/undici.ts:892](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125674
125674
|
|
|
125675
125675
|
> `optional` **filter?**: (`h`) => `boolean`
|
|
125676
125676
|
|
|
125677
|
-
Defined in: [lib/undici.ts:
|
|
125677
|
+
Defined in: [lib/undici.ts:911](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L911)
|
|
125678
125678
|
|
|
125679
125679
|
过滤 header,返回 true 则留下
|
|
125680
125680
|
|
|
@@ -125694,7 +125694,7 @@ Defined in: [lib/undici.ts:901](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125694
125694
|
|
|
125695
125695
|
> `optional` **follow?**: `number`
|
|
125696
125696
|
|
|
125697
|
-
Defined in: [lib/undici.ts:
|
|
125697
|
+
Defined in: [lib/undici.ts:905](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L905)
|
|
125698
125698
|
|
|
125699
125699
|
***
|
|
125700
125700
|
|
|
@@ -125702,7 +125702,7 @@ Defined in: [lib/undici.ts:895](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125702
125702
|
|
|
125703
125703
|
> `optional` **headers?**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
|
|
125704
125704
|
|
|
125705
|
-
Defined in: [lib/undici.ts:
|
|
125705
|
+
Defined in: [lib/undici.ts:909](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L909)
|
|
125706
125706
|
|
|
125707
125707
|
***
|
|
125708
125708
|
|
|
@@ -125710,7 +125710,7 @@ Defined in: [lib/undici.ts:899](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125710
125710
|
|
|
125711
125711
|
> `optional` **hosts?**: `string` \| `Record`\<`string`, `string`\>
|
|
125712
125712
|
|
|
125713
|
-
Defined in: [lib/undici.ts:
|
|
125713
|
+
Defined in: [lib/undici.ts:907](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L907)
|
|
125714
125714
|
|
|
125715
125715
|
自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
|
|
125716
125716
|
|
|
@@ -125720,7 +125720,7 @@ Defined in: [lib/undici.ts:897](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125720
125720
|
|
|
125721
125721
|
> `optional` **local?**: `string`
|
|
125722
125722
|
|
|
125723
|
-
Defined in: [lib/undici.ts:
|
|
125723
|
+
Defined in: [lib/undici.ts:908](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L908)
|
|
125724
125724
|
|
|
125725
125725
|
***
|
|
125726
125726
|
|
|
@@ -125728,7 +125728,7 @@ Defined in: [lib/undici.ts:898](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125728
125728
|
|
|
125729
125729
|
> `optional` **reuse?**: `string` \| `Agent` \| `ProxyAgent`
|
|
125730
125730
|
|
|
125731
|
-
Defined in: [lib/undici.ts:
|
|
125731
|
+
Defined in: [lib/undici.ts:913](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L913)
|
|
125732
125732
|
|
|
125733
125733
|
默认为 default
|
|
125734
125734
|
|
|
@@ -125738,7 +125738,7 @@ Defined in: [lib/undici.ts:903](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125738
125738
|
|
|
125739
125739
|
> `optional` **timeout?**: `number`
|
|
125740
125740
|
|
|
125741
|
-
Defined in: [lib/undici.ts:
|
|
125741
|
+
Defined in: [lib/undici.ts:904](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L904)
|
|
125742
125742
|
|
|
125743
125743
|
秒数,默认 300 秒
|
|
125744
125744
|
|
|
@@ -125753,7 +125753,7 @@ lib/undici/interfaces/IRequestOptions.md
|
|
|
125753
125753
|
|
|
125754
125754
|
# Interface: IRequestOptions
|
|
125755
125755
|
|
|
125756
|
-
Defined in: [lib/undici.ts:
|
|
125756
|
+
Defined in: [lib/undici.ts:863](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L863)
|
|
125757
125757
|
|
|
125758
125758
|
请求的传入参数选项
|
|
125759
125759
|
|
|
@@ -125763,7 +125763,7 @@ Defined in: [lib/undici.ts:853](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125763
125763
|
|
|
125764
125764
|
> `optional` **cookie?**: `Record`\<`string`, [`ICookie`](../../cookie/interfaces/ICookie.md)\>
|
|
125765
125765
|
|
|
125766
|
-
Defined in: [lib/undici.ts:
|
|
125766
|
+
Defined in: [lib/undici.ts:894](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L894)
|
|
125767
125767
|
|
|
125768
125768
|
cookie 托管对象
|
|
125769
125769
|
|
|
@@ -125773,7 +125773,7 @@ cookie 托管对象
|
|
|
125773
125773
|
|
|
125774
125774
|
> `optional` **follow?**: `number`
|
|
125775
125775
|
|
|
125776
|
-
Defined in: [lib/undici.ts:
|
|
125776
|
+
Defined in: [lib/undici.ts:875](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L875)
|
|
125777
125777
|
|
|
125778
125778
|
追踪 location 次数,0 为不追踪,默认为 0
|
|
125779
125779
|
|
|
@@ -125783,7 +125783,7 @@ Defined in: [lib/undici.ts:865](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125783
125783
|
|
|
125784
125784
|
> `optional` **headers?**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
|
|
125785
125785
|
|
|
125786
|
-
Defined in: [lib/undici.ts:
|
|
125786
|
+
Defined in: [lib/undici.ts:880](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L880)
|
|
125787
125787
|
|
|
125788
125788
|
***
|
|
125789
125789
|
|
|
@@ -125791,7 +125791,7 @@ Defined in: [lib/undici.ts:870](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125791
125791
|
|
|
125792
125792
|
> `optional` **hosts?**: `string` \| `Record`\<`string`, `string`\>
|
|
125793
125793
|
|
|
125794
|
-
Defined in: [lib/undici.ts:
|
|
125794
|
+
Defined in: [lib/undici.ts:877](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L877)
|
|
125795
125795
|
|
|
125796
125796
|
自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
|
|
125797
125797
|
|
|
@@ -125801,7 +125801,7 @@ Defined in: [lib/undici.ts:867](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125801
125801
|
|
|
125802
125802
|
> `optional` **keep?**: `boolean`
|
|
125803
125803
|
|
|
125804
|
-
Defined in: [lib/undici.ts:
|
|
125804
|
+
Defined in: [lib/undici.ts:890](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L890)
|
|
125805
125805
|
|
|
125806
125806
|
连接是否保持长连接(即是否允许复用),默认为 true
|
|
125807
125807
|
|
|
@@ -125811,7 +125811,7 @@ Defined in: [lib/undici.ts:880](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125811
125811
|
|
|
125812
125812
|
> `optional` **local?**: `string`
|
|
125813
125813
|
|
|
125814
|
-
Defined in: [lib/undici.ts:
|
|
125814
|
+
Defined in: [lib/undici.ts:879](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L879)
|
|
125815
125815
|
|
|
125816
125816
|
***
|
|
125817
125817
|
|
|
@@ -125819,7 +125819,7 @@ Defined in: [lib/undici.ts:869](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125819
125819
|
|
|
125820
125820
|
> `optional` **log?**: `boolean`
|
|
125821
125821
|
|
|
125822
|
-
Defined in: [lib/undici.ts:
|
|
125822
|
+
Defined in: [lib/undici.ts:896](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L896)
|
|
125823
125823
|
|
|
125824
125824
|
若有异常写入文件日志,默认为 true
|
|
125825
125825
|
|
|
@@ -125829,7 +125829,7 @@ Defined in: [lib/undici.ts:886](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125829
125829
|
|
|
125830
125830
|
> `optional` **method?**: `"GET"` \| `"POST"` \| `"PUT"` \| `"DELETE"` \| `"OPTIONS"`
|
|
125831
125831
|
|
|
125832
|
-
Defined in: [lib/undici.ts:
|
|
125832
|
+
Defined in: [lib/undici.ts:864](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L864)
|
|
125833
125833
|
|
|
125834
125834
|
***
|
|
125835
125835
|
|
|
@@ -125837,7 +125837,7 @@ Defined in: [lib/undici.ts:854](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125837
125837
|
|
|
125838
125838
|
> `optional` **mproxy?**: `object`
|
|
125839
125839
|
|
|
125840
|
-
Defined in: [lib/undici.ts:
|
|
125840
|
+
Defined in: [lib/undici.ts:882](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L882)
|
|
125841
125841
|
|
|
125842
125842
|
正向 mproxy 代理,url 如 https://xxx/abc
|
|
125843
125843
|
|
|
@@ -125865,7 +125865,7 @@ Defined in: [lib/undici.ts:872](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125865
125865
|
|
|
125866
125866
|
> `optional` **retry?**: `number`
|
|
125867
125867
|
|
|
125868
|
-
Defined in: [lib/undici.ts:
|
|
125868
|
+
Defined in: [lib/undici.ts:869](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L869)
|
|
125869
125869
|
|
|
125870
125870
|
网络异常后的重试次数,默认 0;流式请求体不可重试,非幂等请求需由调用方保证安全
|
|
125871
125871
|
|
|
@@ -125875,7 +125875,7 @@ Defined in: [lib/undici.ts:859](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125875
125875
|
|
|
125876
125876
|
> `optional` **retryJson?**: `number`
|
|
125877
125877
|
|
|
125878
|
-
Defined in: [lib/undici.ts:
|
|
125878
|
+
Defined in: [lib/undici.ts:871](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L871)
|
|
125879
125879
|
|
|
125880
125880
|
JSON 解析失败后的重试次数,默认 0;仅适用于 ResponseJson 快捷方法,非幂等请求需由调用方保证安全
|
|
125881
125881
|
|
|
@@ -125885,7 +125885,7 @@ JSON 解析失败后的重试次数,默认 0;仅适用于 ResponseJson 快
|
|
|
125885
125885
|
|
|
125886
125886
|
> `optional` **retryJsonHandler?**: (`json`) => `boolean`
|
|
125887
125887
|
|
|
125888
|
-
Defined in: [lib/undici.ts:
|
|
125888
|
+
Defined in: [lib/undici.ts:873](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L873)
|
|
125889
125889
|
|
|
125890
125890
|
JSON 重试验证方法;返回 false 时按 retryJson 的设置重试,仅适用于 ResponseJson 快捷方法
|
|
125891
125891
|
|
|
@@ -125905,7 +125905,7 @@ JSON 重试验证方法;返回 false 时按 retryJson 的设置重试,仅适
|
|
|
125905
125905
|
|
|
125906
125906
|
> `optional` **reuse?**: `string` \| `Agent` \| `ProxyAgent`
|
|
125907
125907
|
|
|
125908
|
-
Defined in: [lib/undici.ts:
|
|
125908
|
+
Defined in: [lib/undici.ts:892](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L892)
|
|
125909
125909
|
|
|
125910
125910
|
复用池名/Agent,默认为 default
|
|
125911
125911
|
|
|
@@ -125915,7 +125915,7 @@ Defined in: [lib/undici.ts:882](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125915
125915
|
|
|
125916
125916
|
> `optional` **save?**: `string`
|
|
125917
125917
|
|
|
125918
|
-
Defined in: [lib/undici.ts:
|
|
125918
|
+
Defined in: [lib/undici.ts:878](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L878)
|
|
125919
125919
|
|
|
125920
125920
|
***
|
|
125921
125921
|
|
|
@@ -125923,7 +125923,7 @@ Defined in: [lib/undici.ts:868](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125923
125923
|
|
|
125924
125924
|
> `optional` **signal?**: `AbortSignal`
|
|
125925
125925
|
|
|
125926
|
-
Defined in: [lib/undici.ts:
|
|
125926
|
+
Defined in: [lib/undici.ts:898](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L898)
|
|
125927
125927
|
|
|
125928
125928
|
请求中止信号
|
|
125929
125929
|
|
|
@@ -125933,7 +125933,7 @@ Defined in: [lib/undici.ts:888](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125933
125933
|
|
|
125934
125934
|
> `optional` **timeout?**: `number`
|
|
125935
125935
|
|
|
125936
|
-
Defined in: [lib/undici.ts:
|
|
125936
|
+
Defined in: [lib/undici.ts:867](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L867)
|
|
125937
125937
|
|
|
125938
125938
|
秒数,默认 300 秒
|
|
125939
125939
|
|
|
@@ -125943,7 +125943,7 @@ Defined in: [lib/undici.ts:857](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125943
125943
|
|
|
125944
125944
|
> `optional` **type?**: `"form"` \| `"json"`
|
|
125945
125945
|
|
|
125946
|
-
Defined in: [lib/undici.ts:
|
|
125946
|
+
Defined in: [lib/undici.ts:865](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L865)
|
|
125947
125947
|
|
|
125948
125948
|
lib/undici/interfaces/IRproxyOptions.md
|
|
125949
125949
|
---
|
|
@@ -125956,7 +125956,7 @@ lib/undici/interfaces/IRproxyOptions.md
|
|
|
125956
125956
|
|
|
125957
125957
|
# Interface: IRproxyOptions
|
|
125958
125958
|
|
|
125959
|
-
Defined in: [lib/undici.ts:
|
|
125959
|
+
Defined in: [lib/undici.ts:917](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L917)
|
|
125960
125960
|
|
|
125961
125961
|
反向代理请求的传入参数选项
|
|
125962
125962
|
|
|
@@ -125966,7 +125966,7 @@ Defined in: [lib/undici.ts:907](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125966
125966
|
|
|
125967
125967
|
> `optional` **body?**: `string` \| `Buffer`\<`ArrayBufferLike`\> \| `Readable`
|
|
125968
125968
|
|
|
125969
|
-
Defined in: [lib/undici.ts:
|
|
125969
|
+
Defined in: [lib/undici.ts:936](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L936)
|
|
125970
125970
|
|
|
125971
125971
|
手动传入请求体(优先于原始 req 流),用于 req 流已消费后仍需转发 body 的场景
|
|
125972
125972
|
|
|
@@ -125976,7 +125976,7 @@ Defined in: [lib/undici.ts:926](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125976
125976
|
|
|
125977
125977
|
> `optional` **filter?**: (`h`) => `boolean`
|
|
125978
125978
|
|
|
125979
|
-
Defined in: [lib/undici.ts:
|
|
125979
|
+
Defined in: [lib/undici.ts:926](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L926)
|
|
125980
125980
|
|
|
125981
125981
|
过滤 header,返回 true 则留下
|
|
125982
125982
|
|
|
@@ -125996,7 +125996,7 @@ Defined in: [lib/undici.ts:916](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
125996
125996
|
|
|
125997
125997
|
> `optional` **follow?**: `number`
|
|
125998
125998
|
|
|
125999
|
-
Defined in: [lib/undici.ts:
|
|
125999
|
+
Defined in: [lib/undici.ts:920](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L920)
|
|
126000
126000
|
|
|
126001
126001
|
***
|
|
126002
126002
|
|
|
@@ -126004,7 +126004,7 @@ Defined in: [lib/undici.ts:910](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
126004
126004
|
|
|
126005
126005
|
> `optional` **headers?**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
|
|
126006
126006
|
|
|
126007
|
-
Defined in: [lib/undici.ts:
|
|
126007
|
+
Defined in: [lib/undici.ts:924](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L924)
|
|
126008
126008
|
|
|
126009
126009
|
***
|
|
126010
126010
|
|
|
@@ -126012,7 +126012,7 @@ Defined in: [lib/undici.ts:914](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
126012
126012
|
|
|
126013
126013
|
> `optional` **hosts?**: `string` \| `Record`\<`string`, `string`\>
|
|
126014
126014
|
|
|
126015
|
-
Defined in: [lib/undici.ts:
|
|
126015
|
+
Defined in: [lib/undici.ts:922](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L922)
|
|
126016
126016
|
|
|
126017
126017
|
自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
|
|
126018
126018
|
|
|
@@ -126022,7 +126022,7 @@ Defined in: [lib/undici.ts:912](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
126022
126022
|
|
|
126023
126023
|
> `optional` **local?**: `string`
|
|
126024
126024
|
|
|
126025
|
-
Defined in: [lib/undici.ts:
|
|
126025
|
+
Defined in: [lib/undici.ts:923](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L923)
|
|
126026
126026
|
|
|
126027
126027
|
***
|
|
126028
126028
|
|
|
@@ -126030,7 +126030,7 @@ Defined in: [lib/undici.ts:913](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
126030
126030
|
|
|
126031
126031
|
> `optional` **mproxy?**: `object`
|
|
126032
126032
|
|
|
126033
|
-
Defined in: [lib/undici.ts:
|
|
126033
|
+
Defined in: [lib/undici.ts:928](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L928)
|
|
126034
126034
|
|
|
126035
126035
|
正向 mproxy 代理,url 如 https://xxx/abc
|
|
126036
126036
|
|
|
@@ -126058,7 +126058,7 @@ Defined in: [lib/undici.ts:918](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
126058
126058
|
|
|
126059
126059
|
> `optional` **querys?**: `Record`\<`string`, `any`\>
|
|
126060
126060
|
|
|
126061
|
-
Defined in: [lib/undici.ts:
|
|
126061
|
+
Defined in: [lib/undici.ts:938](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L938)
|
|
126062
126062
|
|
|
126063
126063
|
自定义 GET 查询参数,传入后直接替换代理目标 URL 的整个 query string
|
|
126064
126064
|
|
|
@@ -126068,7 +126068,7 @@ Defined in: [lib/undici.ts:928](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
126068
126068
|
|
|
126069
126069
|
> `optional` **reuse?**: `string` \| `Agent` \| `ProxyAgent`
|
|
126070
126070
|
|
|
126071
|
-
Defined in: [lib/undici.ts:
|
|
126071
|
+
Defined in: [lib/undici.ts:940](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L940)
|
|
126072
126072
|
|
|
126073
126073
|
默认为 default
|
|
126074
126074
|
|
|
@@ -126078,7 +126078,7 @@ Defined in: [lib/undici.ts:930](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
126078
126078
|
|
|
126079
126079
|
> `optional` **timeout?**: `number`
|
|
126080
126080
|
|
|
126081
|
-
Defined in: [lib/undici.ts:
|
|
126081
|
+
Defined in: [lib/undici.ts:919](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L919)
|
|
126082
126082
|
|
|
126083
126083
|
秒数,默认 300 秒
|
|
126084
126084
|
|
|
@@ -126589,7 +126589,7 @@ lib/undici/type-aliases/THttpHeaders.md
|
|
|
126589
126589
|
|
|
126590
126590
|
> **THttpHeaders** = `http.IncomingHttpHeaders` & `object`
|
|
126591
126591
|
|
|
126592
|
-
Defined in: [lib/undici.ts:
|
|
126592
|
+
Defined in: [lib/undici.ts:945](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L945)
|
|
126593
126593
|
|
|
126594
126594
|
http headers
|
|
126595
126595
|
|
|
@@ -126876,7 +126876,7 @@ lib/ws/classes/Socket.md
|
|
|
126876
126876
|
|
|
126877
126877
|
# Class: Socket
|
|
126878
126878
|
|
|
126879
|
-
Defined in: [lib/ws.ts:
|
|
126879
|
+
Defined in: [lib/ws.ts:106](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L106)
|
|
126880
126880
|
|
|
126881
126881
|
## Constructors
|
|
126882
126882
|
|
|
@@ -126884,7 +126884,7 @@ Defined in: [lib/ws.ts:96](https://github.com/maiyunnet/kebab/blob/master/lib/ws
|
|
|
126884
126884
|
|
|
126885
126885
|
> **new Socket**(`request?`, `socket?`, `head?`, `options?`): `Socket`
|
|
126886
126886
|
|
|
126887
|
-
Defined in: [lib/ws.ts:
|
|
126887
|
+
Defined in: [lib/ws.ts:111](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L111)
|
|
126888
126888
|
|
|
126889
126889
|
#### Parameters
|
|
126890
126890
|
|
|
@@ -126922,7 +126922,7 @@ Defined in: [lib/ws.ts:101](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
126922
126922
|
|
|
126923
126923
|
> **get** **ended**(): `boolean`
|
|
126924
126924
|
|
|
126925
|
-
Defined in: [lib/ws.ts:
|
|
126925
|
+
Defined in: [lib/ws.ts:420](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L420)
|
|
126926
126926
|
|
|
126927
126927
|
当前是否已经结束读取,并且无法继续读取
|
|
126928
126928
|
|
|
@@ -126938,7 +126938,7 @@ Defined in: [lib/ws.ts:366](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
126938
126938
|
|
|
126939
126939
|
> **get** **finished**(): `boolean`
|
|
126940
126940
|
|
|
126941
|
-
Defined in: [lib/ws.ts:
|
|
126941
|
+
Defined in: [lib/ws.ts:425](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L425)
|
|
126942
126942
|
|
|
126943
126943
|
当前是否已经结束写入,并且无法继续写入
|
|
126944
126944
|
|
|
@@ -126954,7 +126954,7 @@ Defined in: [lib/ws.ts:371](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
126954
126954
|
|
|
126955
126955
|
> **get** **isServer**(): `boolean`
|
|
126956
126956
|
|
|
126957
|
-
Defined in: [lib/ws.ts:
|
|
126957
|
+
Defined in: [lib/ws.ts:432](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L432)
|
|
126958
126958
|
|
|
126959
126959
|
当前连接是不是服务器连接
|
|
126960
126960
|
|
|
@@ -126970,7 +126970,7 @@ Defined in: [lib/ws.ts:378](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
126970
126970
|
|
|
126971
126971
|
> **get** **writable**(): `boolean`
|
|
126972
126972
|
|
|
126973
|
-
Defined in: [lib/ws.ts:
|
|
126973
|
+
Defined in: [lib/ws.ts:415](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L415)
|
|
126974
126974
|
|
|
126975
126975
|
当前是否是可写状态
|
|
126976
126976
|
|
|
@@ -126984,7 +126984,7 @@ Defined in: [lib/ws.ts:361](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
126984
126984
|
|
|
126985
126985
|
> **connect**(`u`, `opt?`): `Promise`\<`Socket` \| `null`\>
|
|
126986
126986
|
|
|
126987
|
-
Defined in: [lib/ws.ts:
|
|
126987
|
+
Defined in: [lib/ws.ts:134](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L134)
|
|
126988
126988
|
|
|
126989
126989
|
以客户端形式发起链接
|
|
126990
126990
|
|
|
@@ -127012,7 +127012,7 @@ Defined in: [lib/ws.ts:124](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127012
127012
|
|
|
127013
127013
|
> **destroy**(): `void`
|
|
127014
127014
|
|
|
127015
|
-
Defined in: [lib/ws.ts:
|
|
127015
|
+
Defined in: [lib/ws.ts:375](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L375)
|
|
127016
127016
|
|
|
127017
127017
|
#### Returns
|
|
127018
127018
|
|
|
@@ -127024,7 +127024,7 @@ Defined in: [lib/ws.ts:332](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127024
127024
|
|
|
127025
127025
|
> **end**(): `void`
|
|
127026
127026
|
|
|
127027
|
-
Defined in: [lib/ws.ts:
|
|
127027
|
+
Defined in: [lib/ws.ts:371](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L371)
|
|
127028
127028
|
|
|
127029
127029
|
#### Returns
|
|
127030
127030
|
|
|
@@ -127036,7 +127036,7 @@ Defined in: [lib/ws.ts:328](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127036
127036
|
|
|
127037
127037
|
> **off**(`event`): `this`
|
|
127038
127038
|
|
|
127039
|
-
Defined in: [lib/ws.ts:
|
|
127039
|
+
Defined in: [lib/ws.ts:366](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L366)
|
|
127040
127040
|
|
|
127041
127041
|
取消监听
|
|
127042
127042
|
|
|
@@ -127058,7 +127058,7 @@ Defined in: [lib/ws.ts:323](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127058
127058
|
|
|
127059
127059
|
> **on**(`event`, `cb`): `this`
|
|
127060
127060
|
|
|
127061
|
-
Defined in: [lib/ws.ts:
|
|
127061
|
+
Defined in: [lib/ws.ts:327](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L327)
|
|
127062
127062
|
|
|
127063
127063
|
绑定监听
|
|
127064
127064
|
|
|
@@ -127080,7 +127080,7 @@ Defined in: [lib/ws.ts:282](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127080
127080
|
|
|
127081
127081
|
> **on**(`event`, `cb`): `this`
|
|
127082
127082
|
|
|
127083
|
-
Defined in: [lib/ws.ts:
|
|
127083
|
+
Defined in: [lib/ws.ts:331](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L331)
|
|
127084
127084
|
|
|
127085
127085
|
绑定监听
|
|
127086
127086
|
|
|
@@ -127102,7 +127102,7 @@ Defined in: [lib/ws.ts:286](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127102
127102
|
|
|
127103
127103
|
> **on**(`event`, `cb`): `this`
|
|
127104
127104
|
|
|
127105
|
-
Defined in: [lib/ws.ts:
|
|
127105
|
+
Defined in: [lib/ws.ts:332](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L332)
|
|
127106
127106
|
|
|
127107
127107
|
绑定监听
|
|
127108
127108
|
|
|
@@ -127122,11 +127122,25 @@ Defined in: [lib/ws.ts:287](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127122
127122
|
|
|
127123
127123
|
***
|
|
127124
127124
|
|
|
127125
|
+
### pause()
|
|
127126
|
+
|
|
127127
|
+
> **pause**(): `void`
|
|
127128
|
+
|
|
127129
|
+
Defined in: [lib/ws.ts:380](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L380)
|
|
127130
|
+
|
|
127131
|
+
暂停向消息监听器派发数据,底层仍只保留有界缓存
|
|
127132
|
+
|
|
127133
|
+
#### Returns
|
|
127134
|
+
|
|
127135
|
+
`void`
|
|
127136
|
+
|
|
127137
|
+
***
|
|
127138
|
+
|
|
127125
127139
|
### ping()
|
|
127126
127140
|
|
|
127127
127141
|
> **ping**(`data?`): `boolean`
|
|
127128
127142
|
|
|
127129
|
-
Defined in: [lib/ws.ts:
|
|
127143
|
+
Defined in: [lib/ws.ts:437](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L437)
|
|
127130
127144
|
|
|
127131
127145
|
发送 ping
|
|
127132
127146
|
|
|
@@ -127146,7 +127160,7 @@ Defined in: [lib/ws.ts:383](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127146
127160
|
|
|
127147
127161
|
> **pong**(`data?`): `boolean`
|
|
127148
127162
|
|
|
127149
|
-
Defined in: [lib/ws.ts:
|
|
127163
|
+
Defined in: [lib/ws.ts:448](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L448)
|
|
127150
127164
|
|
|
127151
127165
|
发送 ping
|
|
127152
127166
|
|
|
@@ -127162,11 +127176,25 @@ Defined in: [lib/ws.ts:394](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127162
127176
|
|
|
127163
127177
|
***
|
|
127164
127178
|
|
|
127179
|
+
### resume()
|
|
127180
|
+
|
|
127181
|
+
> **resume**(): `void`
|
|
127182
|
+
|
|
127183
|
+
Defined in: [lib/ws.ts:385](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L385)
|
|
127184
|
+
|
|
127185
|
+
恢复向消息监听器派发数据
|
|
127186
|
+
|
|
127187
|
+
#### Returns
|
|
127188
|
+
|
|
127189
|
+
`void`
|
|
127190
|
+
|
|
127191
|
+
***
|
|
127192
|
+
|
|
127165
127193
|
### writeBinary()
|
|
127166
127194
|
|
|
127167
127195
|
> **writeBinary**(`data`): `boolean`
|
|
127168
127196
|
|
|
127169
|
-
Defined in: [lib/ws.ts:
|
|
127197
|
+
Defined in: [lib/ws.ts:407](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L407)
|
|
127170
127198
|
|
|
127171
127199
|
发送二进制
|
|
127172
127200
|
|
|
@@ -127186,7 +127214,7 @@ Defined in: [lib/ws.ts:353](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127186
127214
|
|
|
127187
127215
|
> **writeResult**(`data`): `boolean`
|
|
127188
127216
|
|
|
127189
|
-
Defined in: [lib/ws.ts:
|
|
127217
|
+
Defined in: [lib/ws.ts:399](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L399)
|
|
127190
127218
|
|
|
127191
127219
|
发送结果对象字符串
|
|
127192
127220
|
|
|
@@ -127206,7 +127234,7 @@ Defined in: [lib/ws.ts:345](https://github.com/maiyunnet/kebab/blob/master/lib/w
|
|
|
127206
127234
|
|
|
127207
127235
|
> **writeText**(`data`): `boolean`
|
|
127208
127236
|
|
|
127209
|
-
Defined in: [lib/ws.ts:
|
|
127237
|
+
Defined in: [lib/ws.ts:391](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L391)
|
|
127210
127238
|
|
|
127211
127239
|
发送文本
|
|
127212
127240
|
|
|
@@ -127335,7 +127363,7 @@ lib/ws/functions/connect.md
|
|
|
127335
127363
|
|
|
127336
127364
|
> **connect**(`u`, `opt?`): `Promise`\<[`Socket`](../classes/Socket.md) \| `null`\>
|
|
127337
127365
|
|
|
127338
|
-
Defined in: [lib/ws.ts:
|
|
127366
|
+
Defined in: [lib/ws.ts:465](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L465)
|
|
127339
127367
|
|
|
127340
127368
|
创建一个 ws 客户端发起 ws 请求
|
|
127341
127369
|
|
|
@@ -127370,7 +127398,7 @@ lib/ws/functions/createServer.md
|
|
|
127370
127398
|
|
|
127371
127399
|
> **createServer**(`request`, `socket`, `head?`, `options?`): [`Socket`](../classes/Socket.md)
|
|
127372
127400
|
|
|
127373
|
-
Defined in: [lib/ws.ts:
|
|
127401
|
+
Defined in: [lib/ws.ts:475](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L475)
|
|
127374
127402
|
|
|
127375
127403
|
创建一个 ws 服务器接收处理器
|
|
127376
127404
|
|
|
@@ -127419,7 +127447,7 @@ lib/ws/functions/mproxy.md
|
|
|
127419
127447
|
|
|
127420
127448
|
> **mproxy**(`ctr`, `auth`, `opt?`): `Promise`\<`number`\>
|
|
127421
127449
|
|
|
127422
|
-
Defined in: [lib/ws.ts:
|
|
127450
|
+
Defined in: [lib/ws.ts:587](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L587)
|
|
127423
127451
|
|
|
127424
127452
|
正向 mproxy 代理,读取 get 的 url 为实际请求地址
|
|
127425
127453
|
get: url, auth
|
|
@@ -127461,7 +127489,7 @@ lib/ws/functions/rproxy.md
|
|
|
127461
127489
|
|
|
127462
127490
|
> **rproxy**(`ctr`, `url`, `opt?`): `Promise`\<`boolean`\>
|
|
127463
127491
|
|
|
127464
|
-
Defined in: [lib/ws.ts:
|
|
127492
|
+
Defined in: [lib/ws.ts:624](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L624)
|
|
127465
127493
|
|
|
127466
127494
|
反向代理,将本 socket 连接反代到其他网址,在 ws 的 onLoad 事件中使用
|
|
127467
127495
|
|
|
@@ -127502,7 +127530,7 @@ lib/ws/functions/rsocket.md
|
|
|
127502
127530
|
|
|
127503
127531
|
> **rsocket**(`ctr`, `host`, `port`): `Promise`\<`boolean`\>
|
|
127504
127532
|
|
|
127505
|
-
Defined in: [lib/ws.ts:
|
|
127533
|
+
Defined in: [lib/ws.ts:653](https://github.com/maiyunnet/kebab/blob/master/lib/ws.ts#L653)
|
|
127506
127534
|
|
|
127507
127535
|
反向代理,将本 websocket 连接反代到其他真正的 socket,在 ws 的 onLoad 事件中使用
|
|
127508
127536
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '9.17.
|
|
9
|
+
export const VER = '9.17.3';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/socket.js
CHANGED
|
@@ -17,31 +17,60 @@ export function rwebsocket(port, url, opt = {}) {
|
|
|
17
17
|
/** --- 请求端产生的双向 socket --- */
|
|
18
18
|
const server = net.createServer(socket => {
|
|
19
19
|
socket.setKeepAlive(true);
|
|
20
|
+
/** --- 远程端的双向 WebSocket --- */
|
|
21
|
+
let rws = null;
|
|
22
|
+
/** --- 心跳定时器 --- */
|
|
23
|
+
let timer = null;
|
|
24
|
+
/** --- 是否已开始清理 --- */
|
|
25
|
+
let closed = false;
|
|
26
|
+
/** --- 同时清理 TCP、WebSocket 与心跳 --- */
|
|
27
|
+
const close = () => {
|
|
28
|
+
if (closed) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
closed = true;
|
|
32
|
+
if (timer) {
|
|
33
|
+
clearInterval(timer);
|
|
34
|
+
timer = null;
|
|
35
|
+
}
|
|
36
|
+
socket.destroy();
|
|
37
|
+
rws?.destroy();
|
|
38
|
+
};
|
|
39
|
+
// --- 必须在异步连接前监听,避免本地先断开后留下远端连接 ---
|
|
40
|
+
socket.on('close', close).on('error', err => {
|
|
41
|
+
lCore.display('[' + lTime.format(null, 'Y-m-d H:i:s') + '] Client error: ' + socket.remoteAddress + ':' + socket.remotePort + ', ' + err.message);
|
|
42
|
+
close();
|
|
43
|
+
});
|
|
20
44
|
(async () => {
|
|
21
45
|
// --- 每次进一个新连接都反代到一个新 WebSocket ---
|
|
22
46
|
lCore.display('[' + lTime.format(null, 'Y-m-d H:i:s') + '] New client: ' + socket.remoteAddress + ':' + socket.remotePort);
|
|
23
|
-
|
|
24
|
-
const rws = await lWs.connect(url, opt);
|
|
47
|
+
rws = await lWs.connect(url, opt);
|
|
25
48
|
if (!rws) {
|
|
26
|
-
|
|
49
|
+
close();
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (closed) {
|
|
53
|
+
rws.destroy();
|
|
27
54
|
return false;
|
|
28
55
|
}
|
|
29
|
-
|
|
30
|
-
rws
|
|
56
|
+
timer = setInterval(() => {
|
|
57
|
+
rws?.ping();
|
|
31
58
|
}, 10_000);
|
|
32
59
|
rws.on('message', msg => {
|
|
33
60
|
switch (msg.opcode) {
|
|
34
61
|
case lWs.EOpcode.TEXT:
|
|
35
62
|
case lWs.EOpcode.BINARY: {
|
|
36
|
-
socket.write(msg.data)
|
|
63
|
+
if (!socket.write(msg.data)) {
|
|
64
|
+
rws?.pause();
|
|
65
|
+
}
|
|
37
66
|
break;
|
|
38
67
|
}
|
|
39
68
|
case lWs.EOpcode.CLOSE: {
|
|
40
|
-
|
|
69
|
+
close();
|
|
41
70
|
break;
|
|
42
71
|
}
|
|
43
72
|
case lWs.EOpcode.PING: {
|
|
44
|
-
rws
|
|
73
|
+
rws?.pong();
|
|
45
74
|
break;
|
|
46
75
|
}
|
|
47
76
|
case lWs.EOpcode.PONG: {
|
|
@@ -51,20 +80,18 @@ export function rwebsocket(port, url, opt = {}) {
|
|
|
51
80
|
// --- EOpcode.CONTINUATION ---
|
|
52
81
|
}
|
|
53
82
|
}
|
|
54
|
-
}).on('
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
83
|
+
}).on('drain', () => {
|
|
84
|
+
socket.resume();
|
|
85
|
+
}).on('close', close);
|
|
58
86
|
socket.on('data', data => {
|
|
59
|
-
rws.writeBinary(data)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
87
|
+
if (rws && !rws.writeBinary(data)) {
|
|
88
|
+
socket.pause();
|
|
89
|
+
}
|
|
90
|
+
}).on('drain', () => {
|
|
91
|
+
rws?.resume();
|
|
63
92
|
}).on('end', () => {
|
|
64
|
-
rws.end();
|
|
65
93
|
lCore.display('[' + lTime.format(null, 'Y-m-d H:i:s') + '] Client disconnected: ' + socket.remoteAddress + ':' + socket.remotePort);
|
|
66
|
-
|
|
67
|
-
lCore.display('[' + lTime.format(null, 'Y-m-d H:i:s') + '] Client error: ' + socket.remoteAddress + ':' + socket.remotePort + ', ' + err.message);
|
|
94
|
+
close();
|
|
68
95
|
});
|
|
69
96
|
})().catch(() => { });
|
|
70
97
|
}).listen(port, () => {
|
package/lib/undici/response.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class Response {
|
|
|
31
31
|
/**
|
|
32
32
|
* --- 获取响应读取流对象 ---
|
|
33
33
|
*/
|
|
34
|
-
getStream():
|
|
34
|
+
getStream(): (import("undici/types/readable").default & undici.Dispatcher.BodyMixin) | zlib.Gunzip | zlib.Inflate | zlib.BrotliDecompress | null;
|
|
35
35
|
/**
|
|
36
36
|
* --- 获取原生响应读取流对象 ---
|
|
37
37
|
*/
|
package/lib/undici.js
CHANGED
|
@@ -636,10 +636,14 @@ export async function mproxy(ctr, auth, opt = {}) {
|
|
|
636
636
|
});
|
|
637
637
|
// --- 同时监听 close 确保 promise 一定会 resolve(客户端断连等场景) ---
|
|
638
638
|
stream.pipe(res).on('close', () => {
|
|
639
|
+
stream.destroy();
|
|
639
640
|
resolve();
|
|
640
641
|
});
|
|
641
642
|
});
|
|
642
643
|
}
|
|
644
|
+
else {
|
|
645
|
+
stream.destroy();
|
|
646
|
+
}
|
|
643
647
|
return 1;
|
|
644
648
|
}
|
|
645
649
|
/**
|
|
@@ -739,16 +743,22 @@ export async function rproxy(ctr, route, opt = {}) {
|
|
|
739
743
|
// --- 同时监听 close 确保 promise 一定会 resolve(客户端断连等场景) ---
|
|
740
744
|
if (compress) {
|
|
741
745
|
stream.pipe(compress.compress).pipe(res).on('close', () => {
|
|
746
|
+
stream.destroy();
|
|
747
|
+
compress.compress.destroy();
|
|
742
748
|
resolve();
|
|
743
749
|
});
|
|
744
750
|
}
|
|
745
751
|
else {
|
|
746
752
|
stream.pipe(res).on('close', () => {
|
|
753
|
+
stream.destroy();
|
|
747
754
|
resolve();
|
|
748
755
|
});
|
|
749
756
|
}
|
|
750
757
|
});
|
|
751
758
|
}
|
|
759
|
+
else {
|
|
760
|
+
stream.destroy();
|
|
761
|
+
}
|
|
752
762
|
return true;
|
|
753
763
|
}
|
|
754
764
|
return false;
|
package/lib/ws.d.ts
CHANGED
|
@@ -96,12 +96,23 @@ export declare class Socket {
|
|
|
96
96
|
private _bindEvent;
|
|
97
97
|
/** --- 还未开启监听时来的数据将存在这里 --- */
|
|
98
98
|
private readonly _waitMsg;
|
|
99
|
+
/** --- 尚未交给消息监听器的数据量 --- */
|
|
100
|
+
private _waitMsgBytes;
|
|
101
|
+
/** --- 是否暂停向上层派发消息 --- */
|
|
102
|
+
private _paused;
|
|
99
103
|
/** --- 还未开启 error 监听时产生的 error 错误对象 --- */
|
|
100
104
|
private _error;
|
|
101
105
|
/** --- 还未开启 close 监听时是不是就已经 close --- */
|
|
102
106
|
private _close;
|
|
103
107
|
/** --- 绑定的自定义监听事件(未绑定则默认在 _bindEvent 执行) --- */
|
|
104
108
|
private _on;
|
|
109
|
+
/**
|
|
110
|
+
* --- 暂存尚不能交给上层处理的消息 ---
|
|
111
|
+
* @param msg 消息
|
|
112
|
+
*/
|
|
113
|
+
private _queueMessage;
|
|
114
|
+
/** --- 依次派发缓存消息,若再次发生背压则停止 --- */
|
|
115
|
+
private _flushMessages;
|
|
105
116
|
/** --- 绑定监听 --- */
|
|
106
117
|
on(event: 'message', cb: (msg: {
|
|
107
118
|
'opcode': EOpcode;
|
|
@@ -113,6 +124,10 @@ export declare class Socket {
|
|
|
113
124
|
off(event: 'message' | 'drain' | 'error' | 'close' | 'end' | 'timeout'): this;
|
|
114
125
|
end(): void;
|
|
115
126
|
destroy(): void;
|
|
127
|
+
/** --- 暂停向消息监听器派发数据,底层仍只保留有界缓存 --- */
|
|
128
|
+
pause(): void;
|
|
129
|
+
/** --- 恢复向消息监听器派发数据 --- */
|
|
130
|
+
resume(): void;
|
|
116
131
|
/** --- 发送文本 --- */
|
|
117
132
|
writeText(data: Buffer | string | Array<Buffer | string>): boolean;
|
|
118
133
|
/** --- 发送结果对象字符串 --- */
|
package/lib/ws.js
CHANGED
|
@@ -24,6 +24,10 @@ export var EOpcode;
|
|
|
24
24
|
const liwsServer = liws.createServer({
|
|
25
25
|
'frameReceiveMode': EFrameReceiveMode.SIMPLE,
|
|
26
26
|
});
|
|
27
|
+
/** --- 未能及时转发的 WebSocket 消息最大缓存量,超过后关闭连接保护进程内存 --- */
|
|
28
|
+
const MAX_PENDING_MESSAGE_BYTES = 8 * 1024 * 1024;
|
|
29
|
+
/** --- 未能及时转发的 WebSocket 消息最大条数,防止大量小帧占满内存 --- */
|
|
30
|
+
const MAX_PENDING_MESSAGES = 4_096;
|
|
27
31
|
export class Socket {
|
|
28
32
|
/** --- 当前的 ws 对象 --- */
|
|
29
33
|
_ws;
|
|
@@ -132,19 +136,15 @@ export class Socket {
|
|
|
132
136
|
if (!('data' in msg)) {
|
|
133
137
|
return;
|
|
134
138
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
else {
|
|
143
|
-
this._waitMsg.push({
|
|
144
|
-
'opcode': msg.opcode,
|
|
145
|
-
'data': buf,
|
|
146
|
-
});
|
|
139
|
+
const item = {
|
|
140
|
+
'opcode': msg.opcode,
|
|
141
|
+
'data': Buffer.concat(msg.data),
|
|
142
|
+
};
|
|
143
|
+
if (this._paused || !this._on.message) {
|
|
144
|
+
this._queueMessage(item);
|
|
145
|
+
return;
|
|
147
146
|
}
|
|
147
|
+
this._on.message(item);
|
|
148
148
|
}).on('drain', () => {
|
|
149
149
|
this._on.drain?.();
|
|
150
150
|
}).on('error', (e) => {
|
|
@@ -157,6 +157,8 @@ export class Socket {
|
|
|
157
157
|
}).on('end', () => {
|
|
158
158
|
this._on.end?.();
|
|
159
159
|
}).on('close', () => {
|
|
160
|
+
this._waitMsg.length = 0;
|
|
161
|
+
this._waitMsgBytes = 0;
|
|
160
162
|
if (this._on.close) {
|
|
161
163
|
this._on.close();
|
|
162
164
|
}
|
|
@@ -169,6 +171,10 @@ export class Socket {
|
|
|
169
171
|
}
|
|
170
172
|
/** --- 还未开启监听时来的数据将存在这里 --- */
|
|
171
173
|
_waitMsg = [];
|
|
174
|
+
/** --- 尚未交给消息监听器的数据量 --- */
|
|
175
|
+
_waitMsgBytes = 0;
|
|
176
|
+
/** --- 是否暂停向上层派发消息 --- */
|
|
177
|
+
_paused = false;
|
|
172
178
|
/** --- 还未开启 error 监听时产生的 error 错误对象 --- */
|
|
173
179
|
_error = null;
|
|
174
180
|
/** --- 还未开启 close 监听时是不是就已经 close --- */
|
|
@@ -183,13 +189,44 @@ export class Socket {
|
|
|
183
189
|
end: undefined,
|
|
184
190
|
timeout: undefined,
|
|
185
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* --- 暂存尚不能交给上层处理的消息 ---
|
|
194
|
+
* @param msg 消息
|
|
195
|
+
*/
|
|
196
|
+
_queueMessage(msg) {
|
|
197
|
+
this._waitMsgBytes += msg.data.length;
|
|
198
|
+
if ((this._waitMsgBytes > MAX_PENDING_MESSAGE_BYTES) ||
|
|
199
|
+
(this._waitMsg.length >= MAX_PENDING_MESSAGES)) {
|
|
200
|
+
this._waitMsg.length = 0;
|
|
201
|
+
this._waitMsgBytes = 0;
|
|
202
|
+
this.destroy();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
this._waitMsg.push(msg);
|
|
206
|
+
}
|
|
207
|
+
/** --- 依次派发缓存消息,若再次发生背压则停止 --- */
|
|
208
|
+
_flushMessages() {
|
|
209
|
+
if (this._paused || !this._on.message || !this._waitMsg.length) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const messages = this._waitMsg.splice(0);
|
|
213
|
+
this._waitMsgBytes = 0;
|
|
214
|
+
for (let i = 0; i < messages.length; ++i) {
|
|
215
|
+
if (this._paused) {
|
|
216
|
+
for (; i < messages.length; ++i) {
|
|
217
|
+
this._waitMsg.push(messages[i]);
|
|
218
|
+
this._waitMsgBytes += messages[i].data.length;
|
|
219
|
+
}
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this._on.message(messages[i]);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
186
225
|
on(event, cb) {
|
|
187
226
|
this._on[event] = cb;
|
|
188
227
|
switch (event) {
|
|
189
228
|
case 'message': {
|
|
190
|
-
|
|
191
|
-
cb(item);
|
|
192
|
-
}
|
|
229
|
+
this._flushMessages();
|
|
193
230
|
break;
|
|
194
231
|
}
|
|
195
232
|
case 'error': {
|
|
@@ -227,6 +264,15 @@ export class Socket {
|
|
|
227
264
|
destroy() {
|
|
228
265
|
this._ws.destroy();
|
|
229
266
|
}
|
|
267
|
+
/** --- 暂停向消息监听器派发数据,底层仍只保留有界缓存 --- */
|
|
268
|
+
pause() {
|
|
269
|
+
this._paused = true;
|
|
270
|
+
}
|
|
271
|
+
/** --- 恢复向消息监听器派发数据 --- */
|
|
272
|
+
resume() {
|
|
273
|
+
this._paused = false;
|
|
274
|
+
this._flushMessages();
|
|
275
|
+
}
|
|
230
276
|
/** --- 发送文本 --- */
|
|
231
277
|
writeText(data) {
|
|
232
278
|
if (!this._ws.writable) {
|
|
@@ -311,69 +357,93 @@ export function createServer(request, socket, head, options = {}) {
|
|
|
311
357
|
*/
|
|
312
358
|
function bindPipe(s1, s2) {
|
|
313
359
|
return new Promise(resolve => {
|
|
360
|
+
/** --- 是否已经完成关闭,防止双向 close 重复处理 --- */
|
|
361
|
+
let closed = false;
|
|
362
|
+
/** --- 两端一起销毁,避免半开连接继续占用资源 --- */
|
|
363
|
+
const close = () => {
|
|
364
|
+
if (closed) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
closed = true;
|
|
368
|
+
s1.destroy();
|
|
369
|
+
s2.destroy();
|
|
370
|
+
resolve();
|
|
371
|
+
};
|
|
314
372
|
// --- 监听发送端的 ---
|
|
315
373
|
s1.on('message', (msg) => {
|
|
316
374
|
switch (msg.opcode) {
|
|
317
375
|
case EOpcode.TEXT: {
|
|
318
|
-
s2.writeText(msg.data.toString())
|
|
376
|
+
if (!s2.writeText(msg.data.toString())) {
|
|
377
|
+
s1.pause();
|
|
378
|
+
}
|
|
319
379
|
break;
|
|
320
380
|
}
|
|
321
381
|
case EOpcode.BINARY: {
|
|
322
|
-
s2.writeBinary(msg.data)
|
|
382
|
+
if (!s2.writeBinary(msg.data)) {
|
|
383
|
+
s1.pause();
|
|
384
|
+
}
|
|
323
385
|
break;
|
|
324
386
|
}
|
|
325
387
|
case EOpcode.CLOSE: {
|
|
326
|
-
|
|
327
|
-
resolve();
|
|
388
|
+
close();
|
|
328
389
|
break;
|
|
329
390
|
}
|
|
330
391
|
case EOpcode.PING: {
|
|
331
|
-
s2.ping(msg.data)
|
|
392
|
+
if (!s2.ping(msg.data)) {
|
|
393
|
+
s1.pause();
|
|
394
|
+
}
|
|
332
395
|
break;
|
|
333
396
|
}
|
|
334
397
|
case EOpcode.PONG: {
|
|
335
|
-
s2.pong(msg.data)
|
|
398
|
+
if (!s2.pong(msg.data)) {
|
|
399
|
+
s1.pause();
|
|
400
|
+
}
|
|
336
401
|
break;
|
|
337
402
|
}
|
|
338
403
|
default: {
|
|
339
404
|
// --- EOpcode.CONTINUATION ---
|
|
340
405
|
}
|
|
341
406
|
}
|
|
342
|
-
}).on('close', () => {
|
|
343
|
-
s2.
|
|
344
|
-
resolve();
|
|
407
|
+
}).on('close', close).on('drain', () => {
|
|
408
|
+
s2.resume();
|
|
345
409
|
});
|
|
346
410
|
// --- 监听远程端的 ---
|
|
347
411
|
s2.on('message', (msg) => {
|
|
348
412
|
switch (msg.opcode) {
|
|
349
413
|
case EOpcode.TEXT: {
|
|
350
|
-
s1.writeText(msg.data.toString())
|
|
414
|
+
if (!s1.writeText(msg.data.toString())) {
|
|
415
|
+
s2.pause();
|
|
416
|
+
}
|
|
351
417
|
break;
|
|
352
418
|
}
|
|
353
419
|
case EOpcode.BINARY: {
|
|
354
|
-
s1.writeBinary(msg.data)
|
|
420
|
+
if (!s1.writeBinary(msg.data)) {
|
|
421
|
+
s2.pause();
|
|
422
|
+
}
|
|
355
423
|
break;
|
|
356
424
|
}
|
|
357
425
|
case EOpcode.CLOSE: {
|
|
358
|
-
|
|
359
|
-
resolve();
|
|
426
|
+
close();
|
|
360
427
|
break;
|
|
361
428
|
}
|
|
362
429
|
case EOpcode.PING: {
|
|
363
|
-
s1.ping(msg.data)
|
|
430
|
+
if (!s1.ping(msg.data)) {
|
|
431
|
+
s2.pause();
|
|
432
|
+
}
|
|
364
433
|
break;
|
|
365
434
|
}
|
|
366
435
|
case EOpcode.PONG: {
|
|
367
|
-
s1.pong(msg.data)
|
|
436
|
+
if (!s1.pong(msg.data)) {
|
|
437
|
+
s2.pause();
|
|
438
|
+
}
|
|
368
439
|
break;
|
|
369
440
|
}
|
|
370
441
|
default: {
|
|
371
442
|
// --- EOpcode.CONTINUATION ---
|
|
372
443
|
}
|
|
373
444
|
}
|
|
374
|
-
}).on('close', () => {
|
|
375
|
-
s1.
|
|
376
|
-
resolve();
|
|
445
|
+
}).on('close', close).on('drain', () => {
|
|
446
|
+
s1.resume();
|
|
377
447
|
});
|
|
378
448
|
});
|
|
379
449
|
}
|