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 6a67a1d commit 140ad0c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ module.exports = appInfo => {
* @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
* @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
* @property {Boolean} useHttpClientNext - use urllib@3 HttpClient, default is false
* @property {Boolean} allowH2 - use urllib@4 HttpClient and enable H2, default is false
* @property {Boolean} allowH2 - use urllib@4 HttpClient and enable H2, default is false. Only works on Node.js >= 18
*/
config.httpclient = {
enableDNSCache: false,
Expand Down
8 changes: 7 additions & 1 deletion lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ const Messenger = require('./core/messenger');
const DNSCacheHttpClient = require('./core/dnscache_httpclient');
const HttpClient = require('./core/httpclient');
const HttpClientNext = require('./core/httpclient_next');
const HttpClient4 = require('./core/httpclient4');
const createLoggers = require('./core/logger');
const Singleton = require('./core/singleton');
const utils = require('./core/utils');
const BaseContextClass = require('./core/base_context_class');
const BaseHookClass = require('./core/base_hook_class');

let HttpClient4 = HttpClientNext;
const mainNodejsVersion = parseInt(process.versions.node.split('.')[0]);
if (mainNodejsVersion >= 18) {
// urllib@4 only works on Node.js >= 18
HttpClient4 = require('./core/httpclient4');
}

const HTTPCLIENT = Symbol('EggApplication#httpclient');
const LOGGERS = Symbol('EggApplication#loggers');
const EGG_PATH = Symbol.for('egg#eggPath');
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/apps/httpclient-tracer/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ module.exports = app => {
});
assert(res.status === 200);

res = await httpclient.request('https://github.com', {
res = await httpclient.request('https://registry.npmmirror.com', {
method: 'GET',
timeout: 20000,
});

assert(res.status === 200);

res = await httpclient.request('https://www.npmjs.com', {
res = await httpclient.request('https://npmmirror.com', {
method: 'GET',
timeout: 20000,
});
Expand Down
4 changes: 2 additions & 2 deletions test/lib/core/httpclient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,13 +589,13 @@ describe('test/lib/core/httpclient.test.js', () => {
});
assert(res.status === 200);

res = await httpclient.request('https://github.com', {
res = await httpclient.request('https://registry.npmmirror.com', {
method: 'GET',
timeout: 20000,
});
assert(res.status === 200);

res = await httpclient.request('https://www.npmjs.com', {
res = await httpclient.request('https://npmmirror.com', {
method: 'GET',
timeout: 20000,
});
Expand Down

0 comments on commit 140ad0c

Please sign in to comment.