Skip to content

Commit

Permalink
Take options as well as requestListener
Browse files Browse the repository at this point in the history
Closes nginx#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.
  • Loading branch information
javorszky committed Jan 29, 2024
1 parent 02d1984 commit b8b9872
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/nodejs/unit-http/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const {
ServerResponse,
} = require('./http_server');

function createServer (requestHandler) {
return new Server(requestHandler);
function createServer (options, requestHandler) {
return new Server(options, requestHandler);
}

const http = require("http")
Expand Down
10 changes: 9 additions & 1 deletion src/nodejs/unit-http/http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

'use strict';

const { stderr } = require('node:process');
const EventEmitter = require('events');
const http = require('http');
const util = require('util');
Expand Down Expand Up @@ -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('createServer was called with an options object. Unit ignores this for the time being.');
}

EventEmitter.call(this);

this.unit = new unit_lib.Unit();
Expand Down

0 comments on commit b8b9872

Please sign in to comment.