comunicationLeap/node_modules/formidable/test/standalone/test-connection-aborted.js
node_modules/formidable/test/standalone/test-connection-aborted.jsRaw
1var assert = require('assert');
2var http = require('http');
3var net = require('net');
4var formidable = require('../../lib/index');
5
6var server = http.createServer(function (req, res) {
7 var form = new formidable.IncomingForm();
8 var aborted_received = false;
9 form.on('aborted', function () {
10 aborted_received = true;
11 });
12 form.on('error', function () {
13 assert(aborted_received, 'Error event should follow aborted');
14 server.close();
15 });
16 form.on('end', function () {
17 throw new Error('Unexpected "end" event');
18 });
19 form.parse(req);
20}).listen(0, 'localhost', function () {
21 var client = net.connect(server.address().port);
22 client.write(
23 "POST / HTTP/1.1\r\n" +
24 "Content-Length: 70\r\n" +
25 "Content-Type: multipart/form-data; boundary=foo\r\n\r\n");
26 client.end();
27});