openportal 0.1.1 → 0.1.3
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/README.md +113 -0
- package/package.json +1 -1
- package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_buildManifest.js +4 -9
- package/web/.next/static/chunks/{2e7bfb90c343ca96.js → 35cc9dbdc670c73c.js} +4 -4
- package/web/.next/static/chunks/4147ffc67a7b837c.css +1 -0
- package/web/.next/static/chunks/{21ab2574b84ad2d1.js → 52b90bc1740162c2.js} +2 -2
- package/web/.next/static/chunks/{9b265e2198b5525f.js → 8644d68bf325ff24.js} +3 -3
- package/web/.next/static/chunks/{03e1846335a31354.js → 9865709466b09f79.js} +3 -3
- package/web/.next/static/chunks/{c20ae04df8cc28be.js → 9ba9a5774c9421bd.js} +3 -3
- package/web/.next/static/chunks/{967a1e0002fe9ae6.js → b5caad256518cb33.js} +3 -3
- package/web/.next/static/chunks/{turbopack-27558c851386934e.js → turbopack-26af71e419c11487.js} +1 -1
- package/web/.next/static/chunks/{turbopack-f4c0881f9723f5a5.js → turbopack-4ad0df7330c00c8d.js} +1 -1
- package/web/.next/static/chunks/{turbopack-26688626142ac58f.js → turbopack-8e653f3ad3a8ed18.js} +1 -1
- package/web/.next/static/chunks/{turbopack-c40ec6674624f1d7.js → turbopack-d5098189d63fd7b8.js} +1 -1
- package/web/apps/web/.next/BUILD_ID +1 -1
- package/web/apps/web/.next/build-manifest.json +14 -24
- package/web/apps/web/.next/routes-manifest.json +0 -12
- package/web/apps/web/.next/server/chunks/[root-of-the-server]__f366ca98._.js +358 -0
- package/web/apps/web/.next/server/chunks/ssr/{[root-of-the-server]__dfeaf8cf._.js → [root-of-the-server]__1a54ba1e._.js} +3 -3
- package/web/apps/web/.next/server/middleware-build-manifest.js +12 -22
- package/web/apps/web/.next/server/next-font-manifest.js +1 -1
- package/web/apps/web/.next/server/next-font-manifest.json +0 -4
- package/web/apps/web/.next/server/pages/404.html +1 -1
- package/web/apps/web/.next/server/pages/500.html +1 -1
- package/web/apps/web/.next/server/pages/_app/build-manifest.json +3 -3
- package/web/apps/web/.next/server/pages/_app/client-build-manifest.json +1 -1
- package/web/apps/web/.next/server/pages/api/[[...slugs]].js +1 -2
- package/web/apps/web/.next/server/pages/api/[[...slugs]].js.nft.json +1 -1
- package/web/apps/web/.next/server/pages/index/build-manifest.json +3 -3
- package/web/apps/web/.next/server/pages/index/client-build-manifest.json +1 -1
- package/web/apps/web/.next/server/pages/index.html +1 -1
- package/web/apps/web/.next/server/pages/index.js.nft.json +1 -1
- package/web/apps/web/.next/server/pages/session/[id]/build-manifest.json +4 -4
- package/web/apps/web/.next/server/pages/session/[id]/client-build-manifest.json +1 -1
- package/web/apps/web/.next/server/pages/session/[id].html +1 -1
- package/web/apps/web/.next/server/pages/session/[id].js.nft.json +1 -1
- package/web/apps/web/.next/server/pages/settings/build-manifest.json +3 -3
- package/web/apps/web/.next/server/pages/settings/client-build-manifest.json +1 -1
- package/web/apps/web/.next/server/pages/settings.html +1 -1
- package/web/apps/web/.next/server/pages/settings.js.nft.json +1 -1
- package/web/apps/web/.next/server/pages-manifest.json +0 -2
- package/web/apps/web/package.json +1 -9
- package/web/.next/static/chunks/04d4692d75696297.css +0 -1
- package/web/.next/static/chunks/553710f60e2f2b11.js +0 -1
- package/web/.next/static/chunks/58acbbb4090e3362.js +0 -3
- package/web/.next/static/chunks/6ce1e2f08f961db5.js +0 -2
- package/web/.next/static/chunks/d316d63225992c76.js +0 -10
- package/web/.next/static/chunks/e0c97552ba7a9e3d.js +0 -1
- package/web/.next/static/chunks/fc9c4f2dabfb4e0e.css +0 -1
- package/web/.next/static/chunks/turbopack-1837909a677d116b.js +0 -3
- package/web/apps/web/.next/server/chunks/[root-of-the-server]__0f75905d._.js +0 -3
- package/web/apps/web/.next/server/chunks/[root-of-the-server]__89e85365._.js +0 -358
- package/web/apps/web/.next/server/chunks/[root-of-the-server]__ae1361d0._.js +0 -3
- package/web/apps/web/.next/server/pages/api/terminal/ws/pages-manifest.json +0 -3
- package/web/apps/web/.next/server/pages/api/terminal/ws.js +0 -5
- package/web/apps/web/.next/server/pages/api/terminal/ws.js.map +0 -5
- package/web/apps/web/.next/server/pages/api/terminal/ws.js.nft.json +0 -1
- package/web/apps/web/.next/server/pages/terminal/build-manifest.json +0 -20
- package/web/apps/web/.next/server/pages/terminal/client-build-manifest.json +0 -5
- package/web/apps/web/.next/server/pages/terminal/next-font-manifest.json +0 -11
- package/web/apps/web/.next/server/pages/terminal/pages-manifest.json +0 -3
- package/web/apps/web/.next/server/pages/terminal/react-loadable-manifest.json +0 -1
- package/web/apps/web/.next/server/pages/terminal.html +0 -1
- package/web/apps/web/.next/server/pages/terminal.js.map +0 -5
- package/web/apps/web/.next/server/pages/terminal.js.nft.json +0 -1
- package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/cjs/index.js +0 -176
- package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/cjs/package.json +0 -4
- package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/package.json +0 -28
- package/web/node_modules/.bun/accepts@1.3.8/node_modules/accepts/index.js +0 -238
- package/web/node_modules/.bun/accepts@1.3.8/node_modules/accepts/package.json +0 -47
- package/web/node_modules/.bun/base64id@2.0.0/node_modules/base64id/lib/base64id.js +0 -103
- package/web/node_modules/.bun/base64id@2.0.0/node_modules/base64id/package.json +0 -13
- package/web/node_modules/.bun/cookie@0.7.2/node_modules/cookie/index.js +0 -335
- package/web/node_modules/.bun/cookie@0.7.2/node_modules/cookie/package.json +0 -44
- package/web/node_modules/.bun/cookie@1.1.1/node_modules/cookie/package.json +0 -47
- package/web/node_modules/.bun/cors@2.8.5/node_modules/cors/lib/index.js +0 -238
- package/web/node_modules/.bun/cors@2.8.5/node_modules/cors/package.json +0 -41
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/package.json +0 -60
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/browser.js +0 -271
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/common.js +0 -274
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/index.js +0 -10
- package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/node.js +0 -263
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/commons.js +0 -19
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/decodePacket.js +0 -59
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/encodePacket.js +0 -38
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/index.js +0 -164
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/package.json +0 -8
- package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/package.json +0 -46
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/engine.io.js +0 -54
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/parser-v3/index.js +0 -424
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/parser-v3/utf8.js +0 -187
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/server.js +0 -786
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/socket.js +0 -460
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transport.js +0 -117
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/index.js +0 -23
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/polling-jsonp.js +0 -41
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/polling.js +0 -332
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/websocket.js +0 -94
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/webtransport.js +0 -63
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/index.js +0 -8
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/polling.js +0 -364
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/websocket.js +0 -73
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/userver.js +0 -279
- package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/package.json +0 -70
- package/web/node_modules/.bun/has-flag@4.0.0/node_modules/has-flag/index.js +0 -8
- package/web/node_modules/.bun/has-flag@4.0.0/node_modules/has-flag/package.json +0 -46
- package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/db.json +0 -8519
- package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/index.js +0 -12
- package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/package.json +0 -60
- package/web/node_modules/.bun/mime-types@2.1.35/node_modules/mime-types/index.js +0 -188
- package/web/node_modules/.bun/mime-types@2.1.35/node_modules/mime-types/package.json +0 -44
- package/web/node_modules/.bun/ms@2.1.3/node_modules/ms/index.js +0 -162
- package/web/node_modules/.bun/ms@2.1.3/node_modules/ms/package.json +0 -38
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/index.js +0 -82
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/charset.js +0 -169
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/encoding.js +0 -184
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/language.js +0 -179
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/mediaType.js +0 -294
- package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/package.json +0 -42
- package/web/node_modules/.bun/object-assign@4.1.1/node_modules/object-assign/index.js +0 -90
- package/web/node_modules/.bun/object-assign@4.1.1/node_modules/object-assign/package.json +0 -42
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/cluster-adapter.js +0 -674
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/contrib/yeast.js +0 -55
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/in-memory-adapter.js +0 -394
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/index.js +0 -10
- package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/package.json +0 -39
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/binary.js +0 -88
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/index.js +0 -321
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/is-binary.js +0 -55
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/package.json +0 -3
- package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/package.json +0 -58
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.esm.min.js +0 -7
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.js +0 -4908
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.min.js +0 -7
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.msgpack.min.js +0 -7
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/broadcast-operator.js +0 -436
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/client.js +0 -268
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/index.js +0 -804
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/namespace.js +0 -581
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/parent-namespace.js +0 -88
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/socket-types.js +0 -11
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/socket.js +0 -977
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/typed-events.js +0 -81
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/uws.js +0 -136
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/package.json +0 -85
- package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/wrapper.mjs +0 -3
- package/web/node_modules/.bun/supports-color@7.2.0/node_modules/supports-color/index.js +0 -135
- package/web/node_modules/.bun/supports-color@7.2.0/node_modules/supports-color/package.json +0 -53
- package/web/node_modules/.bun/vary@1.1.2/node_modules/vary/index.js +0 -149
- package/web/node_modules/.bun/vary@1.1.2/node_modules/vary/package.json +0 -43
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/index.js +0 -13
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/buffer-util.js +0 -131
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/constants.js +0 -12
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/event-target.js +0 -292
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/extension.js +0 -203
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/limiter.js +0 -55
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/permessage-deflate.js +0 -514
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/receiver.js +0 -704
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/sender.js +0 -497
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/stream.js +0 -159
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/subprotocol.js +0 -62
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/validation.js +0 -130
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/websocket-server.js +0 -540
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/websocket.js +0 -1338
- package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/package.json +0 -69
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/buffer-util.js +0 -131
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/constants.js +0 -18
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/event-target.js +0 -292
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/extension.js +0 -203
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/limiter.js +0 -55
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/permessage-deflate.js +0 -528
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/receiver.js +0 -706
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/sender.js +0 -602
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/stream.js +0 -161
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/subprotocol.js +0 -62
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/validation.js +0 -152
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/websocket-server.js +0 -550
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/websocket.js +0 -1388
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/package.json +0 -69
- package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/wrapper.mjs +0 -8
- /package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_clientMiddlewareManifest.json +0 -0
- /package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_ssgManifest.js +0 -0
package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/polling.js
DELETED
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Polling = void 0;
|
|
4
|
-
const transport_1 = require("../transport");
|
|
5
|
-
const zlib_1 = require("zlib");
|
|
6
|
-
const accepts = require("accepts");
|
|
7
|
-
const debug_1 = require("debug");
|
|
8
|
-
const debug = (0, debug_1.default)("engine:polling");
|
|
9
|
-
const compressionMethods = {
|
|
10
|
-
gzip: zlib_1.createGzip,
|
|
11
|
-
deflate: zlib_1.createDeflate,
|
|
12
|
-
};
|
|
13
|
-
class Polling extends transport_1.Transport {
|
|
14
|
-
/**
|
|
15
|
-
* HTTP polling constructor.
|
|
16
|
-
*/
|
|
17
|
-
constructor(req) {
|
|
18
|
-
super(req);
|
|
19
|
-
this.closeTimeout = 30 * 1000;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Transport name
|
|
23
|
-
*/
|
|
24
|
-
get name() {
|
|
25
|
-
return "polling";
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Overrides onRequest.
|
|
29
|
-
*
|
|
30
|
-
* @param req
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
onRequest(req) {
|
|
35
|
-
const res = req.res;
|
|
36
|
-
// remove the reference to the ServerResponse object (as the first request of the session is kept in memory by default)
|
|
37
|
-
req.res = null;
|
|
38
|
-
if (req.getMethod() === "get") {
|
|
39
|
-
this.onPollRequest(req, res);
|
|
40
|
-
}
|
|
41
|
-
else if (req.getMethod() === "post") {
|
|
42
|
-
this.onDataRequest(req, res);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
res.writeStatus("500 Internal Server Error");
|
|
46
|
-
res.end();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* The client sends a request awaiting for us to send data.
|
|
51
|
-
*
|
|
52
|
-
* @private
|
|
53
|
-
*/
|
|
54
|
-
onPollRequest(req, res) {
|
|
55
|
-
if (this.req) {
|
|
56
|
-
debug("request overlap");
|
|
57
|
-
// assert: this.res, '.req and .res should be (un)set together'
|
|
58
|
-
this.onError("overlap from client");
|
|
59
|
-
res.writeStatus("500 Internal Server Error");
|
|
60
|
-
res.end();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
debug("setting request");
|
|
64
|
-
this.req = req;
|
|
65
|
-
this.res = res;
|
|
66
|
-
const onClose = () => {
|
|
67
|
-
this.writable = false;
|
|
68
|
-
this.onError("poll connection closed prematurely");
|
|
69
|
-
};
|
|
70
|
-
const cleanup = () => {
|
|
71
|
-
this.req = this.res = null;
|
|
72
|
-
};
|
|
73
|
-
req.cleanup = cleanup;
|
|
74
|
-
res.onAborted(onClose);
|
|
75
|
-
this.writable = true;
|
|
76
|
-
this.emit("ready");
|
|
77
|
-
// if we're still writable but had a pending close, trigger an empty send
|
|
78
|
-
if (this.writable && this.shouldClose) {
|
|
79
|
-
debug("triggering empty send to append close packet");
|
|
80
|
-
this.send([{ type: "noop" }]);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The client sends a request with data.
|
|
85
|
-
*
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
onDataRequest(req, res) {
|
|
89
|
-
if (this.dataReq) {
|
|
90
|
-
// assert: this.dataRes, '.dataReq and .dataRes should be (un)set together'
|
|
91
|
-
this.onError("data request overlap from client");
|
|
92
|
-
res.writeStatus("500 Internal Server Error");
|
|
93
|
-
res.end();
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const expectedContentLength = Number(req.headers["content-length"]);
|
|
97
|
-
if (!expectedContentLength) {
|
|
98
|
-
this.onError("content-length header required");
|
|
99
|
-
res.writeStatus("411 Length Required").end();
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (expectedContentLength > this.maxHttpBufferSize) {
|
|
103
|
-
this.onError("payload too large");
|
|
104
|
-
res.writeStatus("413 Payload Too Large").end();
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const isBinary = "application/octet-stream" === req.headers["content-type"];
|
|
108
|
-
if (isBinary && this.protocol === 4) {
|
|
109
|
-
return this.onError("invalid content");
|
|
110
|
-
}
|
|
111
|
-
this.dataReq = req;
|
|
112
|
-
this.dataRes = res;
|
|
113
|
-
let buffer;
|
|
114
|
-
let offset = 0;
|
|
115
|
-
const headers = {
|
|
116
|
-
// text/html is required instead of text/plain to avoid an
|
|
117
|
-
// unwanted download dialog on certain user-agents (GH-43)
|
|
118
|
-
"Content-Type": "text/html",
|
|
119
|
-
};
|
|
120
|
-
this.headers(req, headers);
|
|
121
|
-
for (let key in headers) {
|
|
122
|
-
res.writeHeader(key, String(headers[key]));
|
|
123
|
-
}
|
|
124
|
-
const onEnd = (buffer) => {
|
|
125
|
-
this.onData(buffer.toString());
|
|
126
|
-
this.onDataRequestCleanup();
|
|
127
|
-
res.cork(() => {
|
|
128
|
-
res.end("ok");
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
res.onAborted(() => {
|
|
132
|
-
this.onDataRequestCleanup();
|
|
133
|
-
this.onError("data request connection closed prematurely");
|
|
134
|
-
});
|
|
135
|
-
res.onData((arrayBuffer, isLast) => {
|
|
136
|
-
const totalLength = offset + arrayBuffer.byteLength;
|
|
137
|
-
if (totalLength > expectedContentLength) {
|
|
138
|
-
this.onError("content-length mismatch");
|
|
139
|
-
res.close(); // calls onAborted
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (!buffer) {
|
|
143
|
-
if (isLast) {
|
|
144
|
-
onEnd(Buffer.from(arrayBuffer));
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
buffer = Buffer.allocUnsafe(expectedContentLength);
|
|
148
|
-
}
|
|
149
|
-
Buffer.from(arrayBuffer).copy(buffer, offset);
|
|
150
|
-
if (isLast) {
|
|
151
|
-
if (totalLength != expectedContentLength) {
|
|
152
|
-
this.onError("content-length mismatch");
|
|
153
|
-
res.writeStatus("400 Content-Length Mismatch").end();
|
|
154
|
-
this.onDataRequestCleanup();
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
onEnd(buffer);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
offset = totalLength;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Cleanup request.
|
|
165
|
-
*
|
|
166
|
-
* @private
|
|
167
|
-
*/
|
|
168
|
-
onDataRequestCleanup() {
|
|
169
|
-
this.dataReq = this.dataRes = null;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Processes the incoming data payload.
|
|
173
|
-
*
|
|
174
|
-
* @param {String} encoded payload
|
|
175
|
-
* @private
|
|
176
|
-
*/
|
|
177
|
-
onData(data) {
|
|
178
|
-
debug('received "%s"', data);
|
|
179
|
-
const callback = (packet) => {
|
|
180
|
-
if ("close" === packet.type) {
|
|
181
|
-
debug("got xhr close packet");
|
|
182
|
-
this.onClose();
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
this.onPacket(packet);
|
|
186
|
-
};
|
|
187
|
-
if (this.protocol === 3) {
|
|
188
|
-
this.parser.decodePayload(data, callback);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
this.parser.decodePayload(data).forEach(callback);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Overrides onClose.
|
|
196
|
-
*
|
|
197
|
-
* @private
|
|
198
|
-
*/
|
|
199
|
-
onClose() {
|
|
200
|
-
if (this.writable) {
|
|
201
|
-
// close pending poll request
|
|
202
|
-
this.send([{ type: "noop" }]);
|
|
203
|
-
}
|
|
204
|
-
super.onClose();
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Writes a packet payload.
|
|
208
|
-
*
|
|
209
|
-
* @param {Object} packet
|
|
210
|
-
* @private
|
|
211
|
-
*/
|
|
212
|
-
send(packets) {
|
|
213
|
-
this.writable = false;
|
|
214
|
-
if (this.shouldClose) {
|
|
215
|
-
debug("appending close packet to payload");
|
|
216
|
-
packets.push({ type: "close" });
|
|
217
|
-
this.shouldClose();
|
|
218
|
-
this.shouldClose = null;
|
|
219
|
-
}
|
|
220
|
-
const doWrite = (data) => {
|
|
221
|
-
const compress = packets.some((packet) => {
|
|
222
|
-
return packet.options && packet.options.compress;
|
|
223
|
-
});
|
|
224
|
-
this.write(data, { compress });
|
|
225
|
-
};
|
|
226
|
-
if (this.protocol === 3) {
|
|
227
|
-
this.parser.encodePayload(packets, this.supportsBinary, doWrite);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
this.parser.encodePayload(packets, doWrite);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Writes data as response to poll request.
|
|
235
|
-
*
|
|
236
|
-
* @param {String} data
|
|
237
|
-
* @param {Object} options
|
|
238
|
-
* @private
|
|
239
|
-
*/
|
|
240
|
-
write(data, options) {
|
|
241
|
-
debug('writing "%s"', data);
|
|
242
|
-
this.doWrite(data, options, () => {
|
|
243
|
-
this.req.cleanup();
|
|
244
|
-
this.emit("drain");
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Performs the write.
|
|
249
|
-
*
|
|
250
|
-
* @private
|
|
251
|
-
*/
|
|
252
|
-
doWrite(data, options, callback) {
|
|
253
|
-
// explicit UTF-8 is required for pages not served under utf
|
|
254
|
-
const isString = typeof data === "string";
|
|
255
|
-
const contentType = isString
|
|
256
|
-
? "text/plain; charset=UTF-8"
|
|
257
|
-
: "application/octet-stream";
|
|
258
|
-
const headers = {
|
|
259
|
-
"Content-Type": contentType,
|
|
260
|
-
};
|
|
261
|
-
const respond = (data) => {
|
|
262
|
-
this.headers(this.req, headers);
|
|
263
|
-
this.res.cork(() => {
|
|
264
|
-
Object.keys(headers).forEach((key) => {
|
|
265
|
-
this.res.writeHeader(key, String(headers[key]));
|
|
266
|
-
});
|
|
267
|
-
this.res.end(data);
|
|
268
|
-
});
|
|
269
|
-
callback();
|
|
270
|
-
};
|
|
271
|
-
if (!this.httpCompression || !options.compress) {
|
|
272
|
-
respond(data);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const len = isString ? Buffer.byteLength(data) : data.length;
|
|
276
|
-
if (len < this.httpCompression.threshold) {
|
|
277
|
-
respond(data);
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
const encoding = accepts(this.req).encodings(["gzip", "deflate"]);
|
|
281
|
-
if (!encoding) {
|
|
282
|
-
respond(data);
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
this.compress(data, encoding, (err, data) => {
|
|
286
|
-
if (err) {
|
|
287
|
-
this.res.writeStatus("500 Internal Server Error");
|
|
288
|
-
this.res.end();
|
|
289
|
-
callback(err);
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
headers["Content-Encoding"] = encoding;
|
|
293
|
-
respond(data);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Compresses data.
|
|
298
|
-
*
|
|
299
|
-
* @private
|
|
300
|
-
*/
|
|
301
|
-
compress(data, encoding, callback) {
|
|
302
|
-
debug("compressing");
|
|
303
|
-
const buffers = [];
|
|
304
|
-
let nread = 0;
|
|
305
|
-
compressionMethods[encoding](this.httpCompression)
|
|
306
|
-
.on("error", callback)
|
|
307
|
-
.on("data", function (chunk) {
|
|
308
|
-
buffers.push(chunk);
|
|
309
|
-
nread += chunk.length;
|
|
310
|
-
})
|
|
311
|
-
.on("end", function () {
|
|
312
|
-
callback(null, Buffer.concat(buffers, nread));
|
|
313
|
-
})
|
|
314
|
-
.end(data);
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Closes the transport.
|
|
318
|
-
*
|
|
319
|
-
* @private
|
|
320
|
-
*/
|
|
321
|
-
doClose(fn) {
|
|
322
|
-
debug("closing");
|
|
323
|
-
let closeTimeoutTimer;
|
|
324
|
-
const onClose = () => {
|
|
325
|
-
clearTimeout(closeTimeoutTimer);
|
|
326
|
-
fn();
|
|
327
|
-
this.onClose();
|
|
328
|
-
};
|
|
329
|
-
if (this.writable) {
|
|
330
|
-
debug("transport writable - closing right away");
|
|
331
|
-
this.send([{ type: "close" }]);
|
|
332
|
-
onClose();
|
|
333
|
-
}
|
|
334
|
-
else if (this.discarded) {
|
|
335
|
-
debug("transport discarded - closing right away");
|
|
336
|
-
onClose();
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
debug("transport not writable - buffering orderly close");
|
|
340
|
-
this.shouldClose = onClose;
|
|
341
|
-
closeTimeoutTimer = setTimeout(onClose, this.closeTimeout);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Returns headers for a response.
|
|
346
|
-
*
|
|
347
|
-
* @param req - request
|
|
348
|
-
* @param {Object} extra headers
|
|
349
|
-
* @private
|
|
350
|
-
*/
|
|
351
|
-
headers(req, headers) {
|
|
352
|
-
headers = headers || {};
|
|
353
|
-
// prevent XSS warnings on IE
|
|
354
|
-
// https://github.com/LearnBoost/socket.io/pull/1333
|
|
355
|
-
const ua = req.headers["user-agent"];
|
|
356
|
-
if (ua && (~ua.indexOf(";MSIE") || ~ua.indexOf("Trident/"))) {
|
|
357
|
-
headers["X-XSS-Protection"] = "0";
|
|
358
|
-
}
|
|
359
|
-
headers["cache-control"] = "no-store";
|
|
360
|
-
this.emit("headers", headers, req);
|
|
361
|
-
return headers;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
exports.Polling = Polling;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebSocket = void 0;
|
|
4
|
-
const transport_1 = require("../transport");
|
|
5
|
-
const debug_1 = require("debug");
|
|
6
|
-
const debug = (0, debug_1.default)("engine:ws");
|
|
7
|
-
class WebSocket extends transport_1.Transport {
|
|
8
|
-
/**
|
|
9
|
-
* WebSocket transport
|
|
10
|
-
*
|
|
11
|
-
* @param req
|
|
12
|
-
*/
|
|
13
|
-
constructor(req) {
|
|
14
|
-
super(req);
|
|
15
|
-
this.writable = false;
|
|
16
|
-
this.perMessageDeflate = null;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Transport name
|
|
20
|
-
*/
|
|
21
|
-
get name() {
|
|
22
|
-
return "websocket";
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Advertise upgrade support.
|
|
26
|
-
*/
|
|
27
|
-
get handlesUpgrades() {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Writes a packet payload.
|
|
32
|
-
*
|
|
33
|
-
* @param {Array} packets
|
|
34
|
-
* @private
|
|
35
|
-
*/
|
|
36
|
-
send(packets) {
|
|
37
|
-
this.writable = false;
|
|
38
|
-
for (let i = 0; i < packets.length; i++) {
|
|
39
|
-
const packet = packets[i];
|
|
40
|
-
const isLast = i + 1 === packets.length;
|
|
41
|
-
const send = (data) => {
|
|
42
|
-
const isBinary = typeof data !== "string";
|
|
43
|
-
const compress = this.perMessageDeflate &&
|
|
44
|
-
Buffer.byteLength(data) > this.perMessageDeflate.threshold;
|
|
45
|
-
debug('writing "%s"', data);
|
|
46
|
-
this.socket.send(data, isBinary, compress);
|
|
47
|
-
if (isLast) {
|
|
48
|
-
this.emit("drain");
|
|
49
|
-
this.writable = true;
|
|
50
|
-
this.emit("ready");
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
if (packet.options && typeof packet.options.wsPreEncoded === "string") {
|
|
54
|
-
send(packet.options.wsPreEncoded);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
this.parser.encodePacket(packet, this.supportsBinary, send);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Closes the transport.
|
|
63
|
-
*
|
|
64
|
-
* @private
|
|
65
|
-
*/
|
|
66
|
-
doClose(fn) {
|
|
67
|
-
debug("closing");
|
|
68
|
-
fn && fn();
|
|
69
|
-
// call fn first since socket.end() immediately emits a "close" event
|
|
70
|
-
this.socket.end();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.WebSocket = WebSocket;
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uServer = void 0;
|
|
4
|
-
const debug_1 = require("debug");
|
|
5
|
-
const server_1 = require("./server");
|
|
6
|
-
const transports_uws_1 = require("./transports-uws");
|
|
7
|
-
const debug = (0, debug_1.default)("engine:uws");
|
|
8
|
-
/**
|
|
9
|
-
* An Engine.IO server based on the `uWebSockets.js` package.
|
|
10
|
-
*/
|
|
11
|
-
// TODO export it into its own package
|
|
12
|
-
class uServer extends server_1.BaseServer {
|
|
13
|
-
init() { }
|
|
14
|
-
cleanup() { }
|
|
15
|
-
/**
|
|
16
|
-
* Prepares a request by processing the query string.
|
|
17
|
-
*
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
prepare(req, res) {
|
|
21
|
-
req.method = req.getMethod().toUpperCase();
|
|
22
|
-
req.url = req.getUrl();
|
|
23
|
-
const params = new URLSearchParams(req.getQuery());
|
|
24
|
-
req._query = Object.fromEntries(params.entries());
|
|
25
|
-
req.headers = {};
|
|
26
|
-
req.forEach((key, value) => {
|
|
27
|
-
req.headers[key] = value;
|
|
28
|
-
});
|
|
29
|
-
req.connection = {
|
|
30
|
-
remoteAddress: Buffer.from(res.getRemoteAddressAsText()).toString(),
|
|
31
|
-
};
|
|
32
|
-
res.onAborted(() => {
|
|
33
|
-
debug("response has been aborted");
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
createTransport(transportName, req) {
|
|
37
|
-
return new transports_uws_1.default[transportName](req);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Attach the engine to a µWebSockets.js server
|
|
41
|
-
* @param app
|
|
42
|
-
* @param options
|
|
43
|
-
*/
|
|
44
|
-
attach(app /* : TemplatedApp */, options = {}) {
|
|
45
|
-
const path = this._computePath(options);
|
|
46
|
-
app
|
|
47
|
-
.any(path, this.handleRequest.bind(this))
|
|
48
|
-
//
|
|
49
|
-
.ws(path, {
|
|
50
|
-
compression: options.compression,
|
|
51
|
-
idleTimeout: options.idleTimeout,
|
|
52
|
-
maxBackpressure: options.maxBackpressure,
|
|
53
|
-
maxPayloadLength: this.opts.maxHttpBufferSize,
|
|
54
|
-
upgrade: this.handleUpgrade.bind(this),
|
|
55
|
-
open: (ws) => {
|
|
56
|
-
const transport = ws.getUserData().transport;
|
|
57
|
-
transport.socket = ws;
|
|
58
|
-
transport.writable = true;
|
|
59
|
-
transport.emit("ready");
|
|
60
|
-
},
|
|
61
|
-
message: (ws, message, isBinary) => {
|
|
62
|
-
ws.getUserData().transport.onData(isBinary ? message : Buffer.from(message).toString());
|
|
63
|
-
},
|
|
64
|
-
close: (ws, code, message) => {
|
|
65
|
-
ws.getUserData().transport.onClose(code, message);
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
_applyMiddlewares(req, res, callback) {
|
|
70
|
-
if (this.middlewares.length === 0) {
|
|
71
|
-
return callback();
|
|
72
|
-
}
|
|
73
|
-
// needed to buffer headers until the status is computed
|
|
74
|
-
req.res = new ResponseWrapper(res);
|
|
75
|
-
super._applyMiddlewares(req, req.res, (err) => {
|
|
76
|
-
// some middlewares (like express-session) wait for the writeHead() call to flush their headers
|
|
77
|
-
// see https://github.com/expressjs/session/blob/1010fadc2f071ddf2add94235d72224cf65159c6/index.js#L220-L244
|
|
78
|
-
req.res.writeHead();
|
|
79
|
-
callback(err);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
handleRequest(res, req) {
|
|
83
|
-
debug('handling "%s" http request "%s"', req.getMethod(), req.getUrl());
|
|
84
|
-
this.prepare(req, res);
|
|
85
|
-
req.res = res;
|
|
86
|
-
const callback = (errorCode, errorContext) => {
|
|
87
|
-
if (errorCode !== undefined) {
|
|
88
|
-
this.emit("connection_error", {
|
|
89
|
-
req,
|
|
90
|
-
code: errorCode,
|
|
91
|
-
message: server_1.Server.errorMessages[errorCode],
|
|
92
|
-
context: errorContext,
|
|
93
|
-
});
|
|
94
|
-
this.abortRequest(req.res, errorCode, errorContext);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (req._query.sid) {
|
|
98
|
-
debug("setting new request for existing client");
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
this.clients[req._query.sid].transport.onRequest(req);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
const closeConnection = (errorCode, errorContext) => this.abortRequest(res, errorCode, errorContext);
|
|
104
|
-
this.handshake(req._query.transport, req, closeConnection);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
this._applyMiddlewares(req, res, (err) => {
|
|
108
|
-
if (err) {
|
|
109
|
-
callback(server_1.Server.errors.BAD_REQUEST, { name: "MIDDLEWARE_FAILURE" });
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.verify(req, false, callback);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
handleUpgrade(res, req, context) {
|
|
117
|
-
debug("on upgrade");
|
|
118
|
-
this.prepare(req, res);
|
|
119
|
-
req.res = res;
|
|
120
|
-
const callback = async (errorCode, errorContext) => {
|
|
121
|
-
if (errorCode !== undefined) {
|
|
122
|
-
this.emit("connection_error", {
|
|
123
|
-
req,
|
|
124
|
-
code: errorCode,
|
|
125
|
-
message: server_1.Server.errorMessages[errorCode],
|
|
126
|
-
context: errorContext,
|
|
127
|
-
});
|
|
128
|
-
this.abortRequest(res, errorCode, errorContext);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const id = req._query.sid;
|
|
132
|
-
let transport;
|
|
133
|
-
if (id) {
|
|
134
|
-
const client = this.clients[id];
|
|
135
|
-
if (!client) {
|
|
136
|
-
debug("upgrade attempt for closed client");
|
|
137
|
-
return res.close();
|
|
138
|
-
}
|
|
139
|
-
else if (client.upgrading) {
|
|
140
|
-
debug("transport has already been trying to upgrade");
|
|
141
|
-
return res.close();
|
|
142
|
-
}
|
|
143
|
-
else if (client.upgraded) {
|
|
144
|
-
debug("transport had already been upgraded");
|
|
145
|
-
return res.close();
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
debug("upgrading existing transport");
|
|
149
|
-
transport = this.createTransport(req._query.transport, req);
|
|
150
|
-
client._maybeUpgrade(transport);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
transport = await this.handshake(req._query.transport, req, (errorCode, errorContext) => this.abortRequest(res, errorCode, errorContext));
|
|
155
|
-
if (!transport) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// calling writeStatus() triggers the flushing of any header added in a middleware
|
|
160
|
-
req.res.writeStatus("101 Switching Protocols");
|
|
161
|
-
res.upgrade({
|
|
162
|
-
transport,
|
|
163
|
-
}, req.getHeader("sec-websocket-key"), req.getHeader("sec-websocket-protocol"), req.getHeader("sec-websocket-extensions"), context);
|
|
164
|
-
};
|
|
165
|
-
this._applyMiddlewares(req, res, (err) => {
|
|
166
|
-
if (err) {
|
|
167
|
-
callback(server_1.Server.errors.BAD_REQUEST, { name: "MIDDLEWARE_FAILURE" });
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
this.verify(req, true, callback);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
abortRequest(res, errorCode, errorContext) {
|
|
175
|
-
const statusCode = errorCode === server_1.Server.errors.FORBIDDEN
|
|
176
|
-
? "403 Forbidden"
|
|
177
|
-
: "400 Bad Request";
|
|
178
|
-
const message = errorContext && errorContext.message
|
|
179
|
-
? errorContext.message
|
|
180
|
-
: server_1.Server.errorMessages[errorCode];
|
|
181
|
-
res.writeStatus(statusCode);
|
|
182
|
-
res.writeHeader("Content-Type", "application/json");
|
|
183
|
-
res.end(JSON.stringify({
|
|
184
|
-
code: errorCode,
|
|
185
|
-
message,
|
|
186
|
-
}));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.uServer = uServer;
|
|
190
|
-
class ResponseWrapper {
|
|
191
|
-
constructor(res) {
|
|
192
|
-
this.res = res;
|
|
193
|
-
this.statusWritten = false;
|
|
194
|
-
this.headers = [];
|
|
195
|
-
this.isAborted = false;
|
|
196
|
-
}
|
|
197
|
-
set statusCode(status) {
|
|
198
|
-
if (!status) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
// FIXME: handle all status codes?
|
|
202
|
-
this.writeStatus(status === 200 ? "200 OK" : "204 No Content");
|
|
203
|
-
}
|
|
204
|
-
writeHead(status) {
|
|
205
|
-
this.statusCode = status;
|
|
206
|
-
}
|
|
207
|
-
setHeader(key, value) {
|
|
208
|
-
if (Array.isArray(value)) {
|
|
209
|
-
value.forEach((val) => {
|
|
210
|
-
this.writeHeader(key, val);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
this.writeHeader(key, value);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
removeHeader() {
|
|
218
|
-
// FIXME: not implemented
|
|
219
|
-
}
|
|
220
|
-
// needed by vary: https://github.com/jshttp/vary/blob/5d725d059b3871025cf753e9dfa08924d0bcfa8f/index.js#L134
|
|
221
|
-
getHeader() { }
|
|
222
|
-
writeStatus(status) {
|
|
223
|
-
if (this.isAborted)
|
|
224
|
-
return;
|
|
225
|
-
this.res.writeStatus(status);
|
|
226
|
-
this.statusWritten = true;
|
|
227
|
-
this.writeBufferedHeaders();
|
|
228
|
-
return this;
|
|
229
|
-
}
|
|
230
|
-
writeHeader(key, value) {
|
|
231
|
-
if (this.isAborted)
|
|
232
|
-
return;
|
|
233
|
-
if (key === "Content-Length") {
|
|
234
|
-
// the content length is automatically added by uWebSockets.js
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
if (this.statusWritten) {
|
|
238
|
-
this.res.writeHeader(key, value);
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
this.headers.push([key, value]);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
writeBufferedHeaders() {
|
|
245
|
-
this.headers.forEach(([key, value]) => {
|
|
246
|
-
this.res.writeHeader(key, value);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
end(data) {
|
|
250
|
-
if (this.isAborted)
|
|
251
|
-
return;
|
|
252
|
-
this.res.cork(() => {
|
|
253
|
-
if (!this.statusWritten) {
|
|
254
|
-
// status will be inferred as "200 OK"
|
|
255
|
-
this.writeBufferedHeaders();
|
|
256
|
-
}
|
|
257
|
-
this.res.end(data);
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
onData(fn) {
|
|
261
|
-
if (this.isAborted)
|
|
262
|
-
return;
|
|
263
|
-
this.res.onData(fn);
|
|
264
|
-
}
|
|
265
|
-
onAborted(fn) {
|
|
266
|
-
if (this.isAborted)
|
|
267
|
-
return;
|
|
268
|
-
this.res.onAborted(() => {
|
|
269
|
-
// Any attempt to use the UWS response object after abort will throw!
|
|
270
|
-
this.isAborted = true;
|
|
271
|
-
fn();
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
cork(fn) {
|
|
275
|
-
if (this.isAborted)
|
|
276
|
-
return;
|
|
277
|
-
this.res.cork(fn);
|
|
278
|
-
}
|
|
279
|
-
}
|