-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from alexindigo/v1.0.0-rc1
v1.0.0-rc1
- Loading branch information
Showing
15 changed files
with
127 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.