THRIFT-2493:Node.js lib needs HTTP client
Client: node
Patch: Randy Abernethy

Clean up of many jshint warnings/errors, jsdoc for HttpConnect,
added support for https and Python to HttpConnect, added tests
for HttpConnect with https and promises.
diff --git a/lib/nodejs/test/client.js b/lib/nodejs/test/client.js
index a6fabfc..8813f91 100644
--- a/lib/nodejs/test/client.js
+++ b/lib/nodejs/test/client.js
@@ -53,7 +53,7 @@
   protocol: protocol
 };
 
-var connection = undefined;
+var connection;
 
 if (program.ssl) {
   options.rejectUnauthorized = false;
diff --git a/lib/nodejs/test/http_client.js b/lib/nodejs/test/http_client.js
index 08a7d27..14c1a29 100644
--- a/lib/nodejs/test/http_client.js
+++ b/lib/nodejs/test/http_client.js
@@ -55,23 +55,22 @@
    path: "/test"
 };
 
-var connection = undefined;
-
 if (program.ssl) {
-  options.rejectUnauthorized = false;
-  connection = thrift.createHttpConnection("localhost", 9090, options);
-} else {
-  connection = thrift.createHttpConnection("localhost", 9090, options);
-}
+  options.nodeOptions = { rejectUnauthorized: false };
+  options.https = true;
+} 
+
+var connection = thrift.createHttpConnection("localhost", 9090, options);
 
 var client = thrift.createHttpClient(ThriftTest, connection);
 
-//connection.on('error', function(err) {
-//  assert(false, err);
-//});
+connection.on('error', function(err) {
+  assert(false, err);
+});
 
 var testDriver = ThriftTestDriver;
 if (program.promise) {
+  console.log("    --Testing promise style client");
   testDriver = ThriftTestDriverPromise;
 } 
 testDriver(client, function (status) {
diff --git a/lib/nodejs/test/http_server.js b/lib/nodejs/test/http_server.js
index d8ef73f..f12e695 100644
--- a/lib/nodejs/test/http_server.js
+++ b/lib/nodejs/test/http_server.js
@@ -54,7 +54,13 @@
     protocol: protocol,                 
     transport: transport 		
 };                                  
-var serverOpt = { services: { "/test": SvcOpt } }                                   
+var serverOpt = { services: { "/test": SvcOpt } };                            
+if (program.ssl) {
+  serverOpt.tls = {
+    key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
+    cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
+  };
+}
 thrift.createWebServer(serverOpt).listen(9090);                        		
 
 
diff --git a/lib/nodejs/test/multiplex_client.js b/lib/nodejs/test/multiplex_client.js
index 6580cb5..7b58205 100644
--- a/lib/nodejs/test/multiplex_client.js
+++ b/lib/nodejs/test/multiplex_client.js
@@ -47,9 +47,9 @@
   protocol: protocol
 };
 
-var connection = undefined;
+var connection;
 if (program.ssl) {
-  options.rejectUnauthorized = false
+  options.rejectUnauthorized = false;
   connection = thrift.createSSLConnection('localhost', 9090, options);
 } else {
   connection = thrift.createConnection('localhost', 9090, options);
diff --git a/lib/nodejs/test/multiplex_server.js b/lib/nodejs/test/multiplex_server.js
index 6331f6f..18f9b0d 100644
--- a/lib/nodejs/test/multiplex_server.js
+++ b/lib/nodejs/test/multiplex_server.js
@@ -72,7 +72,7 @@
   options.tls = {
     key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
     cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
-  }
+  };
 }
 
 thrift.createMultiplexServer(processor, options).listen(9090);
diff --git a/lib/nodejs/test/server.js b/lib/nodejs/test/server.js
index 6f5abe6..605c700 100644
--- a/lib/nodejs/test/server.js
+++ b/lib/nodejs/test/server.js
@@ -17,11 +17,6 @@
  * under the License.
  */
 
-//Server test for the following I/O stack:
-//    TBinaryProtocol
-//    TFramedTransport
-//    TSocket
-
 var fs = require('fs');
 var path = require('path');
 var thrift = require('thrift');
@@ -61,7 +56,7 @@
   options.tls = {
     key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
     cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
-  }
+  };
 }
 thrift.createServer(ThriftTest, handler, options).listen(9090);
 
diff --git a/lib/nodejs/test/testAll.sh b/lib/nodejs/test/testAll.sh
index 87bbb9d..9d1da3f 100755
--- a/lib/nodejs/test/testAll.sh
+++ b/lib/nodejs/test/testAll.sh
@@ -96,5 +96,7 @@
 testHttpClientServer json framed || TESTOK=1
 testHttpClientServer binary buffered || TESTOK=1
 testHttpClientServer binary framed || TESTOK=1
+testHttpClientServer json buffered --promise || TESTOK=1
+testHttpClientServer binary framed --ssl || TESTOK=1
 
 exit $TESTOK
diff --git a/lib/nodejs/test/thrift_test_driver.js b/lib/nodejs/test/thrift_test_driver.js
index a21c9c5..02613ec 100644
--- a/lib/nodejs/test/thrift_test_driver.js
+++ b/lib/nodejs/test/thrift_test_driver.js
@@ -67,6 +67,7 @@
 });

 

 //all Languages in UTF-8

+/*jshint -W100 */

 var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +

     "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " +

     "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " +

@@ -92,6 +93,7 @@
     "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " +

     "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " +

     "Bân-lâm-gú, 粵語";

+/*jshint +W100 */

 

 client.testString(stringTest, function(err, response) {

   assert( ! err);

diff --git a/lib/nodejs/test/thrift_test_driver_promise.js b/lib/nodejs/test/thrift_test_driver_promise.js
index b5c1b87..22e2572 100644
--- a/lib/nodejs/test/thrift_test_driver_promise.js
+++ b/lib/nodejs/test/thrift_test_driver_promise.js
@@ -70,6 +70,7 @@
   });

 

 //all Languages in UTF-8

+/*jshint -W100 */

 var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +

     "Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " +

     "Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " +

@@ -95,6 +96,7 @@
     "Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " +

     "Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " +

     "Bân-lâm-gú, 粵語";

+/*jshint +W100 */

 

 client.testString(stringTest)

   .then(function(response) {

@@ -330,7 +332,7 @@
 client.testException('Xception')

   .then(function(response) {

     assert.equal(err.errorCode, 1001);

-    assert.equal('Xception', err.message)

+    assert.equal('Xception', err.message);

   })

   .fail(function() {

     assert(false);

@@ -365,7 +367,7 @@
   client.testI32(-1)

     .then(function(response) {

         assert.equal(-1, response);

-        test_complete = true

+        test_complete = true;

     })

     .fail(function() {

       assert(false);

@@ -391,4 +393,4 @@
 

   setTimeout(TestForCompletion, retry_interval);

 })();

-}

+};