From 209dbbb1de3be3d3fcc2a2dd06c74c8764fbd27d Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Wed, 24 Jan 2024 17:03:48 +0000 Subject: [PATCH] Take options as well as requestListener Closes https://github.com/nginx/unit/issues/1043 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. --- src/nodejs/unit-http/http.js | 5 +++-- src/nodejs/unit-http/http_server.js | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/nodejs/unit-http/http.js b/src/nodejs/unit-http/http.js index d298a35fe..4781ad2cd 100644 --- a/src/nodejs/unit-http/http.js +++ b/src/nodejs/unit-http/http.js @@ -5,14 +5,15 @@ 'use strict'; +const { stderr } = require('node:process'); const { Server, ServerRequest, ServerResponse, } = require('./http_server'); -function createServer (requestHandler) { - return new Server(requestHandler); +function createServer (options, requestHandler) { + return new Server(options, requestHandler); } const http = require("http") diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 8eb13d7f3..793833ddf 100644 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -413,7 +413,14 @@ ServerRequest.prototype._read = function _read(n) { }; -function Server(requestListener) { +function Server(options, requestListener) { + if (typeof options === 'function') { + requestListener = options; + options = {}; + } else { + stderr.write('createServer was called with an options object. Unit ignores this for the time being.'); + } + EventEmitter.call(this); this.unit = new unit_lib.Unit();