From 1443d623d4b5d59e4463e025b4125be9a5aa3436 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Fri, 17 Nov 2023 17:27:31 +0000 Subject: Node.js: ServerResponse.flushHeaders() implemented. This closes #1006 issue on GitHub. Reviewed-by: Andrew Clayton --- src/nodejs/unit-http/http_server.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nodejs/unit-http/http_server.js') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 0f00b47f..8eb13d7f 100644 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -138,6 +138,10 @@ ServerResponse.prototype.removeHeader = function removeHeader(name) { } }; +ServerResponse.prototype.flushHeaders = function flushHeaders() { + this._sendHeaders(); +}; + ServerResponse.prototype._removeHeader = function _removeHeader(lc_name) { let entry = this.headers[lc_name]; let name_len = Buffer.byteLength(entry[0] + "", 'latin1'); -- cgit From fbeb2065b180e2376088387ee150d3975dc08cd5 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Wed, 14 Feb 2024 18:16:01 +0000 Subject: fix: Take options as well as requestListener (#1091) * Take options as well as requestListener Unit-http have not kept up with the signature of nodejs's http package development. Nodejs allows an optional `options` object to be passed to the `createServer` function, we didn't. This resulted in function signature errors when user code that did make use of the options arg tried to call unit's replaced function. This change changes the signature to be more in line with how nodejs does it discarding it and printing a message to stdout. * Add test file to start node application with options * Add changes to docs/changes.xml Closes: https://github.com/nginx/unit/issues/1043 --- src/nodejs/unit-http/http_server.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/nodejs/unit-http/http_server.js') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 8eb13d7f..b78f309a 100644 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -5,6 +5,7 @@ 'use strict'; +const { stderr } = require('process'); const EventEmitter = require('events'); const http = require('http'); const util = require('util'); @@ -413,7 +414,14 @@ ServerRequest.prototype._read = function _read(n) { }; -function Server(requestListener) { +function Server(options, requestListener) { + if (typeof options === 'function') { + requestListener = options; + options = {}; + } else { + stderr.write("http.Server constructor was called with unsupported options, using default settings\n"); + } + EventEmitter.call(this); this.unit = new unit_lib.Unit(); -- cgit From 756feafd541160e97edfb6faf13e9942271629ce Mon Sep 17 00:00:00 2001 From: Dan Callahan Date: Mon, 19 Feb 2024 12:22:05 +0000 Subject: Node.js: Use console.warn instead of stderr.write Functionally identical, but marginally more idiomatic. Refines: fbeb2065b180e2376088387ee150d3975dc08cd5 --- src/nodejs/unit-http/http_server.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nodejs/unit-http/http_server.js') diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index b78f309a..4e1c190e 100644 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -5,7 +5,6 @@ 'use strict'; -const { stderr } = require('process'); const EventEmitter = require('events'); const http = require('http'); const util = require('util'); @@ -419,7 +418,7 @@ function Server(options, requestListener) { requestListener = options; options = {}; } else { - stderr.write("http.Server constructor was called with unsupported options, using default settings\n"); + console.warn("http.Server constructor was called with unsupported options, using default settings"); } EventEmitter.call(this); -- cgit