diff options
author | Alexander Borisov <alexander.borisov@nginx.com> | 2018-10-24 16:21:53 +0300 |
---|---|---|
committer | Alexander Borisov <alexander.borisov@nginx.com> | 2018-10-24 16:21:53 +0300 |
commit | 5b3d3e0a885614cbc7966bc1d4b73ba630caf1ed (patch) | |
tree | 4b37eefa629ab89ba4db9457e8b0c478eb54be74 | |
parent | 6cc4080af23d0d8c39ba43f6c90de4f76d64e0f1 (diff) | |
download | unit-5b3d3e0a885614cbc7966bc1d4b73ba630caf1ed.tar.gz unit-5b3d3e0a885614cbc7966bc1d4b73ba630caf1ed.tar.bz2 |
Node.js: additional type check for response.setHeader value.
Diffstat (limited to '')
-rwxr-xr-x | src/nodejs/unit-http/http_server.js | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 8c144cbe..fa7b8e9b 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -52,7 +52,7 @@ ServerResponse.prototype.setHeader = function setHeader(key, value) { throw new TypeError('Key argument must be a string'); } - let header_key_len = Buffer.byteLength(key + "", 'latin1'); + let header_key_len = Buffer.byteLength(key, 'latin1'); let header_len = 0 let header_count = 0; @@ -60,16 +60,16 @@ ServerResponse.prototype.setHeader = function setHeader(key, value) { header_count = value.length; value.forEach(function(val) { - if (typeof val !== 'string') { - throw new TypeError('Entry in arrey should be a string'); + if (typeof val !== 'string' && typeof val !== 'number') { + throw new TypeError('Array entries must be string or number'); } header_len += Buffer.byteLength(val + "", 'latin1'); }); } else { - if (typeof value !== 'string') { - throw new TypeError('Value argument must be a string or array'); + if (typeof value !== 'string' && typeof value !== 'number') { + throw new TypeError('Value argument must be string, number, or array'); } header_count = 1; @@ -78,7 +78,7 @@ ServerResponse.prototype.setHeader = function setHeader(key, value) { this.removeHeader(key); - this.headers[key] = value; + this.headers[key] = value + ""; this.headers_len += header_len + (header_key_len * header_count); this.headers_count += header_count; }; |