egg 3.0.0 → 3.1.0
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/config/config.default.js +2 -0
- package/index.d.ts +2 -0
- package/lib/core/httpclient_next.js +39 -0
- package/lib/egg.js +4 -1
- package/package.json +2 -1
package/config/config.default.js
CHANGED
|
@@ -290,6 +290,7 @@ module.exports = appInfo => {
|
|
|
290
290
|
* @property {Number} httpsAgent.freeSocketTimeout - httpss agent socket keepalive max free time, default is 4000 ms.
|
|
291
291
|
* @property {Number} httpsAgent.maxSockets - https agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
|
|
292
292
|
* @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
|
|
293
|
+
* @property {Boolean} useHttpClientNext - use urllib@3 HttpClient
|
|
293
294
|
*/
|
|
294
295
|
config.httpclient = {
|
|
295
296
|
enableDNSCache: false,
|
|
@@ -311,6 +312,7 @@ module.exports = appInfo => {
|
|
|
311
312
|
maxSockets: Number.MAX_SAFE_INTEGER,
|
|
312
313
|
maxFreeSockets: 256,
|
|
313
314
|
},
|
|
315
|
+
useHttpClientNext: false,
|
|
314
316
|
};
|
|
315
317
|
|
|
316
318
|
/**
|
package/index.d.ts
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { HttpClient } = require('urllib-next');
|
|
4
|
+
const ms = require('humanize-ms');
|
|
5
|
+
|
|
6
|
+
class HttpClientNext extends HttpClient {
|
|
7
|
+
constructor(app) {
|
|
8
|
+
normalizeConfig(app);
|
|
9
|
+
const config = app.config.httpclient;
|
|
10
|
+
super({
|
|
11
|
+
app,
|
|
12
|
+
defaultArgs: config.request,
|
|
13
|
+
});
|
|
14
|
+
this.app = app;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async request(url, options) {
|
|
18
|
+
options = options || {};
|
|
19
|
+
if (options.ctx && options.ctx.tracer) {
|
|
20
|
+
options.tracer = options.ctx.tracer;
|
|
21
|
+
} else {
|
|
22
|
+
options.tracer = options.tracer || this.app.tracer;
|
|
23
|
+
}
|
|
24
|
+
return await super.request(url, options);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async curl(...args) {
|
|
28
|
+
return await this.request(...args);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function normalizeConfig(app) {
|
|
33
|
+
const config = app.config.httpclient;
|
|
34
|
+
if (typeof config.request.timeout === 'string') {
|
|
35
|
+
config.request.timeout = ms(config.request.timeout);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = HttpClientNext;
|
package/lib/egg.js
CHANGED
|
@@ -15,6 +15,7 @@ const ContextHttpClient = require('./core/context_httpclient');
|
|
|
15
15
|
const Messenger = require('./core/messenger');
|
|
16
16
|
const DNSCacheHttpClient = require('./core/dnscache_httpclient');
|
|
17
17
|
const HttpClient = require('./core/httpclient');
|
|
18
|
+
const HttpClientNext = require('./core/httpclient_next');
|
|
18
19
|
const createLoggers = require('./core/logger');
|
|
19
20
|
const Singleton = require('./core/singleton');
|
|
20
21
|
const utils = require('./core/utils');
|
|
@@ -291,7 +292,9 @@ class EggApplication extends EggCore {
|
|
|
291
292
|
*/
|
|
292
293
|
get httpclient() {
|
|
293
294
|
if (!this[HTTPCLIENT]) {
|
|
294
|
-
if (this.config.httpclient.
|
|
295
|
+
if (this.config.httpclient.useHttpClientNext) {
|
|
296
|
+
this[HTTPCLIENT] = new HttpClientNext(this);
|
|
297
|
+
} else if (this.config.httpclient.enableDNSCache) {
|
|
295
298
|
this[HTTPCLIENT] = new DNSCacheHttpClient(this);
|
|
296
299
|
} else {
|
|
297
300
|
this[HTTPCLIENT] = new this.HttpClient(this);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "egg",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A web framework's framework for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"semver": "^7.3.2",
|
|
54
54
|
"sendmessage": "^1.1.0",
|
|
55
55
|
"urllib": "^2.33.0",
|
|
56
|
+
"urllib-next": "^3.1.1",
|
|
56
57
|
"utility": "^1.15.0",
|
|
57
58
|
"ylru": "^1.2.1"
|
|
58
59
|
},
|