senchalabs / connect

Connect is a middleware layer for Node.js
MIT License
9.83k stars 1.09k forks source link

express.bodyParser({intended for formidable}) not assigning listeners #565

Closed rayie closed 12 years ago

rayie commented 12 years ago

minor feature request if opts contain keys matching formidable event names such as "progress" and "fileBegin", they are not added as listeners but just plain key/val pairs on form

bodyParser.js (line 157)

157   Object.keys(options).forEach(function(key){
158     form[key] = options[key];
159   });

Not finding any other hook to the formidable.IncomingForm object, exposed by express, so no other oppotunity to add listeners to it when using app.use(express.bodyParser({...})

Maybe change to this:

157   Object.keys(options).forEach(function(key){
158     if (typeof options[key]=="function" )
159         form.on(key, options[key]);
160     else form[key] = options[key];
161   });

??

tj commented 12 years ago

this was why I broke bodyParser into multipart(), json() and urlencoded(), so that if you want to use formidable directly you can just omit multipart(). In the near future (or now if you only care about modern browsers) you dont need the server for progress updates anyway, but it would be cleaner to omit multipart() and use formidable directly if you're using events

rayie commented 12 years ago

Sounds good. I'll do that. Thanks.