From e206b1d815ac324d2fff0c212e0d68a029cb9e8f Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sun, 15 Sep 2024 18:42:23 +0800 Subject: [PATCH] f --- lib/core/{httpclient4.js => httpclient_allow_h2.js} | 8 ++++---- lib/egg.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename lib/core/{httpclient4.js => httpclient_allow_h2.js} (90%) diff --git a/lib/core/httpclient4.js b/lib/core/httpclient_allow_h2.js similarity index 90% rename from lib/core/httpclient4.js rename to lib/core/httpclient_allow_h2.js index 2ec166a22e..66be1edf82 100644 --- a/lib/core/httpclient4.js +++ b/lib/core/httpclient_allow_h2.js @@ -2,7 +2,7 @@ const { HttpClient } = require('urllib4'); const ms = require('humanize-ms'); const SSRF_HTTPCLIENT = Symbol('SSRF_HTTPCLIENT'); -class HttpClient4 extends HttpClient { +class HttpClientAllowH2 extends HttpClient { constructor(app, options) { normalizeConfig(app); options = options || {}; @@ -13,7 +13,7 @@ class HttpClient4 extends HttpClient { super({ app, defaultArgs: options.request, - allowH2: options.allowH2, + allowH2: true, // use on egg-security ssrf // https://github.com/eggjs/egg-security/blob/master/lib/extend/safe_curl.js#L11 checkAddress: options.checkAddress, @@ -43,7 +43,7 @@ class HttpClient4 extends HttpClient { } else { this.app.logger.warn('[egg-security] please configure `config.security.ssrf` first'); } - this[SSRF_HTTPCLIENT] = new HttpClient4(this.app, { + this[SSRF_HTTPCLIENT] = new HttpClientAllowH2(this.app, { checkAddress: ssrfConfig.checkAddress, }); } @@ -58,4 +58,4 @@ function normalizeConfig(app) { } } -module.exports = HttpClient4; +module.exports = HttpClientAllowH2; diff --git a/lib/egg.js b/lib/egg.js index 33ed380152..65fcbc4f2f 100644 --- a/lib/egg.js +++ b/lib/egg.js @@ -20,11 +20,11 @@ const utils = require('./core/utils'); const BaseContextClass = require('./core/base_context_class'); const BaseHookClass = require('./core/base_hook_class'); -let HttpClient4 = HttpClientNext; +let HttpClientAllowH2 = HttpClientNext; const mainNodejsVersion = parseInt(process.versions.node.split('.')[0]); if (mainNodejsVersion >= 18) { // urllib@4 only works on Node.js >= 18 - HttpClient4 = require('./core/httpclient4'); + HttpClientAllowH2 = require('./core/httpclient_allow_h2'); } const HTTPCLIENT = Symbol('EggApplication#httpclient'); @@ -58,7 +58,7 @@ class EggApplication extends EggCore { this.ContextHttpClient = ContextHttpClient; this.HttpClient = HttpClient; this.HttpClientNext = HttpClientNext; - this.HttpClient4 = HttpClient4; + this.HttpClientAllowH2 = HttpClientAllowH2; this.loader.loadConfig(); @@ -301,7 +301,7 @@ class EggApplication extends EggCore { createHttpClient(options) { let httpClient; if (this.config.httpclient.allowH2) { - httpClient = new this.HttpClient4(this, options); + httpClient = new this.HttpClientAllowH2(this, options); } else if (this.config.httpclient.useHttpClientNext) { httpClient = new this.HttpClientNext(this, options); } else if (this.config.httpclient.enableDNSCache) {