summaryrefslogtreecommitdiffhomepage
path: root/src/nodejs/unit-http
diff options
context:
space:
mode:
Diffstat (limited to 'src/nodejs/unit-http')
-rw-r--r--src/nodejs/unit-http/http.js4
-rw-r--r--src/nodejs/unit-http/http_server.js13
-rw-r--r--src/nodejs/unit-http/loader.js2
-rw-r--r--src/nodejs/unit-http/loader.mjs2
-rw-r--r--src/nodejs/unit-http/unit.cpp8
-rw-r--r--src/nodejs/unit-http/websocket_connection.js8
-rw-r--r--src/nodejs/unit-http/websocket_request.js8
7 files changed, 33 insertions, 12 deletions
diff --git a/src/nodejs/unit-http/http.js b/src/nodejs/unit-http/http.js
index d298a35f..60b8004f 100644
--- a/src/nodejs/unit-http/http.js
+++ b/src/nodejs/unit-http/http.js
@@ -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")
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js
index 0f00b47f..4e1c190e 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');
@@ -409,7 +413,14 @@ ServerRequest.prototype._read = function _read(n) {
};
-function Server(requestListener) {
+function Server(options, requestListener) {
+ if (typeof options === 'function') {
+ requestListener = options;
+ options = {};
+ } else {
+ console.warn("http.Server constructor was called with unsupported options, using default settings");
+ }
+
EventEmitter.call(this);
this.unit = new unit_lib.Unit();
diff --git a/src/nodejs/unit-http/loader.js b/src/nodejs/unit-http/loader.js
index e5aa3558..849df3d1 100644
--- a/src/nodejs/unit-http/loader.js
+++ b/src/nodejs/unit-http/loader.js
@@ -11,10 +11,12 @@ if (module.parent && module.parent.id === "internal/preload") {
Module.prototype.require = function (id) {
switch(id) {
case "http":
+ case "node:http":
case "unit-http":
return http
case "websocket":
+ case "node:websocket":
case "unit-http/websocket":
return websocket
}
diff --git a/src/nodejs/unit-http/loader.mjs b/src/nodejs/unit-http/loader.mjs
index 83985b0f..01fa2920 100644
--- a/src/nodejs/unit-http/loader.mjs
+++ b/src/nodejs/unit-http/loader.mjs
@@ -2,6 +2,7 @@
export async function resolve(specifier, context, defaultResolver) {
switch (specifier) {
case "websocket":
+ case "node:websocket":
return {
url: new URL("./websocket.js", import.meta.url).href,
format: "commonjs",
@@ -9,6 +10,7 @@ export async function resolve(specifier, context, defaultResolver) {
}
case "http":
+ case "node:http":
return {
url: new URL("./http.js", import.meta.url).href,
format: "commonjs",
diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp
index 7912d0ac..7d9395bb 100644
--- a/src/nodejs/unit-http/unit.cpp
+++ b/src/nodejs/unit-http/unit.cpp
@@ -581,6 +581,7 @@ Unit::get_server_object()
void
Unit::create_headers(nxt_unit_request_info_t *req, napi_value request)
{
+ char *p;
uint32_t i;
napi_value headers, raw_headers;
napi_status status;
@@ -602,7 +603,12 @@ Unit::create_headers(nxt_unit_request_info_t *req, napi_value request)
set_named_property(request, "headers", headers);
set_named_property(request, "rawHeaders", raw_headers);
- set_named_property(request, "httpVersion", r->version, r->version_length);
+
+ // trim the "HTTP/" protocol prefix
+ p = (char *) nxt_unit_sptr_get(&r->version);
+ p += 5;
+
+ set_named_property(request, "httpVersion", create_string_latin1(p, 3));
set_named_property(request, "method", r->method, r->method_length);
set_named_property(request, "url", r->target, r->target_length);
diff --git a/src/nodejs/unit-http/websocket_connection.js b/src/nodejs/unit-http/websocket_connection.js
index 4eccf6bf..c04075d7 100644
--- a/src/nodejs/unit-http/websocket_connection.js
+++ b/src/nodejs/unit-http/websocket_connection.js
@@ -36,11 +36,11 @@ var idCounter = 0;
function WebSocketConnection(socket, extensions, protocol, maskOutgoingPackets, config) {
this._debug = utils.BufferingLogger('websocket:connection', ++idCounter);
this._debug('constructor');
-
+
if (this._debug.enabled) {
instrumentSocketForDebugging(this, socket);
}
-
+
// Superclass Constructor
EventEmitter.call(this);
@@ -432,8 +432,8 @@ WebSocketConnection.prototype.processFrame = function(frame) {
// logic to emit the ping frame: this is only done when a listener is known to exist
// Expose a function allowing the user to override the default ping() behavior
var cancelled = false;
- var cancel = function() {
- cancelled = true;
+ var cancel = function() {
+ cancelled = true;
};
this.emit('ping', cancel, frame.binaryPayload);
diff --git a/src/nodejs/unit-http/websocket_request.js b/src/nodejs/unit-http/websocket_request.js
index d84e428b..450ab629 100644
--- a/src/nodejs/unit-http/websocket_request.js
+++ b/src/nodejs/unit-http/websocket_request.js
@@ -247,7 +247,7 @@ WebSocketRequest.prototype.parseCookies = function(str) {
WebSocketRequest.prototype.accept = function(acceptedProtocol, allowedOrigin, cookies) {
this._verifyResolution();
-
+
// TODO: Handle extensions
var protocolFullCase;
@@ -418,7 +418,7 @@ WebSocketRequest.prototype.accept = function(acceptedProtocol, allowedOrigin, co
// if (negotiatedExtensions) {
// response += 'Sec-WebSocket-Extensions: ' + negotiatedExtensions.join(', ') + '\r\n';
// }
-
+
// Mark the request resolved now so that the user can't call accept or
// reject a second time.
this._resolved = true;
@@ -447,12 +447,12 @@ WebSocketRequest.prototype.accept = function(acceptedProtocol, allowedOrigin, co
WebSocketRequest.prototype.reject = function(status, reason, extraHeaders) {
this._verifyResolution();
-
+
// Mark the request resolved now so that the user can't call accept or
// reject a second time.
this._resolved = true;
this.emit('requestResolved', this);
-
+
if (typeof(status) !== 'number') {
status = 403;
}