Skip to content

Commit 97515d9

Browse files
LaszloLangoyichoi
authored andcommitted
Fix 'statusMessage' setup in implicit header of 'http.ServerResponse'. (#967)
IoT.js-DCO-1.0-Signed-off-by: László Langó [email protected]
1 parent 3f53b9b commit 97515d9

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/js/http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ServerResponse.prototype.statusMessage = undefined;
8282
// if user does not set Header before write(..),
8383
// this function set default header(200).
8484
ServerResponse.prototype._implicitHeader = function() {
85-
this.writeHead(this.statusCode);
85+
this.writeHead(this.statusCode, this.statusMessage);
8686
};
8787

8888

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
2+
*
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
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
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.
14+
*/
15+
16+
// Copyright Joyent, Inc. and other Node contributors.
17+
//
18+
// Permission is hereby granted, free of charge, to any person obtaining a
19+
// copy of this software and associated documentation files (the
20+
// "Software"), to deal in the Software without restriction, including
21+
// without limitation the rights to use, copy, modify, merge, publish,
22+
// distribute, sublicense, and/or sell copies of the Software, and to permit
23+
// persons to whom the Software is furnished to do so, subject to the
24+
// following conditions:
25+
//
26+
// The above copyright notice and this permission notice shall be included
27+
// in all copies or substantial portions of the Software.
28+
//
29+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
32+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
33+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
34+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
35+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
36+
37+
'use strict';
38+
39+
require('node/common');
40+
var assert = require('assert');
41+
var http = require('http');
42+
var net = require('net');
43+
44+
var s = http.createServer(function (req, res) {
45+
res.statusCode = 200;
46+
res.statusMessage = 'Custom Message';
47+
res.end('');
48+
});
49+
50+
s.listen(0, test);
51+
52+
function test() {
53+
var bufs = [];
54+
var client = net.connect(this.address().port, function () {
55+
client.write('GET / HTTP/1.1\r\nConnection: close\r\n\r\n');
56+
});
57+
client.on('data', function (chunk) {
58+
bufs.push(chunk);
59+
});
60+
client.on('end', function () {
61+
var head = Buffer.concat(bufs).toString().split('\r\n')[0];
62+
assert.strictEqual('HTTP/1.1 200 Custom Message', head);
63+
console.log('ok');
64+
s.close();
65+
});
66+
}

test/testsets.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
],
114114
"node/parallel": [
115115
{ "name": "test-assert.js" },
116+
{ "name": "test-http-status-message.js" },
116117
{ "name": "test-http-write-head.js" },
117118
{ "name": "test-net-bind-twice.js" },
118119
{ "name": "test-net-end-without-connect.js" },

0 commit comments

Comments
 (0)