Name: js-handler/node_modules/restify/node_modules/formidable/test/standalone/test-content-transfer-encoding.js 
1:
var assert = require('assert');
2:
var common = require('../common');
3:
var formidable = require('../../lib/index');
4:
var http = require('http');
5:
 
6:
var server = http.createServer(function(req, res) {
7:
  var form = new formidable.IncomingForm();
8:
  form.uploadDir = common.dir.tmp;
9:
  form.on('end', function () {
10:
    throw new Error('Unexpected "end" event');
11:
  });
12:
  form.on('error', function (e) {
13:
    res.writeHead(500);
14:
    res.end(e.message);
15:
  });
16:
  form.parse(req);
17:
});
18:
 
19:
server.listen(0, function() {
20:
  var body =
21:
    '--foo\r\n' +
22:
    'Content-Disposition: form-data; name="file1"; filename="file1"\r\n' +
23:
    'Content-Type: application/octet-stream\r\n' +
24:
    '\r\nThis is the first file\r\n' +
25:
    '--foo\r\n' +
26:
    'Content-Type: application/octet-stream\r\n' +
27:
    'Content-Disposition: form-data; name="file2"; filename="file2"\r\n' +
28:
    'Content-Transfer-Encoding: unknown\r\n' +
29:
    '\r\nThis is the second file\r\n' +
30:
    '--foo--\r\n';
31:
 
32:
  var req = http.request({
33:
    method: 'POST',
34:
    port: server.address().port,
35:
    headers: {
36:
      'Content-Length': body.length,
37:
      'Content-Type': 'multipart/form-data; boundary=foo'
38:
    }
39:
  });
40:
  req.on('response', function (res) {
41:
    assert.equal(res.statusCode, 500);
42:
    res.on('data', function () {});
43:
    res.on('end', function () {
44:
      server.close();
45:
    });
46:
  });
47:
  req.end(body);
48:
});