I want to be able to look at the first chunk of data coming through a
regular net socket and then convert it to a tls socket if necessary.
Breaking that down:
1. establish tcp connection
2. check first packet
3. if tls hello, use tls
4. otherwise use tcp
5. re-emit first packet
I've tried just emitting 'connection' on an http.Server for plain
connections that works.
It does NOT work when I try the exact same thing with tls.Server,
https.Server, or tls.TLSSocket:
'use strict';
var net = require('net');
var tls = require('tls');
var http = require('http');
var tlsOpts = require('localhost.daplie.com-certificates').merge({});
var plainHttp = http.createServer(function (req, res) {
res.end('Hello, World!');
});
var tcp3000 = net.createServer(function (socket) {
socket.once('data', function (chunk) {
if (/http\/1/i.test(chunk.toString())) {
* // works*
console.log("looks like http, continue");
plainHttp.emit('connection', socket);
} else {
* // does not work*
console.log("doesn't look like http, try tls");
// secureHttp.emit('connection', socket);
var tlsSocket = new tls.TLSSocket(socket, { secureContext:
tls.createSecureContext(tlsOpts) });
* tlsSocket.on('data', function (chunk) {*
* // this is never called*
* console.log('chunk', chunk);*
* });*
}
// replay first packet
socket.emit('data', chunk);
});
});
tcp3000.listen(3000, function () {
console.log('listening on 3000');
});
Any thoughts or ideas?
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/36fce106-bcc0-4482-b7a0-50f0fb8a7850%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.