1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 var assert = require('assert');
18 var http = require('http');
21 var server = http.createServer(function (req, res) {
26 req.on('data', function (chunk) {
30 var endHandler = function () {
32 res.writeHead(200, { 'Connection' : 'close',
33 'Content-Length' : body.length
37 if(body == 'close server') server.close();
41 req.on('end', endHandler);
45 server.listen(3005,5);
54 var getResponseHandler = function (res) {
57 assert.equal(200, res.statusCode);
59 var endHandler = function(){
60 // GET msg, no received body
61 assert.equal('', res_body);
63 res.on('end', endHandler);
65 res.on('data', function(chunk){
66 res_body += chunk.toString();
70 http.get(options, getResponseHandler);
73 // 2. close server req
74 var finalMsg = 'close server';
78 headers : {'Content-Length': finalMsg.length}
81 var finalResponseHandler = function (res) {
84 assert.equal(200, res.statusCode);
86 var endHandler = function(){
87 assert.equal(finalMsg, res_body);
89 res.on('end', endHandler);
91 res.on('data', function(chunk){
92 res_body += chunk.toString();
96 var finalReq = http.request(finalOptions, finalResponseHandler);
97 finalReq.write(finalMsg);