cls-tls
When using cls continuation-local-storage with a node tls client socket, the cls contexts get lost in some client socket event callbacks (such as write callback) and tls.connect event, for example,
var tls = ;var cls = ;var ns = cls; ns;
This shim cls-tls monkeypatches the node tls module and/or tls.TLSSocket socket instances. The goal is to make tls socket client work with cls namespace/context.
Usage example - if you create tls socket using "tls.connect"
If you are using convenient tls module api "tls.connect" to make tls connection, use this shim api 'patchTls(ns)'. Calling this api patches the tls module method tls.connect so it works with cls namespace/context, the tls socket created as result of calling tls.connect is also patched so it works with cls namespace/context.
An example,
var tls = ;var cls = ;var ns = cls; var patchTls = ;; ns;
Usage example - if you create tls socket using "new tls.TLSSocket"
If you are creating tls.TLSSocket instance using "new tls.TLSSocket" to make tls connection,
use this shim api 'patchTls(ns, tlsSocket)'. Calling this api patches the passed-in tls socket
so it works with cls namespace/context.
An example,
var tls = ;var cls = ;var ns = cls; var patchTls = ; ns;
For more formal examples, please see test/*.tap.js files.
Tests
Run
$ npm test
Before running the tests, you must run a TLS socket server via
$ node test/TlsServer.js
Note: the server key and cert files under /test were generated before (running above TLS server) using
$ openssl genrsa -out server-key.pem 4096$ openssl req -new -key server-key.pem -out server-csr.pem$ openssl x509 -req -in server-csr.pem -signkey server-key.pem -out server-cert.pem