@whatwg-node/server 0.8.4 → 0.8.5-alpha-20230606131957-b54c4f7
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/cjs/uwebsockets.js +6 -57
- package/esm/uwebsockets.js +5 -55
- package/package.json +1 -1
- package/typings/uwebsockets.d.cts +0 -1
- package/typings/uwebsockets.d.ts +0 -1
package/cjs/uwebsockets.js
CHANGED
|
@@ -1,65 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendResponseToUwsOpts = exports.getRequestFromUWSRequest = exports.
|
|
3
|
+
exports.sendResponseToUwsOpts = exports.getRequestFromUWSRequest = exports.isUWSResponse = void 0;
|
|
4
4
|
const repeater_1 = require("@repeaterjs/repeater");
|
|
5
5
|
function isUWSResponse(res) {
|
|
6
6
|
return typeof res === 'object' && typeof res.onData === 'function';
|
|
7
7
|
}
|
|
8
8
|
exports.isUWSResponse = isUWSResponse;
|
|
9
|
-
function throwReadOnlyHeadersError() {
|
|
10
|
-
throw new Error('You cannot modify headers for a read-only request');
|
|
11
|
-
}
|
|
12
|
-
function getHeadersFromUWSRequest(req) {
|
|
13
|
-
return {
|
|
14
|
-
append() {
|
|
15
|
-
throwReadOnlyHeadersError();
|
|
16
|
-
},
|
|
17
|
-
delete() {
|
|
18
|
-
throwReadOnlyHeadersError();
|
|
19
|
-
},
|
|
20
|
-
get(key) {
|
|
21
|
-
return req.getHeader(key) || null;
|
|
22
|
-
},
|
|
23
|
-
has(key) {
|
|
24
|
-
return req.getHeader(key) != null;
|
|
25
|
-
},
|
|
26
|
-
set() {
|
|
27
|
-
throwReadOnlyHeadersError();
|
|
28
|
-
},
|
|
29
|
-
forEach(callback) {
|
|
30
|
-
req.forEach((key, value) => callback(value, key, this));
|
|
31
|
-
},
|
|
32
|
-
entries() {
|
|
33
|
-
const entries = [];
|
|
34
|
-
this.forEach((value, key) => {
|
|
35
|
-
entries.push([key, value]);
|
|
36
|
-
});
|
|
37
|
-
return entries[Symbol.iterator]();
|
|
38
|
-
},
|
|
39
|
-
keys() {
|
|
40
|
-
const keys = [];
|
|
41
|
-
this.forEach((_, key) => {
|
|
42
|
-
keys.push(key);
|
|
43
|
-
});
|
|
44
|
-
return keys[Symbol.iterator]();
|
|
45
|
-
},
|
|
46
|
-
values() {
|
|
47
|
-
const values = [];
|
|
48
|
-
this.forEach(value => {
|
|
49
|
-
values.push(value);
|
|
50
|
-
});
|
|
51
|
-
return values[Symbol.iterator]();
|
|
52
|
-
},
|
|
53
|
-
[Symbol.iterator]() {
|
|
54
|
-
const entries = [];
|
|
55
|
-
this.forEach((value, key) => {
|
|
56
|
-
entries.push([key, value]);
|
|
57
|
-
});
|
|
58
|
-
return entries[Symbol.iterator]();
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
exports.getHeadersFromUWSRequest = getHeadersFromUWSRequest;
|
|
63
9
|
function getRequestFromUWSRequest({ req, res, fetchAPI }) {
|
|
64
10
|
let body;
|
|
65
11
|
const method = req.getMethod();
|
|
@@ -67,14 +13,17 @@ function getRequestFromUWSRequest({ req, res, fetchAPI }) {
|
|
|
67
13
|
body = new repeater_1.Repeater(function (push, stop) {
|
|
68
14
|
res.onAborted(stop);
|
|
69
15
|
res.onData(function (chunk, isLast) {
|
|
70
|
-
push(Buffer.from(chunk));
|
|
16
|
+
push(Buffer.from(chunk, 0, chunk.byteLength));
|
|
71
17
|
if (isLast) {
|
|
72
18
|
stop();
|
|
73
19
|
}
|
|
74
20
|
});
|
|
75
21
|
});
|
|
76
22
|
}
|
|
77
|
-
const headers =
|
|
23
|
+
const headers = {};
|
|
24
|
+
req.forEach((key, value) => {
|
|
25
|
+
headers[key] = value;
|
|
26
|
+
});
|
|
78
27
|
const url = `http://localhost${req.getUrl()}`;
|
|
79
28
|
return new fetchAPI.Request(url, {
|
|
80
29
|
method,
|
package/esm/uwebsockets.js
CHANGED
|
@@ -2,59 +2,6 @@ import { Repeater } from '@repeaterjs/repeater';
|
|
|
2
2
|
export function isUWSResponse(res) {
|
|
3
3
|
return typeof res === 'object' && typeof res.onData === 'function';
|
|
4
4
|
}
|
|
5
|
-
function throwReadOnlyHeadersError() {
|
|
6
|
-
throw new Error('You cannot modify headers for a read-only request');
|
|
7
|
-
}
|
|
8
|
-
export function getHeadersFromUWSRequest(req) {
|
|
9
|
-
return {
|
|
10
|
-
append() {
|
|
11
|
-
throwReadOnlyHeadersError();
|
|
12
|
-
},
|
|
13
|
-
delete() {
|
|
14
|
-
throwReadOnlyHeadersError();
|
|
15
|
-
},
|
|
16
|
-
get(key) {
|
|
17
|
-
return req.getHeader(key) || null;
|
|
18
|
-
},
|
|
19
|
-
has(key) {
|
|
20
|
-
return req.getHeader(key) != null;
|
|
21
|
-
},
|
|
22
|
-
set() {
|
|
23
|
-
throwReadOnlyHeadersError();
|
|
24
|
-
},
|
|
25
|
-
forEach(callback) {
|
|
26
|
-
req.forEach((key, value) => callback(value, key, this));
|
|
27
|
-
},
|
|
28
|
-
entries() {
|
|
29
|
-
const entries = [];
|
|
30
|
-
this.forEach((value, key) => {
|
|
31
|
-
entries.push([key, value]);
|
|
32
|
-
});
|
|
33
|
-
return entries[Symbol.iterator]();
|
|
34
|
-
},
|
|
35
|
-
keys() {
|
|
36
|
-
const keys = [];
|
|
37
|
-
this.forEach((_, key) => {
|
|
38
|
-
keys.push(key);
|
|
39
|
-
});
|
|
40
|
-
return keys[Symbol.iterator]();
|
|
41
|
-
},
|
|
42
|
-
values() {
|
|
43
|
-
const values = [];
|
|
44
|
-
this.forEach(value => {
|
|
45
|
-
values.push(value);
|
|
46
|
-
});
|
|
47
|
-
return values[Symbol.iterator]();
|
|
48
|
-
},
|
|
49
|
-
[Symbol.iterator]() {
|
|
50
|
-
const entries = [];
|
|
51
|
-
this.forEach((value, key) => {
|
|
52
|
-
entries.push([key, value]);
|
|
53
|
-
});
|
|
54
|
-
return entries[Symbol.iterator]();
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
5
|
export function getRequestFromUWSRequest({ req, res, fetchAPI }) {
|
|
59
6
|
let body;
|
|
60
7
|
const method = req.getMethod();
|
|
@@ -62,14 +9,17 @@ export function getRequestFromUWSRequest({ req, res, fetchAPI }) {
|
|
|
62
9
|
body = new Repeater(function (push, stop) {
|
|
63
10
|
res.onAborted(stop);
|
|
64
11
|
res.onData(function (chunk, isLast) {
|
|
65
|
-
push(Buffer.from(chunk));
|
|
12
|
+
push(Buffer.from(chunk, 0, chunk.byteLength));
|
|
66
13
|
if (isLast) {
|
|
67
14
|
stop();
|
|
68
15
|
}
|
|
69
16
|
});
|
|
70
17
|
});
|
|
71
18
|
}
|
|
72
|
-
const headers =
|
|
19
|
+
const headers = {};
|
|
20
|
+
req.forEach((key, value) => {
|
|
21
|
+
headers[key] = value;
|
|
22
|
+
});
|
|
73
23
|
const url = `http://localhost${req.getUrl()}`;
|
|
74
24
|
return new fetchAPI.Request(url, {
|
|
75
25
|
method,
|
package/package.json
CHANGED
|
@@ -16,7 +16,6 @@ export interface UWSResponse {
|
|
|
16
16
|
}
|
|
17
17
|
export type UWSHandler = (res: UWSResponse, req: UWSRequest) => void | Promise<void>;
|
|
18
18
|
export declare function isUWSResponse(res: any): res is UWSResponse;
|
|
19
|
-
export declare function getHeadersFromUWSRequest(req: UWSRequest): Headers;
|
|
20
19
|
interface GetRequestFromUWSOpts {
|
|
21
20
|
req: UWSRequest;
|
|
22
21
|
res: UWSResponse;
|
package/typings/uwebsockets.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export interface UWSResponse {
|
|
|
16
16
|
}
|
|
17
17
|
export type UWSHandler = (res: UWSResponse, req: UWSRequest) => void | Promise<void>;
|
|
18
18
|
export declare function isUWSResponse(res: any): res is UWSResponse;
|
|
19
|
-
export declare function getHeadersFromUWSRequest(req: UWSRequest): Headers;
|
|
20
19
|
interface GetRequestFromUWSOpts {
|
|
21
20
|
req: UWSRequest;
|
|
22
21
|
res: UWSResponse;
|