Streaming callback gets called an extra time
iangreenleaf opened this issue · 1 comments
iangreenleaf commented
I'm trying to stream a request, but I'm running into weird behavior. Here's my test code, cribbed from your examples:
var scopedClient = require('scoped-http-client')
, util = require('util')
var client = scopedClient.create('https://github.com/api/v2/json')
.header('accept', 'application/json')
.path('user/show/technoweenie')
client.get(function (err, req) {
if (err) util.puts(err);
req.addListener('response', function (resp) {
resp.addListener('data', function (chunk) {
util.puts("CHUNK: " + chunk)
})
})
})()
Which gets me this output:
CHUNK: {"user":{"gravatar_id":"..."...}}
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot call method 'addListener' of undefined
at ClientRequest.<anonymous> (/Users/ian/code/amco_hubot/foo.js:9:7)
at ClientRequest.emit (events.js:64:17)
at CleartextStream.<anonymous> (http.js:1200:11)
at CleartextStream.emit (events.js:64:17)
at Array.0 (tls.js:792:22)
at EventEmitter._tickCallback (node.js:192:40)
It looks like the callback is being invoked twice, once with the proper request object, and again with nil values.
iangreenleaf commented
Closed by #6.