diff --git a/.gitignore b/.gitignore index 6ae115e9..6663ecd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/test/tmp/* \ No newline at end of file +/test/tmp/* +*.upload +*.un~ +/node_modules diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 15339141..00000000 --- a/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -test/tmp/ -*.upload -*.un~ diff --git a/Readme.md b/Readme.md index 7ed859ab..90125f42 100644 --- a/Readme.md +++ b/Readme.md @@ -20,6 +20,20 @@ a big variety of clients and is considered production-ready. ## Changelog +### v1.0.2 + +* Exclude node\_modules folder from git +* Implement new `'aborted'` event +* Fix files in example folder to work with recent node versions + +[See Commits](https://github.com/felixge/node-formidable/compare/v1.0.1...v1.0.2) + +### v1.0.1 + +* Fix package.json to refer to proper main directory. (#68, Dean Landolt) + +[See Commits](https://github.com/felixge/node-formidable/compare/v1.0.0...v1.0.1) + ### v1.0.0 * Add support for multipart boundaries that are quoted strings. (Jeff Craig) @@ -198,6 +212,10 @@ Emitted whenever a field / file pair has been received. `file` is an instance of Emitted when there is an error processing the incoming form. A request that experiences an error is automatically paused, you will have to manually call `request.resume()` if you want the request to continue firing `'data'` events. +#### Event: 'aborted' + +Emitted when the request was aborted by the user. Right now this can be due to a 'timeout' or 'close' event on the socket. In the future there will be a seperate 'timeout' event (needs a change in the node core). + #### Event: 'end' () Emitted when the entire request has been received, and all contained files have finished flushing to disk. This is a great place for you to send your response. diff --git a/benchmark/bench-multipart-parser.js b/benchmark/bench-multipart-parser.js index 89e02950..bff41f15 100644 --- a/benchmark/bench-multipart-parser.js +++ b/benchmark/bench-multipart-parser.js @@ -1,5 +1,5 @@ require('../test/common'); -var multipartParser = require('formidable/multipart_parser'), +var multipartParser = require('../lib/multipart_parser'), MultipartParser = multipartParser.MultipartParser, parser = new MultipartParser(), Buffer = require('buffer').Buffer, @@ -46,7 +46,7 @@ var start = +new Date(), duration = +new Date - start, mbPerSec = (mb / (duration / 1000)).toFixed(2); -p(mbPerSec+' mb/sec'); +console.log(mbPerSec+' mb/sec'); assert.equal(nparsed, buffer.length); diff --git a/example/post.js b/example/post.js index 2d0d57fa..f6c15a64 100644 --- a/example/post.js +++ b/example/post.js @@ -24,11 +24,11 @@ server = http.createServer(function(req, res) { res.end('error:\n\n'+util.inspect(err)); }) .on('field', function(field, value) { - p([field, value]); + console.log(field, value); fields.push([field, value]); }) .on('end', function() { - puts('-> post done'); + console.log('-> post done'); res.writeHead(200, {'content-type': 'text/plain'}); res.end('received fields:\n\n '+util.inspect(fields)); }); @@ -40,4 +40,4 @@ server = http.createServer(function(req, res) { }); server.listen(TEST_PORT); -util.puts('listening on http://localhost:'+TEST_PORT+'/'); +console.log('listening on http://localhost:'+TEST_PORT+'/'); diff --git a/example/upload.js b/example/upload.js index 7ee819ea..050cdd9d 100644 --- a/example/upload.js +++ b/example/upload.js @@ -23,15 +23,15 @@ server = http.createServer(function(req, res) { form .on('field', function(field, value) { - p([field, value]); + console.log(field, value); fields.push([field, value]); }) .on('file', function(field, file) { - p([field, file]); + console.log(field, file); files.push([field, file]); }) .on('end', function() { - puts('-> upload done'); + console.log('-> upload done'); res.writeHead(200, {'content-type': 'text/plain'}); res.write('received fields:\n\n '+util.inspect(fields)); res.write('\n\n'); @@ -45,4 +45,4 @@ server = http.createServer(function(req, res) { }); server.listen(TEST_PORT); -util.puts('listening on http://localhost:'+TEST_PORT+'/'); +console.log('listening on http://localhost:'+TEST_PORT+'/'); diff --git a/lib/incoming_form.js b/lib/incoming_form.js index 4194a738..62c9e3bc 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -69,6 +69,9 @@ IncomingForm.prototype.parse = function(req, cb) { .on('error', function(err) { self._error(err); }) + .on('aborted', function() { + self.emit('aborted'); + }) .on('data', function(buffer) { self.write(buffer); }) diff --git a/package.json b/package.json index bfa76d7c..c0ffdbad 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "formidable", - "version": "1.0.1", - "dependencies": { + "version": "1.0.2", + "dependencies": {}, + "devDependencies": { "gently": ">=0.7.0" }, "directories": { @@ -10,6 +11,5 @@ "main": "./lib/index", "engines": { "node": "*" - }, - "devDependencies": {} + } } \ No newline at end of file diff --git a/test/simple/test-incoming-form.js b/test/simple/test-incoming-form.js index 1c29c4e0..0945abd5 100644 --- a/test/simple/test-incoming-form.js +++ b/test/simple/test-incoming-form.js @@ -60,7 +60,7 @@ test(function parse() { assert.strictEqual(headers, REQ.headers); }); - var events = ['error', 'data', 'end']; + var events = ['error', 'aborted', 'data', 'end']; gently.expect(REQ, 'on', events.length, function(event, fn) { assert.equal(event, events.shift()); emit[event] = fn; @@ -139,6 +139,15 @@ test(function parse() { emit.error(ERR); })(); + (function testEmitAborted() { + gently.expect(form, 'emit',function(event) { + assert.equal(event, 'aborted'); + }); + + emit.aborted(); + })(); + + (function testEmitData() { var BUFFER = [1, 2, 3]; gently.expect(form, 'write', function(buffer) { @@ -181,7 +190,7 @@ test(function parse() { parseCalled = 0; gently.expect(form, 'writeHeaders'); - gently.expect(REQ, 'on', 3, function() { + gently.expect(REQ, 'on', 4, function() { return this; }); @@ -210,7 +219,7 @@ test(function parse() { })); gently.expect(form, 'writeHeaders'); - gently.expect(REQ, 'on', 3, function() { + gently.expect(REQ, 'on', 4, function() { return this; });