Skip to content

Commit

Permalink
Set this to request on socket event.
Browse files Browse the repository at this point in the history
This makes behavior consistent with the Node.js HTTP module
(https://github.com/nodejs/node/blob/v6.0.0/lib/_http_client.js#L541).
  • Loading branch information
RubenVerborgh committed Dec 8, 2016
1 parent 9ee2984 commit 50859e5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/request_overrider.js
Expand Up @@ -193,7 +193,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
req.once = req.on = function(event, listener) {
// emit a fake socket.
if (event == 'socket') {
listener(req.socket);
listener.call(req, req.socket);
req.socket.emit('connect', req.socket);
req.socket.emit('secureConnect', req.socket);
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_intercept.js
Expand Up @@ -4212,6 +4212,7 @@ test('request emits socket', function(t) {

var req = http.get('http://gotzsocketz.com');
req.once('socket', function(socket) {
t.equal(this, req);
t.type(socket, Object);
t.type(socket.getPeerCertificate(), 'string');
t.end();
Expand Down

0 comments on commit 50859e5

Please sign in to comment.