mirror of https://github.com/nodejs/node.git
First pass at new https server
parent
e4dd5cd6fd
commit
94f8368cf9
|
@ -871,6 +871,7 @@ function connectionListener(socket) {
|
|||
return false; // Not a HEAD response. (Not even a response!)
|
||||
};
|
||||
}
|
||||
exports._connectionListener = connectionListener;
|
||||
|
||||
|
||||
function Client() {
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
var tls = require('tls');
|
||||
var http = require('http');
|
||||
var inherits = require('util').inherits;
|
||||
|
||||
|
||||
function Server(opts, requestListener) {
|
||||
if (!(this instanceof Server)) return new Server(opts, requestListener);
|
||||
tls.Server.call(this, opts, http._connectionListener);
|
||||
|
||||
if (requestListener) {
|
||||
this.addListener('request', requestListener);
|
||||
}
|
||||
}
|
||||
inherits(Server, tls.Server);
|
||||
|
||||
|
||||
exports.Server = Server;
|
||||
|
||||
|
||||
exports.createServer = function(opts, requestListener) {
|
||||
return new Server(opts, requestListener);
|
||||
};
|
14
lib/tls.js
14
lib/tls.js
|
@ -77,6 +77,11 @@ CryptoStream.prototype.resume = function() {
|
|||
};
|
||||
|
||||
|
||||
CryptoStream.prototype.setTimeout = function(n) {
|
||||
if (this.socket) this.socket.setTimeout(n);
|
||||
};
|
||||
|
||||
|
||||
function parseCertString (s) {
|
||||
// EG '/C=US/ST=CA/L=SF/O=Joyent/OU=Node.js/CN=ca1/emailAddress=ry@tinyclouds.org'
|
||||
var out = {};
|
||||
|
@ -183,8 +188,13 @@ CryptoStream.prototype._blow = function() {
|
|||
} while ((chunkBytes > 0) && (pool.used + bytesRead < pool.length));
|
||||
|
||||
if (bytesRead > 0) {
|
||||
chunk = pool.slice(0, bytesRead);
|
||||
this.emit('data', chunk);
|
||||
if (this._events && this._events['data']) {
|
||||
chunk = pool.slice(0, bytesRead);
|
||||
this.emit('data', chunk);
|
||||
}
|
||||
|
||||
// Optimization: emit the original buffer with end points
|
||||
if (this.ondata) this.ondata(pool, 0, bytesRead);
|
||||
}
|
||||
} while (bytesRead > 0 && this._writeState === true);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
if (!process.versions.openssl) {
|
||||
console.error("Skipping because node compiled without OpenSSL.");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
var fs = require('fs');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var https = require('https');
|
||||
|
||||
var options = {
|
||||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
||||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
||||
};
|
||||
|
||||
var reqCount = 0;
|
||||
var body = 'hello world\n';
|
||||
|
||||
var server = https.createServer(options, function (req, res) {
|
||||
reqCount++;
|
||||
console.log("got request");
|
||||
res.writeHead(200, { 'content-type': 'text/plain' });
|
||||
res.end(body);
|
||||
})
|
||||
|
||||
function afterCurl (err, stdout, stderr) {
|
||||
if (err) throw err;
|
||||
server.close();
|
||||
common.error(common.inspect(stdout));
|
||||
assert.equal(body, stdout);
|
||||
};
|
||||
|
||||
server.listen(common.PORT, function () {
|
||||
var cmd = 'curl --insecure https://127.0.0.1:' + common.PORT + '/';
|
||||
console.error("executing %j", cmd);
|
||||
exec(cmd, afterCurl);
|
||||
});
|
||||
|
||||
process.on('exit', function () {
|
||||
assert.equal(1, reqCount);
|
||||
});
|
Loading…
Reference in New Issue