@linebridge/engine-neo 1.0.7 → 1.1.0
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.
- package/lib/cookie.d.ts +2 -0
- package/lib/cookie.js +23 -0
- package/lib/request.d.ts +8 -10
- package/lib/request.js +4 -9
- package/lib/response.d.ts +3 -4
- package/lib/response.js +3 -3
- package/lib/uws.js +13 -7
- package/package.json +1 -2
package/lib/cookie.d.ts
ADDED
package/lib/cookie.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
export function sign(value, secret) {
|
|
3
|
+
const mac = crypto
|
|
4
|
+
.createHmac("sha256", secret)
|
|
5
|
+
.update(value)
|
|
6
|
+
.digest("base64")
|
|
7
|
+
.replace(/=+$/, "");
|
|
8
|
+
return `${value}.${mac}`;
|
|
9
|
+
}
|
|
10
|
+
export function unsign(signed_value, secret) {
|
|
11
|
+
const lastDot = signed_value.lastIndexOf(".");
|
|
12
|
+
if (lastDot === -1)
|
|
13
|
+
return undefined;
|
|
14
|
+
const value = signed_value.slice(0, lastDot);
|
|
15
|
+
const expectedSignature = sign(value, secret);
|
|
16
|
+
const expectedBuffer = Buffer.from(expectedSignature);
|
|
17
|
+
const providedBuffer = Buffer.from(signed_value);
|
|
18
|
+
if (expectedBuffer.length === providedBuffer.length &&
|
|
19
|
+
crypto.timingSafeEqual(expectedBuffer, providedBuffer)) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
package/lib/request.d.ts
CHANGED
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* body parsing (JSON, text, urlencoded, buffer), cookies, IP resolution,
|
|
6
6
|
* and path/query parameters.
|
|
7
7
|
*/
|
|
8
|
+
import { sign, unsign } from "./cookie.js";
|
|
8
9
|
import type { uWebsockets } from "./uws.js";
|
|
9
|
-
type HttpRequest = uWebsockets.HttpRequest;
|
|
10
|
-
type HttpResponse = uWebsockets.HttpResponse;
|
|
11
10
|
import type { Request as BaseHttpRequest } from "linebridge/classes/Handler/http";
|
|
12
11
|
import type { EngineAdaptor } from "linebridge/classes/EngineAdaptor/index";
|
|
13
12
|
import type { Route } from "linebridge/classes/Route/index";
|
|
@@ -46,9 +45,9 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
46
45
|
/** Parsed query string parameters (lazy). */
|
|
47
46
|
_query_parameters: any;
|
|
48
47
|
/** The raw uWS HttpRequest object. */
|
|
49
|
-
_raw_request: HttpRequest;
|
|
48
|
+
_raw_request: uWebsockets.HttpRequest;
|
|
50
49
|
/** The raw uWS HttpResponse object (needed for `onData` and `getRemoteAddress`). */
|
|
51
|
-
_raw_response: HttpResponse;
|
|
50
|
+
_raw_response: uWebsockets.HttpResponse;
|
|
52
51
|
/** Request headers extracted synchronously. */
|
|
53
52
|
_headers: Record<string, string>;
|
|
54
53
|
/** Whether all body chunks have been received. */
|
|
@@ -74,7 +73,7 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
74
73
|
/**
|
|
75
74
|
* Creates a Request instance from raw uWS objects.
|
|
76
75
|
*/
|
|
77
|
-
static create<TServer extends Server<any>>(route: Route<TServer>, raw_request: HttpRequest, raw_response: HttpResponse): Request<TServer>;
|
|
76
|
+
static create<TServer extends Server<any>>(route: Route<TServer>, raw_request: uWebsockets.HttpRequest, raw_response: uWebsockets.HttpResponse): Request<TServer>;
|
|
78
77
|
/**
|
|
79
78
|
* The engine that owns this request.
|
|
80
79
|
*/
|
|
@@ -82,7 +81,7 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
82
81
|
/**
|
|
83
82
|
* The raw uWS HttpRequest.
|
|
84
83
|
*/
|
|
85
|
-
get raw(): HttpRequest;
|
|
84
|
+
get raw(): uWebsockets.HttpRequest;
|
|
86
85
|
/**
|
|
87
86
|
* Lazily-parsed headers as a plain object.
|
|
88
87
|
* Header names are lowercased by uWS.
|
|
@@ -98,13 +97,13 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
98
97
|
*/
|
|
99
98
|
resume(): this;
|
|
100
99
|
/**
|
|
101
|
-
* Signs a string with a secret
|
|
100
|
+
* Signs a string with a secret
|
|
102
101
|
*/
|
|
103
|
-
sign
|
|
102
|
+
sign: typeof sign;
|
|
104
103
|
/**
|
|
105
104
|
* Unsigns a signed value. Returns the original string or `undefined` on failure.
|
|
106
105
|
*/
|
|
107
|
-
unsign
|
|
106
|
+
unsign: typeof unsign;
|
|
108
107
|
/**
|
|
109
108
|
* Starts the body parser by registering a uWS `onData` callback.
|
|
110
109
|
*
|
|
@@ -168,4 +167,3 @@ export default class Request<TServer = Server<any>> implements BaseHttpRequest {
|
|
|
168
167
|
*/
|
|
169
168
|
get proxy_ip(): string;
|
|
170
169
|
}
|
|
171
|
-
export {};
|
package/lib/request.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* and path/query parameters.
|
|
7
7
|
*/
|
|
8
8
|
import * as cookie from "cookie";
|
|
9
|
+
import { sign, unsign } from "./cookie.js";
|
|
9
10
|
import querystring from "fast-querystring";
|
|
10
|
-
import signature from "cookie-signature";
|
|
11
11
|
/**
|
|
12
12
|
* HTTP Request class wrapping a uWS HttpRequest.
|
|
13
13
|
*
|
|
@@ -138,18 +138,13 @@ export default class Request {
|
|
|
138
138
|
return this;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Signs a string with a secret
|
|
141
|
+
* Signs a string with a secret
|
|
142
142
|
*/
|
|
143
|
-
sign
|
|
144
|
-
return signature.sign(string, secret);
|
|
145
|
-
}
|
|
143
|
+
sign = sign;
|
|
146
144
|
/**
|
|
147
145
|
* Unsigns a signed value. Returns the original string or `undefined` on failure.
|
|
148
146
|
*/
|
|
149
|
-
unsign
|
|
150
|
-
const unsigned_value = signature.unsign(signed_value, secret);
|
|
151
|
-
return unsigned_value !== false ? unsigned_value : undefined;
|
|
152
|
-
}
|
|
147
|
+
unsign = unsign;
|
|
153
148
|
/**
|
|
154
149
|
* Starts the body parser by registering a uWS `onData` callback.
|
|
155
150
|
*
|
package/lib/response.d.ts
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import SSEventStream from "./SSEventStream.js";
|
|
9
9
|
import type { uWebsockets } from "./uws.js";
|
|
10
|
-
type HttpResponse = uWebsockets.HttpResponse;
|
|
11
10
|
import type { EngineAdaptor } from "linebridge/classes/EngineAdaptor/index";
|
|
12
11
|
import type { Route } from "linebridge/classes/Route/index";
|
|
13
12
|
import type { Server } from "linebridge/server";
|
|
@@ -39,7 +38,7 @@ export default class Response<TServer = Server<any>> implements BaseHttpResponse
|
|
|
39
38
|
/** The uWS upgrade socket (WebSocket upgrade requests only). */
|
|
40
39
|
_upgrade_socket: any;
|
|
41
40
|
/** The raw uWS HttpResponse object. */
|
|
42
|
-
_raw_response: HttpResponse | null;
|
|
41
|
+
_raw_response: uWebsockets.HttpResponse | null;
|
|
43
42
|
/** HTTP status code (defaults to 200). */
|
|
44
43
|
_status_code: number;
|
|
45
44
|
/** Custom status message (overrides the default from STATUS_CODES). */
|
|
@@ -71,7 +70,7 @@ export default class Response<TServer = Server<any>> implements BaseHttpResponse
|
|
|
71
70
|
* pending request counter, stops body parsing on the paired request, and
|
|
72
71
|
* fires abort/close event listeners.
|
|
73
72
|
*/
|
|
74
|
-
static create<TServer extends Server<any>>(raw_response: HttpResponse, route: Route<TServer>, request: any, socket: any): Response<TServer>;
|
|
73
|
+
static create<TServer extends Server<any>>(raw_response: uWebsockets.HttpResponse, route: Route<TServer>, request: any, socket: any): Response<TServer>;
|
|
75
74
|
/**
|
|
76
75
|
* Registers an event listener on the response.
|
|
77
76
|
* Supported events: `"abort"`, `"close"`, `"finish"`.
|
|
@@ -198,7 +197,7 @@ export default class Response<TServer = Server<any>> implements BaseHttpResponse
|
|
|
198
197
|
/**
|
|
199
198
|
* The raw uWS HttpResponse.
|
|
200
199
|
*/
|
|
201
|
-
get raw(): HttpResponse | null;
|
|
200
|
+
get raw(): uWebsockets.HttpResponse | null;
|
|
202
201
|
/**
|
|
203
202
|
* Whether the response has been aborted by the client.
|
|
204
203
|
*/
|
package/lib/response.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* headers, cookies (with signed cookie support), streaming, file serving,
|
|
6
6
|
* Server-Sent Events, redirects, and JSON/HTML shortcuts.
|
|
7
7
|
*/
|
|
8
|
-
import * as cookie from "cookie";
|
|
9
|
-
import signature from "cookie-signature";
|
|
10
8
|
import { STATUS_CODES } from "http";
|
|
9
|
+
import * as cookie from "cookie";
|
|
10
|
+
import { sign } from "./cookie.js";
|
|
11
11
|
import mime_types from "mime-types";
|
|
12
12
|
import SSEventStream from "./SSEventStream.js";
|
|
13
13
|
const stringify = JSON.stringify;
|
|
@@ -237,7 +237,7 @@ export default class Response {
|
|
|
237
237
|
}
|
|
238
238
|
if (sign_cookie && typeof options.secret === "string") {
|
|
239
239
|
options.encode = false;
|
|
240
|
-
value =
|
|
240
|
+
value = sign(value, options.secret);
|
|
241
241
|
}
|
|
242
242
|
if (this._cookies === null) {
|
|
243
243
|
this._cookies = Object.create(null);
|
package/lib/uws.js
CHANGED
|
@@ -11,17 +11,23 @@
|
|
|
11
11
|
* See the License for the specific language governing permissions and
|
|
12
12
|
* limitations under the License.
|
|
13
13
|
*/
|
|
14
|
-
import
|
|
14
|
+
import os from "node:os";
|
|
15
15
|
let uws_wrapper;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (process.env.IS_BUNDLED) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const mod = await import("../uws-wrapper.node");
|
|
19
|
+
uws_wrapper = mod.default ?? mod;
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
else {
|
|
20
22
|
try {
|
|
21
|
-
uws_wrapper =
|
|
23
|
+
uws_wrapper = await import(import.meta.resolve("../uws-wrapper.node"));
|
|
22
24
|
}
|
|
23
|
-
catch (
|
|
24
|
-
uws_wrapper =
|
|
25
|
+
catch (e) {
|
|
26
|
+
uws_wrapper = await import(import.meta.resolve(`../build/Release/uws-wrapper-${os.arch()}.node`));
|
|
27
|
+
}
|
|
28
|
+
if (uws_wrapper) {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
uws_wrapper = uws_wrapper.default ?? uws_wrapper;
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
export default uws_wrapper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linebridge/engine-neo",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"busboy": "^1.6.0",
|
|
30
30
|
"cookie": "^2.0.1",
|
|
31
|
-
"cookie-signature": "^1.2.2",
|
|
32
31
|
"fast-json-stringify": "^7.0.1",
|
|
33
32
|
"fast-querystring": "^1.1.2",
|
|
34
33
|
"mime-types": "^3.0.2",
|