[Bugfix] Correct Handling of http expect: 100-continue 26/138126/5
authorAkhil Kedia <akhil.kedia@samsung.com>
Tue, 11 Jul 2017 07:00:26 +0000 (16:00 +0900)
committerAkhil Kedia <akhil.kedia@samsung.com>
Mon, 17 Jul 2017 05:23:31 +0000 (14:23 +0900)
Added a Unit test case for this too at ./test/run_pass/test_https_expect.js.
This case fails before this commit, passes after.

Change-Id: I3f5cc94c31cd890fa028bc9737b6534e2f19f2f4
Signed-off-by: Akhil Kedia <akhil.kedia@samsung.com>
src/js/https_incoming.js
test/run_pass/test_https_post_status_codes.js [new file with mode: 0644]
test/testsets.json

index 23b4f9057ed29c6849eebe3221f1b906072fafb1..7fb8143cab7dd66e902f70450c8d4b4a894438fd 100644 (file)
@@ -113,6 +113,9 @@ function parserOnHeadersComplete(info) {
   parser.incoming.started = true;
 
   // For client side, if response to 'HEAD' request, we will skip parsing body
+  if (parser.incoming.statusCode == 100) {
+    return false;
+  }
   return parser.incoming.clientRequest.headersComplete();
 }
 
@@ -137,9 +140,16 @@ function parserOnMessageComplete() {
   var incoming = parser.incoming;
 
   if (incoming) {
-    incoming.completed = true;
-    // no more data from incoming, stream will emit 'end' event
-    incoming.push(null);
+    if (incoming.statusCode == 100) {
+      incoming.headers = {};
+      incoming.statusCode = null;
+      incoming.statusMessage = null;
+      incoming.started = false;
+    } else {
+      incoming.completed = true;
+      // no more data from incoming, stream will emit 'end' event
+      incoming.push(null);
+    }
   }
 }
 
diff --git a/test/run_pass/test_https_post_status_codes.js b/test/run_pass/test_https_post_status_codes.js
new file mode 100644 (file)
index 0000000..26f4ff7
--- /dev/null
@@ -0,0 +1,60 @@
+/* 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+var assert = require('assert');
+var https = require('https');
+
+var isRequest1Finished = false;
+// 1. POST req
+var data = JSON.stringify({ data: { temp: 50, onFire: false },
+  sdid: '170e5221612b4bc38dce53fd4395174a',
+  type: 'message' });
+
+var options = {
+  "method": "POST",
+  "hostname": "api.artik.cloud",
+  "path": "/v1.1/messages",
+  "headers": {
+    "content-type": "application/json",
+    "content-length": data.length,
+    "authorization": "Bearer 1718113118564ad495ad03f04116f379"
+  }
+};
+
+var getResponseHandler = function (res) {
+  var res_body = '';
+
+  assert.equal(200, res.statusCode);
+
+  var endHandler = function(){
+    var response = JSON.parse(res_body);
+    assert.assert(response['data'], 'Recieved incorrect response from server');
+    isRequest1Finished = true;
+  };
+  res.on('end', endHandler);
+
+  res.on('data', function(chunk){
+    res_body += chunk.toString();
+  });
+};
+
+var req = https.request(options, getResponseHandler);
+req.write(data);
+req.end();
+
+process.on('exit', function() {
+  assert.equal(isRequest1Finished, true);
+});
index 2de56ea90a8b28fea419ba6e7be43c706c6892fc..86b221f36fe7ffdf00c71ea638e26306fe828b1f 100644 (file)
     { "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, "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_https_expect.js", "timeout": 40, "skip": ["all"], "reason": "Implemented only for Tizen" },
+    { "name": "test_https_get.js", "timeout": 40, "skip": ["all"], "reason": "Implemented only for Tizen" },
+    { "name": "test_https_request_response.js", "timeout": 40, "skip": ["all"], "reason": "Implemented only for Tizen" },
+    { "name": "test_https_timeout.js", "timeout": 40, "skip": ["all"], "reason": "Implemented only for Tizen" },
     { "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" },