node-js-libs / curlrequest

A cURL wrapper
MIT License
184 stars 44 forks source link

curl request call callback function before get all stdout stream. #26

Closed floodZero closed 9 years ago

floodZero commented 9 years ago

Hi, chriso. I'm gavin of korea. (So, you could feel odd in my English.)

I found some issue on rapid request situation. When curlrequest.request called rapidly, callback's data argument get "" string often. With no error object and no stdrerr stream. Also i checked packets, and it's good. there's no problem.

And I solved this issue, I think.

I changed bind of "exit" event to "close". And "" string output disappeared.

//Handle curl exit
curl.on('exit', function (code) {
  try {
    err = code;

to

curl.on('close', function (code) {
  try {
    err = code;

According to this API doc, "exit" event can be emitted before stdout stream flushed.

How you think about this modification?

chriso commented 9 years ago

Thanks, it sounds like it should be close rather than exit. I'd be happy to accept a PR with the fix :smile:

floodZero commented 9 years ago

OK, I requested PR from my fork. Thank you. :)