Skip to content

Commit 9552eee

Browse files
committed
fix: res.socket is null in node-v14.x
res.socket has been detached from IncomingMessage in node-v14.x Reference: nodejs/node#32153
1 parent e4e9137 commit 9552eee

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_js:
55
- '8'
66
- '10'
77
- '12'
8+
- '14'
89
script:
910
- npm run ci
1011
after_script:

lib/urllib.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ exports.requestThunk = function requestThunk(url, args) {
196196
};
197197

198198
function requestWithCallback(url, args, callback) {
199+
var req;
199200
// requestWithCallback(url, callback)
200201
if (!url || (typeof url !== 'string' && typeof url !== 'object')) {
201202
var msg = util.format('expect request url to be a string or a http request options, but got %j', url);
@@ -592,10 +593,11 @@ function requestWithCallback(url, args, callback) {
592593
if (serverSocketTimeout < freeSocketTimeout) {
593594
// https://github.com/node-modules/agentkeepalive/blob/master/lib/agent.js#L127
594595
// agentkeepalive@4
596+
var socket = res.socket || (req && req.socket);
595597
if (agent.options && agent.options.freeSocketTimeout) {
596-
res.socket.freeSocketTimeout = serverSocketTimeout;
598+
socket.freeSocketTimeout = serverSocketTimeout;
597599
} else {
598-
res.socket.freeSocketKeepAliveTimeout = serverSocketTimeout;
600+
socket.freeSocketKeepAliveTimeout = serverSocketTimeout;
599601
}
600602
}
601603
}
@@ -966,7 +968,6 @@ function requestWithCallback(url, args, callback) {
966968
}
967969
}
968970

969-
var req;
970971
// request headers checker will throw error
971972
try {
972973
req = httplib.request(options, onResponse);

0 commit comments

Comments
 (0)