Skip to content

Instantly share code, notes, and snippets.

@dannycoates
Created September 15, 2011 19:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannycoates/1220229 to your computer and use it in GitHub Desktop.
Save dannycoates/1220229 to your computer and use it in GitHub Desktop.
ssl test
var http = require('http'), // intentionally using http to connect to https
options = {
host: 'localhost',
port: 4443,
path: '/ping',
};
function pingLoop() {
http.get(options, function (res) {
console.assert(false, "server should never accept http over https");
}).on('error', function (e) {
process.nextTick(pingLoop); // blast it
});
}
pingLoop();
var http = require('https'),
options = {
host: 'localhost',
port: 4443,
path: '/ping',
};
function pingLoop() {
http.get(options, function (res) {
console.log('got statusCode: ' + res.statusCode);
setTimeout(pingLoop, 10);
}).on('error', function (e) {
console.log('got error: ' + e.message);
setTimeout(pingLoop, 10);
});
}
pingLoop();
var https = require('https'),
fs = require('fs');
https.createServer({
key: fs.readFileSync('key.pem'), // use real key here
cert: fs.readFileSync('cert.pem') // use real cert here
},
function (req, res) {
res.end('pong\n');
}
).listen(4443);
@dannycoates
Copy link
Author

In node versions under 0.4.12 an ssl error from one connection can spill over into another when the ssl error list contains more than one entry.

To reproduce, run these scripts concurrently. You will notice that correct.js will hang at some point and stop printing output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment