From aeb026c8ab41b907f2e19a9f2fa978717d034830 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 12 Dec 2018 19:57:15 +0300 Subject: Node.js: removed unused dependency. --- src/nodejs/unit-http/package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/package.json b/src/nodejs/unit-http/package.json index 3a15d573..6a2cd27c 100644 --- a/src/nodejs/unit-http/package.json +++ b/src/nodejs/unit-http/package.json @@ -22,8 +22,5 @@ }, "author": "Alexander Borisov", "license": "Apache-2.0", - "gypfile": true, - "dependencies": { - "node-addon-api": "1.2.0" - } + "gypfile": true } -- cgit From de3c062c6e3e869d726b93a1ffe617059df7611a Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:55:54 +0300 Subject: Node.js: buffering HTTP headers before writing the body. --- src/nodejs/unit-http/http_server.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 57163c0b..47851c98 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -178,21 +178,16 @@ function writeHead(statusCode, reason, obj) { } } } - - unit_lib.unit_response_headers(this, statusCode, this.headers, this.headers_count, this.headers_len); - - this.headersSent = true; }; ServerResponse.prototype._writeBody = function(chunk, encoding, callback) { var contentLength = 0; if (!this.headersSent) { - this.writeHead(this.statusCode); - } + unit_lib.unit_response_headers(this, this.statusCode, this.headers, + this.headers_count, this.headers_len); - if (this.finished) { - return this; + this.headersSent = true; } if (typeof chunk === 'function') { @@ -225,15 +220,23 @@ ServerResponse.prototype._writeBody = function(chunk, encoding, callback) { }; ServerResponse.prototype.write = function write(chunk, encoding, callback) { + if (this.finished) { + throw new Error("Write after end"); + } + this._writeBody(chunk, encoding, callback); return true; }; ServerResponse.prototype.end = function end(chunk, encoding, callback) { - this._writeBody(chunk, encoding, callback); + if (!this.finished) { + this._writeBody(chunk, encoding, callback); - this.finished = true; + unit_lib.unit_response_end(this); + + this.finished = true; + } return this; }; -- cgit From 13c9ebccca9c7bee80f4b9c1da4c128435d9dac1 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:55:58 +0300 Subject: Node.js: changed the 'data' event calling sequence for the request. The problem is caused by Promises' inconsistency. The 'date' event could have been triggered before the user has started listening for it. To resolve the issue, we override the 'on' method of the request's emitter. --- src/nodejs/unit-http/http_server.js | 40 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 47851c98..9b7b8403 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -288,6 +288,28 @@ ServerRequest.prototype.resume = function resume() { return []; }; +/* + * The "on" method is overridden to defer reading data until user code is + * ready, that is (ev === "data"). This can occur after req.emit("end") is + * executed, since the user code can be scheduled asynchronously by Promises + * and so on. Passing the data is postponed by process.nextTick() until + * the "on" method caller completes. + */ +ServerRequest.prototype.on = function on(ev, fn) { + Server.prototype.on.call(this, ev, fn); + + if (ev === "data") { + process.nextTick(function () { + if (this.server.buffer.length !== 0) { + this.emit("data", this.server.buffer); + } + + }.bind(this)); + } +}; + +ServerRequest.prototype.addListener = ServerRequest.prototype.on; + function Server(requestListener) { EventEmitter.call(this); @@ -321,22 +343,20 @@ Server.prototype.listen = function () { }; Server.prototype.run_events = function (server, req, res) { + req.server = server; + res.server = server; + req.res = res; + res.req = req; + + server.buffer = server.unit._read(req.socket.req_pointer); + /* Important!!! setImmediate starts the next iteration in Node.js loop. */ setImmediate(function () { server.emit("request", req, res); - Promise.resolve().then(() => { - let buf = server.unit._read(req.socket.req_pointer); - - if (buf.length != 0) { - req.emit("data", buf); - } - - req.emit("end"); - }); - Promise.resolve().then(() => { req.emit("finish"); + req.emit("end"); if (res.finished) { unit_lib.unit_response_end(res); -- cgit From f47a5db506911f1cf117bdc15474d40508bb7601 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:56:01 +0300 Subject: Node.js: napi_call_function() replaced with napi_make_callback(). The sequence of napi_open_callback_scope(), napi_call_function(), and napi_close_callback_scope() functions calls executes the provided JS code and all functions enqueued by process.nextTick() and Promises during this execution. --- src/nodejs/unit-http/http_server.js | 17 +++------ src/nodejs/unit-http/unit.cpp | 73 +++++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 27 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 9b7b8403..8a536cde 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -342,7 +342,7 @@ Server.prototype.listen = function () { this.unit.listen(); }; -Server.prototype.run_events = function (server, req, res) { +Server.prototype.emit_events = function (server, req, res) { req.server = server; res.server = server; req.res = res; @@ -350,18 +350,11 @@ Server.prototype.run_events = function (server, req, res) { server.buffer = server.unit._read(req.socket.req_pointer); - /* Important!!! setImmediate starts the next iteration in Node.js loop. */ - setImmediate(function () { - server.emit("request", req, res); + server.emit("request", req, res); - Promise.resolve().then(() => { - req.emit("finish"); - req.emit("end"); - - if (res.finished) { - unit_lib.unit_response_end(res); - } - }); + process.nextTick(() => { + req.emit("finish"); + req.emit("end"); }); }; diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp index be64a59b..b233359c 100644 --- a/src/nodejs/unit-http/unit.cpp +++ b/src/nodejs/unit-http/unit.cpp @@ -276,12 +276,13 @@ Unit::_read(napi_env env, napi_callback_info info) void Unit::request_handler(nxt_unit_request_info_t *req) { - Unit *obj; - napi_value socket, request, response; - napi_value global, server_obj; - napi_value run_events, events_res; - napi_status status; - napi_value events_args[3]; + Unit *obj; + napi_value socket, request, response, global, server_obj; + napi_value emit_events, events_res, async_name, resource_object; + napi_status status; + napi_async_context async_context; + napi_callback_scope async_scope; + napi_value events_args[3]; obj = reinterpret_cast(req->unit->data); @@ -328,11 +329,11 @@ Unit::request_handler(nxt_unit_request_info_t *req) return; } - status = napi_get_named_property(obj->env_, server_obj, "run_events", - &run_events); + status = napi_get_named_property(obj->env_, server_obj, "emit_events", + &emit_events); if (status != napi_ok) { - napi_throw_error(obj->env_, NULL, "Failed to get" - " 'run_events' function"); + napi_throw_error(obj->env_, NULL, "Failed to get " + "'emit_events' function"); return; } @@ -340,15 +341,57 @@ Unit::request_handler(nxt_unit_request_info_t *req) events_args[1] = request; events_args[2] = response; - status = napi_call_function(obj->env_, server_obj, run_events, 3, - events_args, &events_res); + status = napi_create_string_utf8(obj->env_, "unit_request_handler", + sizeof("unit_request_handler") - 1, + &async_name); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, "Failed to create utf-8 string"); + return; + } + + status = napi_async_init(obj->env_, NULL, async_name, &async_context); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, "Failed to init async object"); + return; + } + + status = napi_create_object(obj->env_, &resource_object); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, "Failed to create object for " + "callback scope"); + return; + } + + status = napi_open_callback_scope(obj->env_, resource_object, async_context, + &async_scope); if (status != napi_ok) { - napi_throw_error(obj->env_, NULL, "Failed to call" - " 'run_events' function"); + napi_throw_error(obj->env_, NULL, "Failed to open callback scope"); return; } - napi_close_handle_scope(obj->env_, scope); + status = napi_make_callback(obj->env_, async_context, server_obj, + emit_events, 3, events_args, &events_res); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, "Failed to make callback"); + return; + } + + status = napi_close_callback_scope(obj->env_, async_scope); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, "Failed to close callback scope"); + return; + } + + status = napi_async_destroy(obj->env_, async_context); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, "Failed to destroy async object"); + return; + } + + status = napi_close_handle_scope(obj->env_, scope); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, "Failed to close handle scope"); + } } -- cgit From dc16885b60f1d31d09114ea6140384531cad78e0 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:56:06 +0300 Subject: Node.js: changed the unit-http socket constructor. Third-party file descriptors are not supported. Socket "readable" and "writable" options are set true by default. --- src/nodejs/unit-http/socket.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/socket.js b/src/nodejs/unit-http/socket.js index aef065bf..6e836949 100755 --- a/src/nodejs/unit-http/socket.js +++ b/src/nodejs/unit-http/socket.js @@ -18,10 +18,16 @@ function Socket(options) { throw new TypeError('Options must be object'); } - this.readable = (typeof options.readable === 'boolean' ? options.readable - : false); - this.writable = (typeof options.writable === 'boolean' ? options.writable - : false); + if ("fd" in options) { + throw new TypeError('Working with file descriptors not supported'); + } + + /* + * For HTTP TCP socket 'readable' and 'writable' are always true. + * These options are required by Express and Koa frameworks. + */ + this.readable = true; + this.writable = true; } util.inherits(Socket, EventEmitter); @@ -43,7 +49,6 @@ Socket.prototype.connect = function connect(options, connectListener) { this.once('connect', connectListener); this.connecting = true; - this.writable = true; return this; }; -- cgit From 704fe556b423795d06f79cec3a3406ef6defb635 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:56:09 +0300 Subject: Node.js: style fixes. No functional changes. --- src/nodejs/unit-http/http_server.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 8a536cde..c93d2b10 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -105,21 +105,23 @@ ServerResponse.prototype.removeHeader = function removeHeader(name) { } let name_len = Buffer.byteLength(name + "", 'latin1'); + let value = this.headers[name]; - if (Array.isArray(this.headers[name])) { - this.headers_count -= this.headers[name].length; - this.headers_len -= this.headers[name].length * name_len; + delete this.headers[name]; + + if (Array.isArray(value)) { + this.headers_count -= value.length; + this.headers_len -= value.length * name_len; - this.headers[name].forEach(function(val) { + value.forEach(function(val) { this.headers_len -= Buffer.byteLength(val + "", 'latin1'); }); - } else { - this.headers_count--; - this.headers_len -= name_len + Buffer.byteLength(this.headers[name] + "", 'latin1'); + return; } - delete this.headers[name]; + this.headers_count--; + this.headers_len -= name_len + Buffer.byteLength(value + "", 'latin1'); }; ServerResponse.prototype.sendDate = function sendDate() { -- cgit From 607653c0f12a99981dbf3118b60b84ded4084d50 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:56:13 +0300 Subject: Node.js: calling write callback asynchronously. --- src/nodejs/unit-http/http_server.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index c93d2b10..28f2303f 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -217,7 +217,19 @@ ServerResponse.prototype._writeBody = function(chunk, encoding, callback) { } if (typeof callback === 'function') { - callback(this); + /* + * The callback must be called only when response.write() caller + * completes. process.nextTick() postpones the callback execution. + * + * process.nextTick() is not technically part of the event loop. + * Instead, the nextTickQueue will be processed after the current + * operation completes, regardless of the current phase of + * the event loop. All callbacks passed to process.nextTick() + * will be resolved before the event loop continues. + */ + process.nextTick(function () { + callback(this); + }.bind(this)); } }; -- cgit From dcf51274ce0953e577fbfffd81afb592319a2267 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:56:30 +0300 Subject: Node.js: checking uniqueness of HTTP headers for different case. --- src/nodejs/unit-http/http_server.js | 72 +++++++++++++++++++++++++------------ src/nodejs/unit-http/unit.cpp | 14 ++++++-- 2 files changed, 62 insertions(+), 24 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 28f2303f..216c4394 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -47,24 +47,23 @@ ServerResponse.prototype.writeContinue = function writeContinue(cb) { ServerResponse.prototype.writeProcessing = function writeProcessing(cb) { }; -ServerResponse.prototype.setHeader = function setHeader(key, value) { - if (typeof key !== 'string') { - throw new TypeError('Key argument must be a string'); +ServerResponse.prototype.setHeader = function setHeader(name, value) { + if (typeof name !== 'string') { + throw new TypeError('Name argument must be a string'); } - let header_key_len = Buffer.byteLength(key, 'latin1'); - let header_len = 0 - let header_count = 0; + let value_len = 0 + let count = 0; if (Array.isArray(value)) { - header_count = value.length; + count = value.length; value.forEach(function(val) { if (typeof val !== 'string' && typeof val !== 'number') { throw new TypeError('Array entries must be string or number'); } - header_len += Buffer.byteLength(val + "", 'latin1'); + value_len += Buffer.byteLength(val + "", 'latin1'); }); } else { @@ -72,19 +71,27 @@ ServerResponse.prototype.setHeader = function setHeader(key, value) { throw new TypeError('Value argument must be string, number, or array'); } - header_count = 1; - header_len = Buffer.byteLength(value + "", 'latin1'); + count = 1; + value_len = Buffer.byteLength(value + "", 'latin1'); } - this.removeHeader(key); + let lc_name = name.toLowerCase(); - this.headers[key] = value; - this.headers_len += header_len + (header_key_len * header_count); - this.headers_count += header_count; + if (lc_name in this.headers) { + this._removeHeader(lc_name); + } + + let name_len = Buffer.byteLength(name, 'latin1'); + + this.headers[lc_name] = [name, value]; + this.headers_len += value_len + (name_len * count); + this.headers_count += count; }; ServerResponse.prototype.getHeader = function getHeader(name) { - return this.headers[name]; + const entry = this.headers[name.toLowerCase()]; + + return entry && entry[1]; }; ServerResponse.prototype.getHeaderNames = function getHeaderNames() { @@ -92,22 +99,43 @@ ServerResponse.prototype.getHeaderNames = function getHeaderNames() { }; ServerResponse.prototype.getHeaders = function getHeaders() { - return this.headers; + const ret = Object.create(null); + + if (this.headers) { + const keys = Object.keys(this.headers); + + for (var i = 0; i < keys.length; i++) { + const key = keys[i]; + + ret[key] = this.headers[key][1]; + } + } + + return ret; }; ServerResponse.prototype.hasHeader = function hasHeader(name) { - return name in this.headers; + return name.toLowerCase() in this.headers; }; ServerResponse.prototype.removeHeader = function removeHeader(name) { - if (!(name in this.headers)) { - return; + if (typeof name !== 'string') { + throw new TypeError('Name argument must be a string'); } - let name_len = Buffer.byteLength(name + "", 'latin1'); - let value = this.headers[name]; + let lc_name = name.toLowerCase(); + + if (lc_name in this.headers) { + this._removeHeader(lc_name); + } +}; + +ServerResponse.prototype._removeHeader = function _removeHeader(lc_name) { + let entry = this.headers[lc_name]; + let name_len = Buffer.byteLength(entry[0] + "", 'latin1'); + let value = entry[1]; - delete this.headers[name]; + delete this.headers[lc_name]; if (Array.isArray(value)) { this.headers_count -= value.length; diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp index b233359c..36bc98db 100644 --- a/src/nodejs/unit-http/unit.cpp +++ b/src/nodejs/unit-http/unit.cpp @@ -737,7 +737,7 @@ Unit::response_send_headers(napi_env env, napi_callback_info info) uint32_t keys_count, i, j; uint16_t hash; napi_value this_arg, headers, keys, name, value, array_val; - napi_value req_num; + napi_value req_num, array_entry; napi_status status; napi_valuetype val_type; nxt_unit_field_t *f; @@ -814,7 +814,17 @@ Unit::response_send_headers(napi_env env, napi_callback_info info) goto failed; } - status = napi_get_property(env, headers, name, &value); + status = napi_get_property(env, headers, name, &array_entry); + if (status != napi_ok) { + goto failed; + } + + status = napi_get_element(env, array_entry, 0, &name); + if (status != napi_ok) { + goto failed; + } + + status = napi_get_element(env, array_entry, 1, &value); if (status != napi_ok) { goto failed; } -- cgit From ab461437b5714d75e710febe3b44da49ebfe83fc Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:56:37 +0300 Subject: Node.js: checking for exception after running JS code from C++. --- src/nodejs/unit-http/unit.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp index 36bc98db..60b0412a 100644 --- a/src/nodejs/unit-http/unit.cpp +++ b/src/nodejs/unit-http/unit.cpp @@ -277,7 +277,7 @@ void Unit::request_handler(nxt_unit_request_info_t *req) { Unit *obj; - napi_value socket, request, response, global, server_obj; + napi_value socket, request, response, global, server_obj, except; napi_value emit_events, events_res, async_name, resource_object; napi_status status; napi_async_context async_context; @@ -372,8 +372,25 @@ Unit::request_handler(nxt_unit_request_info_t *req) status = napi_make_callback(obj->env_, async_context, server_obj, emit_events, 3, events_args, &events_res); if (status != napi_ok) { - napi_throw_error(obj->env_, NULL, "Failed to make callback"); - return; + if (status != napi_pending_exception) { + napi_throw_error(obj->env_, NULL, "Failed to make callback"); + return; + } + + status = napi_get_and_clear_last_exception(obj->env_, &except); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, + "Failed to get and clear last exception"); + return; + } + + /* Logging a description of the error and call stack. */ + status = napi_fatal_exception(obj->env_, except); + if (status != napi_ok) { + napi_throw_error(obj->env_, NULL, "Failed to call " + "napi_fatal_exception() function"); + return; + } } status = napi_close_callback_scope(obj->env_, async_scope); -- cgit From c55f329ecf8d32bad0d5bc2aae1da1522b3a92f8 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:56:54 +0300 Subject: libunit: added generation of version header file. --- src/nodejs/unit-http/binding.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/binding.gyp b/src/nodejs/unit-http/binding.gyp index 171c2eb7..ee09bfed 100644 --- a/src/nodejs/unit-http/binding.gyp +++ b/src/nodejs/unit-http/binding.gyp @@ -3,7 +3,7 @@ 'target_name': "unit-http", 'sources': ["unit.cpp", "addon.cpp"], 'include_dirs': [ - " Date: Wed, 19 Dec 2018 15:56:57 +0300 Subject: Node.js: added check for libunit version at compile time. --- src/nodejs/unit-http/package.json | 9 +++++---- src/nodejs/unit-http/unit.h | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/package.json b/src/nodejs/unit-http/package.json index 6a2cd27c..13c91018 100644 --- a/src/nodejs/unit-http/package.json +++ b/src/nodejs/unit-http/package.json @@ -4,14 +4,15 @@ "description": "HTTP module for NGINX Unit", "main": "http.js", "files": [ + "unit.h", + "version.h", "addon.cpp", - "binding.gyp", - "http_server.js", + "unit.cpp", "http.js", + "http_server.js", "package.json", "socket.js", - "unit.cpp", - "unit.h", + "binding.gyp", "README.md" ], "scripts": { diff --git a/src/nodejs/unit-http/unit.h b/src/nodejs/unit-http/unit.h index 5f541cc4..8baeb967 100644 --- a/src/nodejs/unit-http/unit.h +++ b/src/nodejs/unit-http/unit.h @@ -6,18 +6,23 @@ #ifndef _NXT_NODEJS_UNIT_H_INCLUDED_ #define _NXT_NODEJS_UNIT_H_INCLUDED_ - #include - #ifdef __cplusplus extern "C" { #endif +#include "version.h" #include + +#if NXT_UNIT_VERNUM != NXT_NODE_VERNUM +#error "libunit version mismatch." +#endif + #include #include + #ifdef __cplusplus } /* extern "C" */ #endif -- cgit From d9dad07934c17319b6aecd5b4958cdef3a196ad0 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:57:04 +0300 Subject: Node.js: removed unused _implicitHeader() function. --- src/nodejs/unit-http/http_server.js | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 216c4394..061c39aa 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -166,11 +166,6 @@ ServerResponse.prototype.setTimeout = function setTimeout(msecs, callback) { return this; }; -// for Express -ServerResponse.prototype._implicitHeader = function _implicitHeader() { - this.writeHead(this.statusCode); -}; - ServerResponse.prototype.writeHead = writeHead; ServerResponse.prototype.writeHeader = ServerResponse.prototype.writeHead; -- cgit From 98e8f366dabbe1b8e923678d9edd17ee61b54e0f Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Wed, 19 Dec 2018 15:57:07 +0300 Subject: Node.js: removed value checking for headers. --- src/nodejs/unit-http/http_server.js | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/nodejs') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 061c39aa..057a1f26 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -59,18 +59,10 @@ ServerResponse.prototype.setHeader = function setHeader(name, value) { count = value.length; value.forEach(function(val) { - if (typeof val !== 'string' && typeof val !== 'number') { - throw new TypeError('Array entries must be string or number'); - } - value_len += Buffer.byteLength(val + "", 'latin1'); }); } else { - if (typeof value !== 'string' && typeof value !== 'number') { - throw new TypeError('Value argument must be string, number, or array'); - } - count = 1; value_len = Buffer.byteLength(value + "", 'latin1'); } -- cgit