egg 3.25.0 → 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.
@@ -2,13 +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
- const config = app.config.httpclient;
7
+ options = options || {};
8
+ options = {
9
+ ...app.config.httpclient,
10
+ ...options,
11
+ };
8
12
  super({
9
13
  app,
10
- defaultArgs: config.request,
11
- allowH2: config.allowH2,
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,
12
19
  });
13
20
  this.app = app;
14
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
- if (this.config.httpclient.useHttpClientNext) {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "egg",
3
- "version": "3.25.0",
3
+ "version": "3.26.0",
4
4
  "publishConfig": {
5
5
  "tag": "release-3.x",
6
6
  "access": "public"