egg 3.24.1 → 3.26.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/README.md +2 -4
- package/config/config.default.js +2 -0
- package/index.d.ts +5 -3
- package/lib/core/httpclient_next.js +11 -3
- package/lib/egg.js +17 -7
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -9,12 +9,11 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
9
9
|
[](https://npmjs.org/package/egg)
|
|
10
10
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fegg?ref=badge_shield)
|
|
11
11
|
|
|
12
|
-
[](https://github.com/eggjs/egg/actions?query=branch%
|
|
12
|
+
[](https://github.com/eggjs/egg/actions?query=branch%3A3.x)
|
|
13
13
|
[](https://codecov.io/gh/eggjs/egg)
|
|
14
14
|
[](https://snyk.io/test/npm/egg)
|
|
15
15
|
[](https://opencollective.com/eggjs)
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
## Features
|
|
19
18
|
|
|
20
19
|
- Built-in Process Management
|
|
@@ -62,5 +61,4 @@ To become a contributor, please follow our [contributing guide](CONTRIBUTING.md)
|
|
|
62
61
|
|
|
63
62
|
[MIT](LICENSE)
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
[](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fegg?ref=badge_large)
|
|
64
|
+
[](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fegg?ref=badge_large)
|
package/config/config.default.js
CHANGED
|
@@ -304,6 +304,7 @@ module.exports = appInfo => {
|
|
|
304
304
|
* @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
|
|
305
305
|
* @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
|
|
306
306
|
* @property {Boolean} useHttpClientNext - use urllib@3 HttpClient
|
|
307
|
+
* @property {Boolean} allowH2 - Allow to use HTTP2 first, only work on `useHttpClientNext = true`
|
|
307
308
|
*/
|
|
308
309
|
config.httpclient = {
|
|
309
310
|
enableDNSCache: false,
|
|
@@ -326,6 +327,7 @@ module.exports = appInfo => {
|
|
|
326
327
|
maxFreeSockets: 256,
|
|
327
328
|
},
|
|
328
329
|
useHttpClientNext: false,
|
|
330
|
+
// allowH2: false,
|
|
329
331
|
};
|
|
330
332
|
|
|
331
333
|
/**
|
package/index.d.ts
CHANGED
|
@@ -296,16 +296,18 @@ declare module 'egg' {
|
|
|
296
296
|
request?: HttpClientRequestOptions | RequestOptionsOld;
|
|
297
297
|
/** Whether enable dns cache */
|
|
298
298
|
enableDNSCache?: boolean;
|
|
299
|
-
/** Enable proxy request
|
|
299
|
+
/** Enable proxy request. Default is `false`. */
|
|
300
300
|
enableProxy?: boolean;
|
|
301
|
-
/** proxy agent uri or options
|
|
301
|
+
/** proxy agent uri or options. Default is `null`. */
|
|
302
302
|
proxy?: string | { [key: string]: any };
|
|
303
303
|
/** DNS cache lookup interval */
|
|
304
304
|
dnsCacheLookupInterval?: number;
|
|
305
305
|
/** DNS cache max age */
|
|
306
306
|
dnsCacheMaxLength?: number;
|
|
307
|
-
/** use urllib@3 HttpClient */
|
|
307
|
+
/** use urllib@3 HttpClient. Default is `false` */
|
|
308
308
|
useHttpClientNext?: boolean;
|
|
309
|
+
/** Allow to use HTTP2 first, only work on `useHttpClientNext = true`. Default is `false` */
|
|
310
|
+
allowH2?: boolean;
|
|
309
311
|
}
|
|
310
312
|
|
|
311
313
|
export interface EggAppConfig {
|
|
@@ -2,12 +2,20 @@ const { HttpClient } = require('urllib-next');
|
|
|
2
2
|
const ms = require('humanize-ms');
|
|
3
3
|
|
|
4
4
|
class HttpClientNext extends HttpClient {
|
|
5
|
-
constructor(app) {
|
|
5
|
+
constructor(app, options) {
|
|
6
6
|
normalizeConfig(app);
|
|
7
|
-
|
|
7
|
+
options = options || {};
|
|
8
|
+
options = {
|
|
9
|
+
...app.config.httpclient,
|
|
10
|
+
...options,
|
|
11
|
+
};
|
|
8
12
|
super({
|
|
9
13
|
app,
|
|
10
|
-
defaultArgs:
|
|
14
|
+
defaultArgs: options.request,
|
|
15
|
+
allowH2: options.allowH2,
|
|
16
|
+
// use on egg-security ssrf
|
|
17
|
+
// https://github.com/eggjs/egg-security/blob/master/lib/extend/safe_curl.js#L11
|
|
18
|
+
checkAddress: options.checkAddress,
|
|
11
19
|
});
|
|
12
20
|
this.app = app;
|
|
13
21
|
}
|
package/lib/egg.js
CHANGED
|
@@ -286,6 +286,22 @@ class EggApplication extends EggCore {
|
|
|
286
286
|
return await this.httpclient.request(url, opts);
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
/**
|
|
290
|
+
* Create a new HttpClient instance with custom options
|
|
291
|
+
* @param {Object} [options] HttpClient init options
|
|
292
|
+
*/
|
|
293
|
+
createHttpClient(options) {
|
|
294
|
+
let httpClient;
|
|
295
|
+
if (this.config.httpclient.useHttpClientNext) {
|
|
296
|
+
httpClient = new this.HttpClientNext(this, options);
|
|
297
|
+
} else if (this.config.httpclient.enableDNSCache) {
|
|
298
|
+
httpClient = new DNSCacheHttpClient(this, options);
|
|
299
|
+
} else {
|
|
300
|
+
httpClient = new this.HttpClient(this, options);
|
|
301
|
+
}
|
|
302
|
+
return httpClient;
|
|
303
|
+
}
|
|
304
|
+
|
|
289
305
|
/**
|
|
290
306
|
* HttpClient instance
|
|
291
307
|
* @see https://github.com/node-modules/urllib
|
|
@@ -293,13 +309,7 @@ class EggApplication extends EggCore {
|
|
|
293
309
|
*/
|
|
294
310
|
get httpclient() {
|
|
295
311
|
if (!this[HTTPCLIENT]) {
|
|
296
|
-
|
|
297
|
-
this[HTTPCLIENT] = new this.HttpClientNext(this);
|
|
298
|
-
} else if (this.config.httpclient.enableDNSCache) {
|
|
299
|
-
this[HTTPCLIENT] = new DNSCacheHttpClient(this);
|
|
300
|
-
} else {
|
|
301
|
-
this[HTTPCLIENT] = new this.HttpClient(this);
|
|
302
|
-
}
|
|
312
|
+
this[HTTPCLIENT] = this.createHttpClient();
|
|
303
313
|
}
|
|
304
314
|
return this[HTTPCLIENT];
|
|
305
315
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "egg",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.26.0",
|
|
4
4
|
"publishConfig": {
|
|
5
|
-
"tag": "
|
|
5
|
+
"tag": "release-3.x",
|
|
6
|
+
"access": "public"
|
|
6
7
|
},
|
|
7
8
|
"description": "A web framework's framework for Node.js",
|
|
8
9
|
"keywords": [
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"onelogger": "^1.0.0",
|
|
55
56
|
"sendmessage": "^2.0.0",
|
|
56
57
|
"urllib": "^2.33.0",
|
|
57
|
-
"urllib-next": "npm:urllib@^3.
|
|
58
|
+
"urllib-next": "npm:urllib@^3.26.0",
|
|
58
59
|
"utility": "^2.1.0",
|
|
59
60
|
"ylru": "^1.3.2"
|
|
60
61
|
},
|