THRIFT-4489: Add unix domain socket support for nodejs
Client: nodejs
This closes #1491
diff --git a/lib/nodejs/test/client.js b/lib/nodejs/test/client.js
index 006fad2..55839f6 100644
--- a/lib/nodejs/test/client.js
+++ b/lib/nodejs/test/client.js
@@ -36,6 +36,7 @@
.option('-t, --transport <transport>', 'Set thrift transport (buffered|framed|http) [transport]')
.option('--port <port>', 'Set thrift server port number to connect', 9090)
.option('--host <host>', 'Set thrift server host to connect', 'localhost')
+ .option('--domain-socket <path>', 'Set thrift server unix domain socket to connect')
.option('--ssl', 'use SSL transport')
.option('--promise', 'test with promise style functions')
.option('-t, --type <type>', 'Select server type (http|multiplex|tcp|websocket)', 'tcp')
@@ -43,6 +44,7 @@
var host = program.host;
var port = program.port;
+var domainSocket = program.domainSocket;
var type = program.type;
var ssl = program.ssl;
var promise = program.promise;
@@ -83,11 +85,19 @@
var testDriver = promise ? ThriftTestDriverPromise : ThriftTestDriver;
if (type === 'tcp' || type === 'multiplex') {
- connection = ssl ?
- thrift.createSSLConnection(host, port, options) :
- thrift.createConnection(host, port, options);
+ if (domainSocket) {
+ connection = thrift.createUDSConnection(domainSocket, options);
+ } else {
+ connection = ssl ?
+ thrift.createSSLConnection(host, port, options) :
+ thrift.createConnection(host, port, options);
+ }
} else if (type === 'http') {
- connection = thrift.createHttpConnection(host, port, options);
+ if (domainSocket) {
+ connection = thrift.createHttpUDSConnection(domainSocket, options);
+ } else {
+ connection = thrift.createHttpConnection(host, port, options);
+ }
} else if (type === 'websocket') {
connection = thrift.createWSConnection(host, port, options);
connection.open();
diff --git a/lib/nodejs/test/server.js b/lib/nodejs/test/server.js
index 8f2e06b..030d28b 100644
--- a/lib/nodejs/test/server.js
+++ b/lib/nodejs/test/server.js
@@ -36,11 +36,13 @@
.option('-t, --transport <transport>', 'Set thrift transport (buffered|framed|http)', 'buffered')
.option('--ssl', 'use ssl transport')
.option('--port <port>', 'Set thrift server port', 9090)
+ .option('--domain-socket <path>', 'Set thift server unix domain socket')
.option('--promise', 'test with promise style functions')
.option('-t, --type <type>', 'Select server type (http|multiplex|tcp|websocket)', 'tcp')
.parse(process.argv);
var port = program.port;
+var domainSocket = program.domainSocket;
var type = program.type;
var ssl = program.ssl;
var promise = program.promise;
@@ -88,10 +90,12 @@
}
if (ssl) {
- options.tls = {
- key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
- cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
- };
+ if (type === 'tcp' || type === 'multiplex' || type === 'http' || type === 'websocket') {
+ options.tls = {
+ key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
+ cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
+ };
+ }
}
var server;
@@ -103,4 +107,8 @@
server = thrift.createWebServer(options);
}
-server.listen(port);
+if (domainSocket) {
+ server.listen(domainSocket);
+} else if (type === 'tcp' || type === 'multiplex' || type === 'http' || type === 'websocket') {
+ server.listen(port);
+}