egg 3.32.0 → 3.33.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.
Files changed (2) hide show
  1. package/lib/egg.js +47 -3
  2. package/package.json +1 -1
package/lib/egg.js CHANGED
@@ -297,18 +297,62 @@ class EggApplication extends EggCore {
297
297
  */
298
298
  createHttpClient(options = {}) {
299
299
  let httpClient;
300
- options.lookup = options.lookup ?? this.config.httpclient.lookup;
301
-
302
300
  if (this.config.httpclient.useHttpClientNext || this.config.httpclient.allowH2) {
303
- httpClient = new this.HttpClientNext(this, options);
301
+ httpClient = this._createHttpClientNextProxy(options);
304
302
  } else if (this.config.httpclient?.enableDNSCache) {
305
303
  httpClient = new DNSCacheHttpClient(this, options);
306
304
  } else {
305
+ options.lookup = options.lookup ?? this.config.httpclient.lookup;
307
306
  httpClient = new this.HttpClient(this, options);
308
307
  }
309
308
  return httpClient;
310
309
  }
311
310
 
311
+ _createHttpClientNextProxy(options = {}) {
312
+ const self = this;
313
+ let realClient = null;
314
+ const init = () => {
315
+ if (realClient) return;
316
+ options.lookup = options.lookup ?? self.config.httpclient.lookup;
317
+ realClient = new self.HttpClientNext(self, options);
318
+ };
319
+ return new Proxy({}, {
320
+ get(_target, prop) {
321
+ init();
322
+ const value = realClient[prop];
323
+ if (typeof value === 'function') {
324
+ return value.bind(realClient);
325
+ }
326
+ return value;
327
+ },
328
+ set(_target, prop, value) {
329
+ init();
330
+ realClient[prop] = value;
331
+ return true;
332
+ },
333
+ has(_target, prop) {
334
+ init();
335
+ return prop in realClient;
336
+ },
337
+ ownKeys() {
338
+ init();
339
+ return Reflect.ownKeys(realClient);
340
+ },
341
+ getOwnPropertyDescriptor(_target, prop) {
342
+ init();
343
+ return Object.getOwnPropertyDescriptor(realClient, prop);
344
+ },
345
+ deleteProperty(_target, prop) {
346
+ init();
347
+ return delete realClient[prop];
348
+ },
349
+ getPrototypeOf() {
350
+ init();
351
+ return Object.getPrototypeOf(realClient);
352
+ },
353
+ });
354
+ }
355
+
312
356
  /**
313
357
  * HttpClient instance
314
358
  * @see https://github.com/node-modules/urllib
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "egg",
3
- "version": "3.32.0",
3
+ "version": "3.33.0",
4
4
  "publishConfig": {
5
5
  "tag": "release-3.x",
6
6
  "access": "public"