topbit 3.2.0 → 3.2.2

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/README.cn.md CHANGED
@@ -933,9 +933,6 @@ app.run(1234)
933
933
  //url最大长度
934
934
  maxUrlLength: 2048,
935
935
 
936
- //请求上下文缓存池最大数量。
937
- maxpool: 4096,
938
-
939
936
  //子进程汇报资源信息的定时器毫秒数。
940
937
  monitorTimeSlice: 640,
941
938
 
@@ -1936,16 +1933,6 @@ app.run(1234)
1936
1933
 
1937
1934
  ### 7. SNI (HTTPS 多域名支持)
1938
1935
 
1939
- **描述**:用于在同一 IP 地址和端口上支持多个 HTTPS 域名证书的中间件。
1940
-
1941
- 感谢提供源代码。根据代码逻辑,`SNI` 扩展通过 `init` 方法将 `SNICallback` 注入到应用的 `config.server` 配置中,从而利用 Node.js 原生 TLS 的能力实现多域名证书支持。
1942
-
1943
- 以下是补全后的 **SNI** 文档部分:
1944
-
1945
- ---
1946
-
1947
- ### 7. SNI (HTTPS 多域名支持)
1948
-
1949
1936
  **描述**:用于在同一 IP 地址和端口上支持多个 HTTPS 域名证书的中间件。它利用 TLS 协议的 Server Name Indication 特性,根据客户端请求的域名动态加载对应的 SSL 证书。
1950
1937
 
1951
1938
  **注意**:初始化时会同步读取证书文件,请确保路径正确。如果某个域名的证书读取失败,会在控制台输出错误信息,但不会阻塞其他域名的加载。
package/README.md CHANGED
@@ -897,9 +897,6 @@ Full configuration options for app initialization are as follows. Please read th
897
897
  // Max URL length
898
898
  maxUrlLength: 2048,
899
899
 
900
- // Max number of request context cache pool.
901
- maxpool: 4096,
902
-
903
900
  // Timer milliseconds for child process resource reporting.
904
901
  monitorTimeSlice: 640,
905
902
 
package/demo/http2.js CHANGED
@@ -19,7 +19,15 @@ let app = new Topbit({
19
19
  loadInfoFile: '--mem',
20
20
  cert: './cert/localhost-cert.pem',
21
21
  key: './cert/localhost-privkey.pem',
22
- http2: true
22
+ http2: true,
23
+ server: {
24
+ peerMaxConcurrentStreams: 200,
25
+ settings: {
26
+ maxConcurrentStreams: 201,
27
+ maxHeaderListSize: 16384,
28
+ maxHeaderSize: 16384
29
+ }
30
+ }
23
31
  })
24
32
 
25
33
  if (app.isWorker) {
@@ -42,8 +50,32 @@ if (app.isWorker) {
42
50
  })
43
51
  }
44
52
 
53
+ app.on('connection', sock => {
54
+ console.log(sock)
55
+ })
45
56
 
46
57
  app.sched('none')
47
58
  .autoWorker(3)
48
59
  .printServInfo()
49
60
  .daemon(1234, 2)
61
+
62
+ let settings = {
63
+ maxConcurrentStreams: 200,
64
+ maxHeaderListSize: 16384
65
+ }
66
+
67
+ app.on('session', sess => {
68
+ console.log(sess.localSettings, sess.remoteSettings)
69
+
70
+ sess.on('localSettings', s => {
71
+ console.log('local', s)
72
+ })
73
+
74
+ sess.on('remoteSettings', s => {
75
+ console.log('remote', s)
76
+ })
77
+ /* sess.settings(settings, (err, setting, dura) => {
78
+ console.log(setting, dura)
79
+ }) */
80
+
81
+ })
package/demo/loader.js CHANGED
@@ -31,7 +31,7 @@ let app = new Topbit({
31
31
  globalLog : false,
32
32
  logType: 'stdio',
33
33
  loadInfoFile : args.load ? '' : '/tmp/topbit-loadinfo.log',
34
- maxLoadRate: 0.6
34
+ maxLoadRate: 0.85
35
35
  })
36
36
 
