Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use .once() when listening for parser error
Also remove parser error listener when finished
  • Loading branch information
mscdex committed Jul 28, 2012
1 parent 975ea90 commit 205dfd2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main.js
Expand Up @@ -509,7 +509,7 @@ Request.prototype.start = function () {


self.req = self.httpModule.request(self, function (response) { self.req = self.httpModule.request(self, function (response) {
if (response.connection.listeners('error').indexOf(self._parserErrorHandler) === -1) { if (response.connection.listeners('error').indexOf(self._parserErrorHandler) === -1) {
response.connection.on('error', self._parserErrorHandler) response.connection.once('error', self._parserErrorHandler)
} }
if (self._aborted) return if (self._aborted) return
if (self._paused) response.pause() if (self._paused) response.pause()
Expand Down Expand Up @@ -677,7 +677,9 @@ Request.prototype.start = function () {
self.req.on('drain', function() { self.req.on('drain', function() {
self.emit('drain') self.emit('drain')
}) })

self.on('end', function() {
self.req.connection.removeListener('error', self._parserErrorHandler)
})
self.emit('request', self.req) self.emit('request', self.req)
} }


Expand Down

0 comments on commit 205dfd2

Please sign in to comment.