Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Sep 15, 2024
1 parent e9d5b99 commit e206b1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/core/httpclient4.js → lib/core/httpclient_allow_h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand All @@ -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,
Expand Down Expand Up @@ -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,
});
}
Expand All @@ -58,4 +58,4 @@ function normalizeConfig(app) {
}
}

module.exports = HttpClient4;
module.exports = HttpClientAllowH2;
8 changes: 4 additions & 4 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e206b1d

Please sign in to comment.