Minor changes from git review. 84/136284/1
authorAkhil Kedia <akhil.kedia@samsung.com>
Thu, 29 Jun 2017 03:58:00 +0000 (12:58 +0900)
committerAkhil Kedia <akhil.kedia@samsung.com>
Thu, 29 Jun 2017 03:59:26 +0000 (12:59 +0900)
IoT.js-DCO-1.0-Signed-off-by: Akhil Kedia akhil.kedia@samsung.com

Change-Id: I0080192fe910bba6291dc6071499fa38450e6a89

build.config
docs/api/IoT.js-API-HTTPS.md
src/iotjs_module.h
src/js/https_client.js
src/js/https_incoming.js
src/modules/iotjs_module_https.c
test/run_pass/test_https_timeout.js
test/testsets.json

index 034cf4649937d5205b0ff705eb66d3e730270a5f..72cf2d0365920960d6e0040c092735195c28c622 100644 (file)
   },
   "module": {
     "always": ["buffer", "console", "events", "fs", "module", "timers"],
-    "include": ["assert", "dns", "http", "net", "stream", "testdriver", "https"],
+    "include": ["assert", "dns", "http", "net", "stream", "testdriver"],
     "exclude": {
       "all": [],
-      "linux": ["adc", "ble", "dgram", "gpio", "i2c", "pwm", "spi", "uart", "https"],
-      "nuttx": ["adc", "dgram", "gpio", "i2c", "pwm", "stm32f4dis", "uart", "https"],
-      "darwin": ["https"],
-      "tizen": ["adc", "ble", "dgram", "gpio", "i2c", "pwm", "spi", "uart"],
-      "tizenrt": ["gpio", "pwm", "https"]
+      "linux": ["adc", "ble", "dgram", "gpio", "i2c", "pwm", "spi", "uart"],
+      "nuttx": ["adc", "dgram", "gpio", "i2c", "pwm", "stm32f4dis", "uart"],
+      "darwin": [],
+      "tizen": ["adc", "ble", "dgram", "gpio", "i2c", "pwm", "spi", "uart", "https"],
+      "tizenrt": ["gpio", "pwm"]
     }
   }
 }
index 5ed3aaec4c3368c42743772a7486f7db08926619..a310130ec3f8b8653ba83eb9b279cde6efbd3f53 100644 (file)
 
 # Https
 
-IoT.js provides HTTPS to support HTTPS clients enabling users to send HTTPS request easily.
+IoT.js provides HTTPS to support HTTPS clients enabling users to send HTTPS requests easily.
 
 ### https.request(options[, callback])
 * `options` {Object}
-  * `host` {string} A domain name or IP address of the server to issue the request to. Defaults to 'localhost'.
+  * `host` {string} A domain name or IP address of the server to issue the request to. **Deafult:** 'localhost'.
   * `hostname` {string} Alias for host.
-  * `port` {number} Port of remote server. Defaults to 80.
-  * `method` {string} A string specifying the HTTPS request method. Defaults to 'GET'.
-  * `path` {string} Request path. Defaults to '/'. Should include query string if any. E.G. '/index.html?page=12'. An exception is thrown when the request path contains illegal characters. Currently, only spaces are rejected but that may change in the future.
+  * `port` {number} Port of remote server. **Deafult:** 80.
+  * `method` {string} A string specifying the HTTPS request method. **Deafult:** 'GET'.
+  * `path` {string} Request path. **Deafult:** '/'. Should include query string if any. E.G. '/index.html?page=12'. An exception is thrown when the request path contains illegal characters. Currently, only spaces are rejected but that may change in the future.
   * `headers` {Object} An object containing request headers.
   * `auth` {string} Optional Basic Authentication in the form `username:password`. Used to compute HTTPS Basic Authentication header.
   * `ca` {string} Optional file path to CA certificate. Allows to override system trusted CA certificates.
   * `cert` {string} Optional file path to client authentication certificate in PEM format.
-  * `key1` {string} Optional file path to private keys for client cert in PEM format.
+  * `key` {string} Optional file path to private keys for client cert in PEM format.
 * `callback` {Function}
   * `response` {https.IncomingMessage}
 * Returns: {https.ClientRequest}
@@ -47,6 +47,16 @@ Note that in the example `req.end()` was called. With `https.request()` one must
 
 ### https.get(options[, callback])
 * `options` {Object}
