Skip to content

Commit

Permalink
Merge pull request #114 from alexindigo/v1.0.0-rc1
Browse files Browse the repository at this point in the history
v1.0.0-rc1
  • Loading branch information
alexindigo committed Jun 13, 2015
2 parents 61adeff + 2c11b01 commit e6650a4
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "0.8"
- "0.10"
- "0.12"
- "iojs"
2 changes: 1 addition & 1 deletion lib/form_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ FormData.prototype.submit = function(params, cb) {
options.headers = this.getHeaders(params.headers);

// https if specified, fallback to http in any other case
if (params.protocol == 'https:') {
if (options.protocol == 'https:') {
request = https.request(options);
} else {
request = http.request(options);
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
"name": "form-data",
"description": "A module to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.",
"version": "0.2.0",
"version": "1.0.0-rc1",
"repository": {
"type": "git",
"url": "git://github.com/felixge/node-form-data.git"
Expand All @@ -12,12 +12,12 @@
"test": "node test/run.js"
},
"engines": {
"node": ">= 0.8"
"node": ">= 0.10"
},
"dependencies": {
"async": "~0.9.0",
"combined-stream": "~0.0.4",
"mime-types": "~2.0.3"
"async": "^1.2.1",
"combined-stream": "^1.0.3",
"mime-types": "^2.1.1"
},
"licenses": [
{
Expand All @@ -26,9 +26,9 @@
}
],
"devDependencies": {
"fake": "~0.2.2",
"far": "~0.0.7",
"formidable": "~1.0.14",
"request": "~2.36.0"
"fake": "^0.2.2",
"far": "^0.0.7",
"formidable": "^1.0.17",
"request": "^2.57.0"
}
}
17 changes: 13 additions & 4 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
var common = module.exports;
var fs = require('fs');
var path = require('path');

var common = module.exports;

var rootDir = path.join(__dirname, '..');
common.dir = {
lib: rootDir + '/lib',
fixture: rootDir + '/test/fixture',
tmp: rootDir + '/test/tmp',
lib: path.join(rootDir, '/lib'),
fixture: path.join(rootDir, '/test/fixture'),
tmp: path.join(rootDir, '/test/tmp'),
};

common.assert = require('assert');
common.fake = require('fake');

common.port = 8432;

common.staticPort = 9432;
common.httpsPort = 9443;

// store server cert in common for later reuse, because self-signed
common.httpsServerKey = fs.readFileSync(path.join(__dirname, './fixture/key.pem'));
common.httpsServerCert = fs.readFileSync(path.join(__dirname, './fixture/cert.pem'));
11 changes: 11 additions & 0 deletions test/fixture/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN CERTIFICATE-----
MIIBnDCCAUYCCQCgIldFYidw0zANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJV
UzELMAkGA1UECBMCQ0ExEjAQBgNVBAcTCVBhbG8gQWx0bzERMA8GA1UEChMIRm9y
bURhdGExEjAQBgNVBAMTCWxvY2FsaG9zdDAeFw0xNTA2MTMxMzA3MTBaFw00MjEw
MjgxMzA3MTBaMFUxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTESMBAGA1UEBxMJ
UGFsbyBBbHRvMREwDwYDVQQKEwhGb3JtRGF0YTESMBAGA1UEAxMJbG9jYWxob3N0
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAOkE8JJzLQbVEo/vRVRqiwNEbiuEooJA
099h1IJLtsPJVphSDBTtE0FLB0YIzT7bG44Drm/975XEZjoQ9TmYbTMCAwEAATAN
BgkqhkiG9w0BAQUFAANBALSDmvKXb4cE622OdSRrDsnr8xUosetsAGSlGauWBKgc
DNQhP6wSQHTAJT8wiVgSPYwnhcnzkZlwzdfMHMtzFIc=
-----END CERTIFICATE-----
9 changes: 9 additions & 0 deletions test/fixture/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBAOkE8JJzLQbVEo/vRVRqiwNEbiuEooJA099h1IJLtsPJVphSDBTt
E0FLB0YIzT7bG44Drm/975XEZjoQ9TmYbTMCAwEAAQJBAMzjTAjpfujoBzdKIwLT
38GStPBM4nt3NxTOt4WNv3kr7QBsUKEB6I3nQfNw5ZmLs7cee9FebaAZXDwoPHvs
p0ECIQD5HgrPnK0LkmfOiEasZ9kGBbaKyEbd84QDTvqwi3izoQIhAO91CgSifv3F
0hitLxgZd4MRYhcos9WyjRkpTojKyDBTAiBf4nFU0cBFSPfNpeRV7a65w68sIcQt
H9K7F0Ykd7pgoQIhAOkKiZ5rGpYVgNvdJ/kXR9V6BHGvfh1acLFtHu5IE73bAiAs
e7X+r8KxH0KmFZU8UJ/snHLbfuotB0ZyYAw6SlTjyQ==
-----END RSA PRIVATE KEY-----
5 changes: 4 additions & 1 deletion test/integration/test-http-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');
var IncomingForm = require('formidable').IncomingForm;

var remoteFile = 'http://nodejs.org/images/logo.png';
// static server prepared for all tests
var remoteFile = 'http://localhost:'+common.staticPort+'/unicycle.jpg';

var FIELDS;
var server;
Expand All @@ -22,6 +23,7 @@ var parsedUrl = parseUrl(remoteFile)
}
;

// request static file
http.request(options, function(res) {

FIELDS = [
Expand Down Expand Up @@ -55,6 +57,7 @@ http.request(options, function(res) {

}).end();

// prepare form-receiving http server
server = http.createServer(function(req, res) {

var form = new IncomingForm({uploadDir: common.dir.tmp});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');
var IncomingForm = require('formidable').IncomingForm;

var remoteFile = 'http://nodejs.org/images/logo.png';
var remoteFile = 'http://localhost:'+common.staticPort+'/unicycle.jpg';

// wrap non simple values into function
// just to deal with ReadStream "autostart"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test-submit-custom-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');
var IncomingForm = require('formidable').IncomingForm;

var remoteFile = 'http://nodejs.org/images/logo.png';
var remoteFile = 'http://localhost:'+common.staticPort+'/unicycle.jpg';

// wrap non simple values into function
// just to deal with ReadStream "autostart"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test-submit-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');
var IncomingForm = require('formidable').IncomingForm;

var remoteFile = 'http://nodejs.org/images/logo.png';
var remoteFile = 'http://localhost:'+common.staticPort+'/unicycle.jpg';

// wrap non simple values into function
// just to deal with ReadStream "autostart"
Expand Down
67 changes: 38 additions & 29 deletions test/integration/test-submit-https.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
var https = require('https');
var common = require('../common');
var assert = common.assert;
var FormData = require(common.dir.lib + '/form_data');
var correctSocket = 'npmjs.org:443';
var server;

// testing default https port
function submitForm() {

// check params as string
testRequest('https://npmjs.org/');
var form = new FormData();

// check params as object
testRequest({protocol: 'https:', hostname: 'npmjs.org', pathname: '/'});
form.append('field', 'value');

// --- Santa's little helpers
form.submit({
protocol: 'https:',
hostname: 'localhost',
port: common.httpsPort,
pathname: '/',
// for self-signed certs on localhost
secureOptions: require('constants').SSL_OP_NO_TLSv1_2,
ca: common.httpsServerCert
}, function(err, res) {

function testRequest(params)
{
var form;
var request;
var sockets;
if (err) {
throw err;
}

form = new FormData();
assert.strictEqual(res.statusCode, 200);
assert.strictEqual(res.headers['x-success'], 'OK');

// break getLength – prevent submit() from actually submitting
form.getLength = function(){};
// unstuck new streams
res.resume();

request = form.submit(params);

sockets = Object.keys(request.agent.sockets);

assert.equal(sockets.length, 1);
server.close();
});
}

// in 0.10 it's "nodomain:443"
// in 0.11 it's "nodomain:443::::::::"
assert.equal(correctSocket, sockets[0].substr(0, correctSocket.length));
// create https server
server = https.createServer({
key: common.httpsServerKey,
cert: common.httpsServerCert
}, function(req, res) {

// stop here
request.abort();
// old and simple
req.on('data', function(){});

request.on('error', function(err){
assert.equal(err.code, 'ECONNRESET');
req.on('end', function()
{
res.writeHead(200, {'x-success': 'OK'});
res.end('Great Success');
});
});

return request;
}
// when https server ready submit form
server.listen(common.httpsPort, submitForm);
2 changes: 1 addition & 1 deletion test/integration/test-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');
var IncomingForm = require('formidable').IncomingForm;

var remoteFile = 'http://nodejs.org/images/logo.png';
var remoteFile = 'http://localhost:'+common.staticPort+'/unicycle.jpg';

// wrap non simple values into function
// just to deal with ReadStream "autostart"
Expand Down
7 changes: 6 additions & 1 deletion test/run.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
var static = require('./static');
var far = require('far').create();

if (process.env.verbose)
Expand All @@ -9,4 +10,8 @@ if (process.env.verbose)
far.add(__dirname);
far.include(/test-.*\.js$/);

far.execute();
// start static server for all tests
static(function()
{
far.execute();
});
31 changes: 31 additions & 0 deletions test/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// serves static files
var http = require('http');
var fs = require('fs');
var path = require('path');
var mime = require('mime-types');
var common = require('./common');

// prepare tmp folder
if (!fs.existsSync(common.dir.tmp))
{
fs.mkdirSync(common.dir.tmp);
}

module.exports = function(callback) {

// create http server
var httpServer = http.createServer(function(req, res) {

var target = path.join(common.dir.fixture, req.url);
var stat = fs.statSync(target);

res.writeHead(200, {
'Content-Type': mime.lookup(target),
'Content-Length': stat.size
});

fs.createReadStream(target).pipe(res);
});

httpServer.listen(common.staticPort, callback.bind(undefined, httpServer));
};
Empty file removed test/tmp/.empty
Empty file.

0 comments on commit e6650a4

Please sign in to comment.