~ps-jenkins/ubuntu-push/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to docs/example-server/node_modules/supertest/node_modules/superagent/node_modules/formidable/test/standalone/test-content-transfer-encoding.js

  • Committer: Roberto Alsina
  • Date: 2014-09-05 14:57:17 UTC
  • mto: (91.179.25 automatic)
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: roberto.alsina@canonical.com-20140905145717-0ufcsv27w25i1nnu
added example app server

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
});