+  * `host` {string} A domain name or IP address of the server to issue the request to. **Deafult:** 'localhost'.
+  * `hostname` {string} Alias for host.
+  * `port` {number} Port of remote server. **Deafult:** 80.
+  * `method` {string} A string specifying the HTTPS request method. **Deafult:** 'GET'.
+  * `path` {string} Request path. **Deafult:** '/'. Should include query string if any. E.G. '/index.html?page=12'. An exception is thrown when the request path contains illegal characters. Currently, only spaces are rejected but that may change in the future.
+  * `headers` {Object} An object containing request headers.
+  * `auth` {string} Optional Basic Authentication in the form `username:password`. Used to compute HTTPS Basic Authentication header.
+  * `ca` {string} Optional file path to CA certificate. Allows to override system trusted CA certificates.
+  * `cert` {string} Optional file path to client authentication certificate in PEM format.
+  * `key` {string} Optional file path to private keys for client cert in PEM format.
 * `callback` {Function}
   * `response` {https.IncomingMessage}
 * Returns: {https.ClientRequest}
@@ -75,9 +85,6 @@ This object is created internally and returned from https.request(). It represen
 
 https.ClientRequest inherits [`Stream.writable`](IoT.js-API-Stream.md). See it's documentation to write data to an outgoing HTTP request. Notable methods are `'writable.write()'` (to send data as request body), `'writable.end()'` (to signal an end and flush remaining request body), and the event `'finish'`.
 
-### request.aborted
-If the request has been aborted, this contains the time at which the request was aborted in milliseconds since epoch as `Number`.
-
 ### Event: 'close'
 This event is fired when the underlying socket is closed.
 
@@ -92,6 +99,9 @@ This event is emitted when a socket is assigned to this request.
 ### request.abort()
 Will abort the outgoing request, dropping any data to be sent/received and destroying the underlying socket.
 
+### request.aborted
+If the request has been aborted, this contains the time at which the request was aborted in milliseconds since epoch as `Number`.
+
 ### request.setTimeout(ms, cb)
 * `ms` {number}
 * `cb` {Function}
index 73b10ad956bb358a15e0f2e730a0a08f5543c7a2..0b6d86ed0f6571e1ce042c5207f85c13258f79bd 100644 (file)
@@ -43,6 +43,7 @@ typedef iotjs_jval_t (*register_func)();
   E(F, FS, Fs, fs)                               \
   E(F, GPIO, Gpio, gpio)                         \
   E(F, HTTPPARSER, Httpparser, httpparser)       \
+  E(F, HTTPS, Https, https)                      \
   E(F, I2C, I2c, i2c)                            \
   E(F, PROCESS, Process, process)                \
   E(F, PWM, Pwm, pwm)                            \
@@ -52,8 +53,7 @@ typedef iotjs_jval_t (*register_func)();
   E(F, TCP, Tcp, tcp)                            \
   E(F, TIMER, Timer, timer)                      \
   E(F, UART, Uart, uart)                         \
-  E(F, UDP, Udp, udp)                            \
-  E(F, HTTPS, Https, https)
+  E(F, UDP, Udp, udp)
 
 #define ENUMDEF_MODULE_LIST(upper, Camel, lower) MODULE_##upper,
 
