First pass at new https server
This commit is contained in:
parent
e4dd5cd6fd
commit
94f8368cf9
@ -871,6 +871,7 @@ function connectionListener(socket) {
|
|||||||
return false; // Not a HEAD response. (Not even a response!)
|
return false; // Not a HEAD response. (Not even a response!)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
exports._connectionListener = connectionListener;
|
||||||
|
|
||||||
|
|
||||||
function Client() {
|
function Client() {
|
||||||
|
22
lib/https.js
Normal file
22
lib/https.js
Normal file
@ -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);
|
||||||
|
};
|
10
lib/tls.js
10
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) {
|
function parseCertString (s) {
|
||||||
// EG '/C=US/ST=CA/L=SF/O=Joyent/OU=Node.js/CN=ca1/emailAddress=ry@tinyclouds.org'
|
// EG '/C=US/ST=CA/L=SF/O=Joyent/OU=Node.js/CN=ca1/emailAddress=ry@tinyclouds.org'
|
||||||
var out = {};
|
var out = {};
|
||||||
@ -183,9 +188,14 @@ CryptoStream.prototype._blow = function() {
|
|||||||
} while ((chunkBytes > 0) && (pool.used + bytesRead < pool.length));
|
} while ((chunkBytes > 0) && (pool.used + bytesRead < pool.length));
|
||||||
|
|
||||||
if (bytesRead > 0) {
|
if (bytesRead > 0) {
|
||||||
|
if (this._events && this._events['data']) {
|
||||||
chunk = pool.slice(0, bytesRead);
|
chunk = pool.slice(0, bytesRead);
|
||||||
this.emit('data', chunk);
|
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);
|
} while (bytesRead > 0 && this._writeState === true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
44
test/simple/test-https-simple.js
Normal file
44
test/simple/test-https-simple.js
Normal file
@ -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…
x
Reference in New Issue
Block a user