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.
18 var assert = require('assert');
19 var http = require('http');
20 var checkReqFinish = false;
23 // Server just ends after sending with some headers.
25 var server = http.createServer(function (req, res) {
27 req.on('data', function (chunk) {
31 var endHandler = function () {
33 res.setHeader('h1','h1');
34 res.setHeader('h2','h2');
35 res.setHeader('h3','h3');
36 res.removeHeader('h2');
37 if (res.getHeader('h3') == 'h3') {
38 res.setHeader('h3','h3prime'); // h3 value should be overwrited
40 // final res.headers = { 'h1' : 'h1', 'h3': 'h3prime' }
47 req.on('end', endHandler);
50 server.listen(3045, 3);
61 var postResponseHandler = function (res) {
64 assert.equal(200, res.statusCode);
65 assert.equal(res.headers['h1'], 'h1');
66 assert.equal(res.headers['h2'], undefined);
67 assert.equal(res.headers['h3'], 'h3prime');
69 var endHandler = function(){
70 checkReqFinish = true;
72 res.on('end', endHandler);
74 res.on('data', function(chunk){
75 res_body += chunk.toString();
79 var req = http.request(options, postResponseHandler);
82 process.on('exit', function() {
83 assert.equal(checkReqFinish, true);