Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Fix test-http-conn-reset.js on OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Oct 13, 2011
1 parent 39987cb commit 3a34972
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/http.js
Expand Up @@ -1071,6 +1071,14 @@ ClientRequest.prototype.abort = function() {
}
};


function createHangUpError() {
var error = new Error('socket hang up');
error.code = 'ECONNRESET';
return error;
}


ClientRequest.prototype.onSocket = function(socket) {
var req = this;
process.nextTick(function () {
Expand Down Expand Up @@ -1128,7 +1136,7 @@ ClientRequest.prototype.onSocket = function(socket) {
if (!req.res) {
// If we don't have a response then we know that the socket
// ended prematurely and we need to emit an error on the request.
req.emit('error', new Error("Request ended prematurely."));
req.emit('error', createHangUpError());
req._hadError = true;
}
parser.finish();
Expand All @@ -1148,9 +1156,7 @@ ClientRequest.prototype.onSocket = function(socket) {
// This socket error fired before we started to
// receive a response. The error needs to
// fire on the request.
var error = new Error('socket hang up');
error.code = 'ECONNRESET';
req.emit('error', error);
req.emit('error', createHangUpError());
}
}
socket.on('close', closeListener);
Expand Down
2 changes: 1 addition & 1 deletion test/simple/test-http-conn-reset.js
Expand Up @@ -44,8 +44,8 @@ function onListen() {
assert.ok(false, 'this should never run');
});
req.on('error', function(err) {
assert.equal(err.message, 'socket hang up');
assert.equal(err.code, 'ECONNRESET');
assert.equal(err.message, 'socket hang up');
caughtError = true;
});
req.end();
Expand Down

0 comments on commit 3a34972

Please sign in to comment.