Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrap net.connect failed in node.js 8+ #129

Merged
merged 3 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var shimmer = require('shimmer')

var v6plus = semver.gte(process.version, '6.0.0');
var v7plus = semver.gte(process.version, '7.0.0');
var v8plus = semver.gte(process.version, '8.0.0');

var net = require('net');

Expand Down Expand Up @@ -105,10 +106,18 @@ function patchOnRead(ctx) {

wrap(net.Socket.prototype, 'connect', function (original) {
return function () {
var args;
if (v8plus &&
Array.isArray(arguments[0]) &&
Object.getOwnPropertySymbols(arguments[0]).length > 0) {
// already normalized
args = arguments[0];
} else {
// From Node.js v7.0.0, net._normalizeConnectArgs have been renamed net._normalizeArgs
var args = v7plus
? net._normalizeArgs(arguments)
: net._normalizeConnectArgs(arguments);
args = v7plus
? net._normalizeArgs(arguments)
: net._normalizeConnectArgs(arguments);
}
if (args[1]) args[1] = wrapCallback(args[1]);
var result = original.apply(this, args);
patchOnRead(this);
Expand Down
2 changes: 1 addition & 1 deletion test/http-request.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ test('http.Agent socket reuse works', function(t){
})
];

if (nodeVersion[0] > 4 && nodeVersion[0] < 8) {
if (nodeVersion[0] > 4) {
firstImmediateChildren.push(make('ping #0 request'));
};

Expand Down