37
37
  if (app.isWorker) {
package/demo/monitor.js CHANGED
@@ -33,7 +33,7 @@ const app = new Topbit({
33
33
  globalLog : false,
34
34
  logType: 'stdio',
35
35
  loadInfoFile : args.load ? '' : '/tmp/topbit-loadinfo.log',
36
- maxLoadRate: 0.56
36
+ maxLoadRate: 0.6
37
37
  });
38
38
 
39
39
  app.get('/', async c => {
@@ -46,7 +46,7 @@ app.get('/test', async c => {
46
46
  for (let i = 0; i < 90000; i++) {
47
47
  sum += Math.random() * i;
48
48
  }
49
- c.to({sum});
49
+ c.setHeader(`x-test-${Math.floor(Math.random() * 100)}`, sum).to({sum});
50
50
  }, {group: 'test', name : 'test'});
51
51
 
52
52
  app.post('/test', async c => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topbit",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "A Server-side web framework support http/1.1 and http/2",
5
5
  "main": "src/topbit.js",
6
6
  "directories": {
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  *
5
- * 基于IP的限制,titbit已经能够处理。
5
+ * 基于IP的限制,topbit已经能够处理。
6
6
  *
7
7
  * 此限流针对的是因为http/2协议设计上特点导致单个连接请求密集。
8
8
  *
package/src/http1.js CHANGED
@@ -7,7 +7,6 @@ const process = require('node:process');
7
7
  const logger = require('./logger.js');
8
8
  const {fpurl} = require('./fastParseUrl.js');
9
9
  const Context = require('./context1.js');
10
- const ctxpool = require('./ctxpool.js');
11
10
  const checkHeaderLimit = require('./headerLimit.js');
12
11
  const sendmsg = require('./sendmsg.js');
13
12
 
@@ -25,9 +24,6 @@ class Http1 {
25
24
  this.isWorker = options.isWorker;
26
25
 
27
26
  this.logger = logger;
28
- ctxpool.max = this.config.maxpool;
29
-
30
- this.ctxpool = ctxpool;
31
27
  this.Context = Context;
32
28
  this.fpurl = fpurl;
33
29
  this.host = '';
@@ -109,7 +105,7 @@ class Http1 {
109
105
  return ;
110
106
  }
111
107
 
112
- let ctx = ctxpool.getctx () || new Context();
108
+ let ctx = new Context();
113
109
 
114
110
  ctx.bodyLength = 0;
115
111
  ctx.maxBody = self.config.maxBody;
@@ -134,10 +130,7 @@ class Http1 {
134
130
  ctx.param = rt.args;
135
131
  rt = null;
136
132
 
137
- return self.midware.run(ctx).finally(()=>{
138
- ctxpool.free(ctx);
139
- ctx = null;
140
- });
133
+ return self.midware.run(ctx);
141
134
  };
142
135
 
143
136
  return callback;
package/src/http2.js CHANGED
@@ -5,7 +5,6 @@ const fs = require('node:fs');
5
5
  const process = require('node:process');
6
6
  const logger = require('./logger.js');
7
7
  const {fpurl} = require('./fastParseUrl.js');
8
- const ctxpool = require('./ctxpool.js');
9
8
  const Context = require('./context2.js');
10
9
  const checkHeaderLimit = require('./headerLimit.js');
11
10
  const sendmsg = require('./sendmsg.js');
@@ -25,9 +24,6 @@ class Httpt {
25
24
  this.isWorker = options.isWorker;
26
25
 
27
26
  this.logger = logger;
28
- ctxpool.max = this.config.maxpool;
29
-
30
- this.ctxpool = ctxpool;
31
27
  this.Context = Context;
32
28
  this.fpurl = fpurl;
33
29
 
@@ -114,7 +110,7 @@ class Httpt {
114
110
  stream.close();
115
111
  });
116
112
 
117
- let ctx = ctxpool.getctx() || new Context();
113
+ let ctx = new Context();
118
114
 
119
115
  ctx.bodyLength = 0;
120
116
  ctx.maxBody = self.config.maxBody;
@@ -128,10 +124,7 @@ class Httpt {
128
124
  ctx.stream = stream;
129
125
  ctx.res = ctx.stream;
130
126
  ctx.req = ctx.stream;
131
-
132
- ctx.dataHeaders = {};
133
127
  ctx.headers = headers;
134
-
135
128
  ctx.path = urlobj.path;
136
129
  ctx.query = urlobj.query;
137
130
  ctx.routepath = rt.key;
@@ -141,10 +134,7 @@ class Httpt {
141
134
  ctx.param = rt.args;
142
135
  rt = null;
143
136
 
144
- return self.midware.run(ctx).finally(() => {
145
- ctxpool.free(ctx);
146
- ctx = null;
147
- });
137
+ return self.midware.run(ctx);
148
138
  };
149
139
 
150
140
  return callback;
@@ -15,30 +15,13 @@ class Middleware extends MidCore {
15
15
  try {
16
16
  await this.exec(ctx, ctx.group);
17
17
  } catch (err) {
18
-
19
18
  this.errorHandle(err, '--ERR-res--');
20
-
21
19
  try {
22
20
  if (ctx.res && !ctx.res.writableEnded) {
23
21
  ctx.res.statusCode = 500;
24
22
  ctx.res.end();
25
23
  }
26
24
  } catch (err) {}
27
-
28
- } finally {
29
- ctx.req = null;
30
- ctx.res = null;
31
- ctx.data = null;
32
- ctx.box = null;
33
- ctx.service = null;
34
- ctx.requestCall = null;
35
- ctx.headers = null;
36
- ctx.body = null;
37
- ctx.rawBody = null;
38
- ctx.files = null;
39
- ctx.param = null;
40
- ctx.user = null;
41
- ctx = null;
42
25
  }
43
26
  }
44
27
 
@@ -16,9 +16,7 @@ class Middleware extends MidCore {
16
16
  try {
17
17
  await this.exec(ctx, ctx.group);
18
18
  } catch (err) {
19
-
20
19
  this.errorHandle(err, '--ERR-RESPONSE--');
21
-
22
20
  if (ctx.stream && !ctx.stream.destroyed && ctx.stream.writable) {
23
21
  try {
24
22
  if (!ctx.stream.headersSent) {
@@ -30,24 +28,7 @@ class Middleware extends MidCore {
30
28
  ctx.stream.end();
31
29
  } catch (err) {}
32
30
  }
33
- } finally {
34
- ctx.data = null;
35
- ctx.dataHeaders = null;
36
- ctx.stream = null;
37
- ctx.req = null;
38
- ctx.res = null;
39
- ctx.service = null;
40
- ctx.box = null;
41
- ctx.requestCall = null;
42
- ctx.body = null;
43
- ctx.headers = null;
44
- ctx.rawBody = null;
45
- ctx.files = null;
46
- ctx.param = null;
47
- ctx.user = null;
48
- ctx = null;
49
31
  }
50
-
51
32
  }
52
33
 
53
34
  /** 这是最终添加的请求中间件。基于洋葱模型,这个中间件最先执行,所以最后会返回响应结果。 */
package/src/topbit.js CHANGED
@@ -155,7 +155,6 @@ class Topbit {
155
155
  * - memFactor {number} 控制内存最大使用量的系数,范围从 -0.45 ~ 0.45,会使用基本系数加上此值并乘以内存总量。默认值0.28。
156
156
  * RSS基本系数是0.52。不要设置的太低,提供比较低的值是为了测试使用。
157
157
  * - maxUrlLength 最大URL长度,包括path和querystring
158
- * - maxpool 请求上下文的最大缓存池数量。
159
158
  * - loadMonitor true|false,表示是否启用负载监控功能,在daemon模式有效,默认为true。
160
159
  * - monitorTimeSlice 子进程获取系统占用资源的定时器时间片,毫秒值,默认为500。
161
160
  * - maxQuery 最大允许的querystring的参数,默认为12。
@@ -240,8 +239,6 @@ class Topbit {
240
239
 
241
240
  maxUrlLength: 1152,
242
241
 
243
- maxpool : 8192,
244
-
245
242
  //子进程汇报资源信息的定时器毫秒数。
246
243
  monitorTimeSlice: 500,
247
244
 
@@ -339,10 +336,6 @@ class Topbit {
339
336
  case 'maxUrlLength':
340
337
  optionsCheck(k, options[k], this.config, {type: 'number', min: 1, max: 4096});
341
338
  break;
342
-
343
- case 'maxpool':
344
- optionsCheck(k, options[k], this.config, {type: 'number', min: 2, max: 50000});
345
- break;
346
339
 
347
340
  case 'monitorTimeSlice':
348
341
  optionsCheck(k, options[k], this.config, {type: 'number', min: 5, max: 10000});
@@ -787,14 +780,20 @@ class Topbit {
787
780
  if (typeof callback === 'function') {
788
781
  this.httpServ.requestError = callback;
789
782
  }
790
- return;
783
+ return this;
791
784
  }
792
-
785
+
786
+ if (this.server && this.server.on) {
787
+ this.server.on(evt, callback);
788
+ return this;
789
+ }
790
+
793
791
  if (!this.eventTable[evt]) {
794
792
  this.eventTable[evt] = [ callback ];
795
793
  } else {
796
794
  this.eventTable[evt].push(callback);
797
795
  }
796
+ return this;
798
797
  }
799
798
 
800
799
  /**
File without changes