owebjs 1.5.2-dev → 1.5.4-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ import {
4
4
  import { Writable } from "stream";
5
5
  import { toLowerCase } from "./utils/string.js";
6
6
  import HttpResponseSocket from './responseSocket.js';
7
+ import http from "node:http";
7
8
  class HttpResponse extends Writable {
8
9
  static {
9
10
  __name(this, "HttpResponse");
@@ -22,7 +23,7 @@ class HttpResponse extends Writable {
22
23
  this.res = uResponse;
23
24
  this.server = uServer;
24
25
  this.statusCode = 200;
25
- this.statusMessage = "OK";
26
+ this.statusMessage = null;
26
27
  this.__headers = {};
27
28
  this.headersSent = false;
28
29
  this.socket = new HttpResponseSocket(uResponse);
@@ -50,7 +51,8 @@ class HttpResponse extends Writable {
50
51
  }
51
52
  _flushHeaders() {
52
53
  if (this.headersSent) return;
53
- this.res.writeStatus(`${this.statusCode} ${this.statusMessage}`);
54
+ const message = this.statusMessage || http.STATUS_CODES[this.statusCode] || "Unknown";
55
+ this.res.writeStatus(`${this.statusCode} ${message}`);
54
56
  const keys = Object.keys(this.__headers);
55
57
  for (let i = 0; i < keys.length; i++) {
56
58
  const key = keys[i];
@@ -5,6 +5,7 @@ import { EventEmitter } from "node:events";
5
5
  const REQUEST_EVENT = "request";
6
6
  import HttpRequest from './request.js';
7
7
  import HttpResponse from './response.js';
8
+ import http from "node:http";
8
9
  async function server_default({ cert_file_name, key_file_name }) {
9
10
  let uWS;
10
11
  uWS = (await import("uWebSockets.js")).default;
@@ -84,51 +85,51 @@ async function server_default({ cert_file_name, key_file_name }) {
84
85
  };
85
86
  }
86
87
  close(cb) {
87
- uWS.us_listen_socket_close(uServer._socket);
88
- if (!cb) return;
89
- return cb();
88
+ if (uServer._socket) {
89
+ uWS.us_listen_socket_close(uServer._socket);
90
+ uServer._socket = null;
91
+ }
92
+ if (cb) cb();
90
93
  }
91
94
  start(host, port, cb) {
92
- let args;
93
- const callbackFunction = /* @__PURE__ */ __name(function(socket) {
94
- uServer._socket = socket;
95
- if (cb) cb(socket);
95
+ const callbackFunction = /* @__PURE__ */ __name(function(token) {
96
+ uServer._socket = token;
97
+ if (cb) cb(token);
96
98
  }, "callbackFunction");
97
- if (host && port && cb) {
98
- args = [
99
- host,
100
- port,
101
- callbackFunction
102
- ];
103
- }
104
- if (!cb && (!port || typeof port === "function")) {
105
- cb = port;
106
- port = host;
107
- args = [
108
- port,
109
- callbackFunction
110
- ];
99
+ if (host && port) {
100
+ return uServer.listen(host, port, callbackFunction);
101
+ } else {
102
+ return uServer.listen(port || host, callbackFunction);
111
103
  }
112
- return uServer.listen(...args);
113
104
  }
114
105
  listen(host, port, cb) {
115
106
  if (typeof host === "object") {
116
107
  const listenOptions = host;
117
108
  port = listenOptions.port;
118
109
  cb = listenOptions.cb;
119
- host = listenOptions.host;
120
- return this.start(host, port, (socket) => {
121
- uServer._socket = socket;
122
- if (cb) cb(socket);
110
+ host = listenOptions.host || "0.0.0.0";
111
+ return this.start(host, port, (token) => {
112
+ if (token) {
113
+ uServer._socket = token;
114
+ if (cb) cb(null, `http://${host}:${port}`);
115
+ } else {
116
+ if (cb) cb(new Error(`Failed to listen on ${host}:${port}`));
117
+ }
123
118
  });
124
119
  } else {
125
120
  if ((!port || typeof port === "function") && !cb) {
126
121
  cb = port;
127
122
  port = host;
128
- return this.start(port, cb);
129
- } else {
130
- return this.start(host, port, cb);
123
+ host = "0.0.0.0";
131
124
  }
125
+ return this.start(host, port, (token) => {
126
+ if (token) {
127
+ uServer._socket = token;
128
+ if (cb) cb(null, `http://${host}:${port}`);
129
+ } else {
130
+ if (cb) cb(new Error(`Failed to listen on ${host}:${port}`));
131
+ }
132
+ });
132
133
  }
133
134
  }
134
135
  ws(pattern, behaviors, hooks = []) {
@@ -195,7 +196,8 @@ async function server_default({ cert_file_name, key_file_name }) {
195
196
  send(payload) {
196
197
  if (aborted || this.finished) return;
197
198
  this.finished = true;
198
- res.writeStatus(`${this.statusCode} Response`);
199
+ const message = http.STATUS_CODES[this.statusCode] || "Response";
200
+ res.writeStatus(`${this.statusCode} ${message}`);
199
201
  for (const [k, v] of Object.entries(this._headers)) {
200
202
  res.writeHeader(k, String(v));
201
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owebjs",
3
- "version": "1.5.2-dev",
3
+ "version": "1.5.4-dev",
4
4
  "description": "A flexible and modern web framework built on top of Fastify",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",