mikeal/request — pull request #623 by AndreasMadsen (2013-08-12 11:26:11+00:00)
Title: fix error listener leak on connection object

This should fix #622

When `onRequest` was called multiply times this line would be executed:

```javascript
if (response.connection.listeners('error').indexOf(self._parserErrorHandler) === -1) {
response.connection.once('error', self._parserErrorHandler)
}
```

however because the `EventEmitter.once(fn)` method don't add `fn` to the internal events object but rather a function there executes `fn` and calls `EventEmitter.removeListener` (see: [node/events.js](https://github.com/joyent/node/blob/master/lib/events.js#L185-191)) the `this._parserErrorHandler` method would never be in the `listeners('error')` array.

This changes `indexOf(self._parserErrorHandler) === -1` to just `.length === 0`. Alternativ fixes are to use the `.on` method, or check the internal `.listener` property on each item in the `listeners('error')` array.

**I'm not intiment with `request` so I couldn't figure out why `onRequest` was called multiply times (I guess it's caused by redirects) and therefore there are no added test**