From 71c7a8378f7112e0d6fa4c33e2b0d264c329d3e9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 11 Oct 2016 14:49:52 -0600 Subject: [PATCH] fix paired-duplex example --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 27d2e9d..fc21dc9 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,10 @@ var token = jwt.sign(tokenData, secret); Let's say you want to handle http requests in-process or decrypt https before passing it to the local http handler. + +You'll need to create a pair of streams to connect between the +local handler and the tunnel handler. + You could do a little magic like this: ``` @@ -116,11 +120,16 @@ stunnel.connect({ createConnection: function (info, cb) { // data is the hello packet / first chunk // info = { data, servername, port, host, remoteAddress: { family, address, port } } - // socket = { write, push, end, events: [ 'readable', 'data', 'error', 'end' ] }; - var myDuplex = new (require('streams').Duplex); + var myDuplex = new (require('streams').Duplex)(); + var myDuplex2 = new (require('streams').Duplex)(); + // duplex = { write, push, end, events: [ 'readable', 'data', 'error', 'end' ] }; - myDuplex.__my_socket = socket; + myDuplex2.__my_socket = myDuplex; + myDuplex2._write = Dup.write; + myDuplex2._read = Dup.read; + + myDuplex.__my_socket = myDuplex2; myDuplex._write = Dup.write; myDuplex._read = Dup.read; @@ -139,7 +148,7 @@ stunnel.connect({ cb(); } - return myDuplex; + return myDuplex2; } }); ```