@e-mc/request 0.4.2 → 0.5.1
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.
- package/index.js +16 -7
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -33,6 +33,7 @@ const kConnectDns = Symbol('connectDns');
|
|
|
33
33
|
const kPendingDns = Symbol('pendingDns');
|
|
34
34
|
const kConnectHttp = Symbol('connectHttp');
|
|
35
35
|
const PLATFORM_WIN32 = process.platform === 'win32';
|
|
36
|
+
const SUPPORT_NODEJS20 = module_1.default.supported(20);
|
|
36
37
|
const SUPPORT_ABORTSIGNAL = module_1.default.supported(15, 4);
|
|
37
38
|
const HTTP = {
|
|
38
39
|
HOST: {},
|
|
@@ -570,7 +571,7 @@ class Request extends module_1.default {
|
|
|
570
571
|
for (const hostname in resolve) {
|
|
571
572
|
let { address, family: ipv } = resolve[hostname];
|
|
572
573
|
if (address && (ipv = ipv && ((ipv = +ipv) === 4 || ipv === 6) ? ipv : net.isIPv6(address) ? 6 : net.isIPv4(address) ? 4 : 0)) {
|
|
573
|
-
DNS.CACHE[hostname] = [address, ipv];
|
|
574
|
+
DNS.CACHE[hostname] = [{ address, family: ipv }];
|
|
574
575
|
}
|
|
575
576
|
}
|
|
576
577
|
}
|
|
@@ -815,14 +816,16 @@ class Request extends module_1.default {
|
|
|
815
816
|
}
|
|
816
817
|
break;
|
|
817
818
|
}
|
|
818
|
-
setDnsCache(hostname, this[kConnectDns][hostname] = [address, family]);
|
|
819
|
+
setDnsCache(hostname, this[kConnectDns][hostname] = [{ address, family }]);
|
|
819
820
|
}
|
|
820
821
|
}
|
|
821
822
|
lookupDns(hostname) {
|
|
822
823
|
var _l;
|
|
823
824
|
const resolved = this[kConnectDns][hostname] || DNS.CACHE[hostname];
|
|
824
825
|
if (resolved) {
|
|
825
|
-
return (...args) =>
|
|
826
|
+
return (...args) => {
|
|
827
|
+
return SUPPORT_NODEJS20 ? args[2](null, resolved) : args[2](null, resolved[0].address, resolved[0].family);
|
|
828
|
+
};
|
|
826
829
|
}
|
|
827
830
|
const pending = (_l = this[kPendingDns])[hostname] || (_l[hostname] = []);
|
|
828
831
|
return (value, options, callback) => {
|
|
@@ -830,17 +833,23 @@ class Request extends module_1.default {
|
|
|
830
833
|
const configure = (family) => family === 0 ? options : { family, hints: family === 6 ? dns.V4MAPPED : 0 };
|
|
831
834
|
const success = (connected) => {
|
|
832
835
|
setDnsCache(value, this[kConnectDns][value] = connected);
|
|
833
|
-
|
|
836
|
+
if (SUPPORT_NODEJS20) {
|
|
837
|
+
pending.forEach(cb => cb(null, connected));
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
const { address, family } = connected[0];
|
|
841
|
+
pending.forEach(cb => cb(null, address, family));
|
|
842
|
+
}
|
|
834
843
|
pending.length = 0;
|
|
835
844
|
};
|
|
836
845
|
const failed = (err) => {
|
|
837
|
-
pending.forEach(cb => cb(err, '', 0));
|
|
846
|
+
pending.forEach(cb => SUPPORT_NODEJS20 ? cb(err, []) : cb(err, '', 0));
|
|
838
847
|
pending.length = 0;
|
|
839
848
|
};
|
|
840
849
|
let ipVersion = this.ipVersion;
|
|
841
850
|
dns.lookup(value, configure(ipVersion), (err, address, family) => {
|
|
842
851
|
if (!err) {
|
|
843
|
-
success([address, family]);
|
|
852
|
+
success(typeof address === 'string' ? [{ address, family }] : address);
|
|
844
853
|
}
|
|
845
854
|
else {
|
|
846
855
|
switch (err.code) {
|
|
@@ -865,7 +874,7 @@ class Request extends module_1.default {
|
|
|
865
874
|
}
|
|
866
875
|
dns.lookup(value, configure(ipVersion), (err, address, family) => {
|
|
867
876
|
if (!err) {
|
|
868
|
-
success([address, family]);
|
|
877
|
+
success(typeof address === 'string' ? [{ address, family }] : address);
|
|
869
878
|
}
|
|
870
879
|
else {
|
|
871
880
|
failed(err);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/module": "0.
|
|
24
|
-
"@e-mc/types": "0.
|
|
23
|
+
"@e-mc/module": "0.5.1",
|
|
24
|
+
"@e-mc/types": "0.5.1",
|
|
25
25
|
"combined-stream": "^1.0.8",
|
|
26
26
|
"js-yaml": "^4.1.0",
|
|
27
27
|
"which": "^2.0.2"
|