index 02246a653c435bf047e631364736a44e01db4b81..faadadb2e04540195b25051bf9da253f61d5ce1a 100644 (file)
@@ -41,13 +41,14 @@ function ClientRequest(options, cb) {
   var isMethodGood = false;
   for (var key in methods) {
     if (methods.hasOwnProperty(key)) {
-      if(this.method == methods[key]) {
+      if (this.method === methods[key]) {
         isMethodGood = true;
+        break;
       }
     }
   }
 
-  if(!isMethodGood) {
+  if (!isMethodGood) {
     var err = new Error('Incorrect options.method.')
     this.emit('error', err);
     return;
@@ -149,8 +150,8 @@ function toBase64(input) {
     }
 
     output = output +
-    _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
-    _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
+      _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
+      _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
   }
   return output;
 }
index 9570582aae4be7a5de43aefedcbc893c87c626f9..23b4f9057ed29c6849eebe3221f1b906072fafb1 100644 (file)
@@ -149,7 +149,7 @@ function cbOnEnd() {
   var incoming = this;
   var parser = incoming.parser;
   if (parser) {
-    // unref all links to parser, make parser GCed
+    // Unref all links to parser, make parser GCed
     parser.finish();
     parser = null;
     incoming.parser = null;
@@ -171,7 +171,7 @@ function cbOnClosed() {
   } else if (!incoming.started) {
     incoming.emit('close');
     clientRequest.emit('close');
-    // socket closed before response starts.
+    // Socket closed before response starts.
     var err = new Error('Could Not Start Connection');
     clientRequest.onError(err);
   } else {
@@ -179,7 +179,7 @@ function cbOnClosed() {
   }
 
   if (parser) {
-    // unref all links to parser, make parser GCed
+    // Unref all links to parser, make parser GCed
     parser.finish();
     parser = null;
     incoming.parser = null;
@@ -202,7 +202,7 @@ function cbOnData(chunk) {
 
   if (ret instanceof Error) {
     parser.finish();
-    // unref all links to parser, make parser GCed
+    // Unref all links to parser, make parser GCed
     parser = null;
     clientRequest.onError(ret);
     return false;
index 1a0a9c362c74a5951a41bef79a2d179022fcffbc..dd6f2d22fd5916ea262541c87d4606a4f36a4c29 100644 (file)
@@ -53,7 +53,7 @@ iotjs_https_t* iotjs_https_create(const char* URL, const char* method,
   else if (strcmp(method, STRING_TRACE) == 0)
     _this->method = HTTPS_TRACE;
   else {
-    // Will never reach here cuz checked in JS
+    IOTJS_ASSERT(0);
   }
 
   // TLS certs stuff
@@ -176,7 +176,6 @@ void iotjs_https_cleanup(iotjs_https_t* https_data) {
   if (_this->poll_data != NULL)
     iotjs_https_poll_close_all(_this->poll_data);
 
-
   if (_this->to_destroy_read_onwrite) {
     const iotjs_jargs_t* jarg = iotjs_jargs_get_empty();
     const iotjs_jval_t* jthis = &(_this->jthis_native);
@@ -552,18 +551,12 @@ size_t iotjs_https_curl_write_callback(void* contents, size_t size,
     return real_size - 1;
   iotjs_jargs_t jarg = iotjs_jargs_create(1);
   iotjs_jval_t jresult_arr = iotjs_jval_create_byte_array(real_size, contents);
-  // iotjs_string_t jresult_string =
-  //    iotjs_string_create_with_size(contents, real_size);
-  // iotjs_jargs_append_string(&jarg, &jresult_string);
-  // Use the jresult_arr Byte Array in production, but in testing use
-  // string. Uncomment out above line in testing.
   iotjs_jargs_append_jval(&jarg, &jresult_arr);
 
   bool result =
       iotjs_https_jcallback(https_data, IOTJS_MAGIC_STRING_ONDATA, &jarg, true);
 
   iotjs_jval_destroy(&jresult_arr);
-  // iotjs_string_destroy(&jresult_string);
   iotjs_jargs_destroy(&jarg);
 
   if (!result) {
index 465fa24a0aa16c62f7ccf8b41fec438eda9063e8..95531b66958c2d228f187ec9c8ae0eebfd2b8213 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
+/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
index 0d43ffe5ed8335d220039c41d20fb5d2765728ec..2de56ea90a8b28fea419ba6e7be43c706c6892fc 100644 (file)
@@ -41,9 +41,9 @@
     { "name": "test_fs_open_read_sync_3.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" },
     { "name": "test_gpio_input.js", "skip": ["all"], "reason": "needs hardware" },
     { "name": "test_gpio_output.js", "skip": ["all"], "reason": "need user input"},
-    { "name": "test_https_get.js", "timeout": 40 },
-    { "name": "test_https_request_response.js", "timeout": 40 },
-    { "name": "test_https_timeout.js", "timeout": 40 },
+    { "name": "test_https_get.js", "timeout": 40, "skip": ["all"], "reason": "Only tizen support https, and on tizen we test manually" },
+    { "name": "test_https_request_response.js", "timeout": 40, "skip": ["all"], "reason": "Only tizen support https, and on tizen we test manually" },
+    { "name": "test_https_timeout.js", "timeout": 40, "skip": ["all"], "reason": "Only tizen support https, and on tizen we test manually" },
     { "name": "test_i2c.js", "skip": ["all"], "reason": "need to setup test environment" },
     { "name": "test_iotjs_promise.js", "skip": ["all"], "reason": "es2015 is off by default" },
     { "name": "test_module_cache.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" },