Skip to content

Commit

Permalink
Fixes #194. setTimeout only works on node 0.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal committed Feb 27, 2012
1 parent 0ea2351 commit 5815a69
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,16 @@ Request.prototype.start = function () {

// Set additional timeout on socket - in case if remote
// server freeze after sending headers
self.req.setTimeout(self.timeout, function(){
if (self.req) {
self.req.abort()
var e = new Error("ESOCKETTIMEDOUT")
e.code = "ESOCKETTIMEDOUT"
self.emit("error", e)
}
});
if (self.req.setTimeout) { // only works on node 0.6+
self.req.setTimeout(self.timeout, function(){
if (self.req) {
self.req.abort()
var e = new Error("ESOCKETTIMEDOUT")
e.code = "ESOCKETTIMEDOUT"
self.emit("error", e)
}
})
}
}

self.req.on('error', self.clientErrorHandler)
Expand Down

0 comments on commit 5815a69

Please sign in to comment.