@opra/core 0.33.13 → 1.0.0-alpha.10
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/augmentation/18n.augmentation.js +18 -5
- package/cjs/augmentation/http-controller.augmentation.js +25 -0
- package/cjs/constants.js +5 -0
- package/cjs/execution-context.js +24 -12
- package/cjs/{services → helpers}/logger.js +1 -2
- package/cjs/{services/api-service.js → helpers/service-base.js} +8 -8
- package/cjs/http/express-adapter.js +153 -0
- package/cjs/http/http-adapter.js +27 -0
- package/cjs/http/http-context.js +119 -0
- package/cjs/http/impl/asset-cache.js +21 -0
- package/cjs/http/impl/http-handler.js +584 -0
- package/cjs/http/{http-server-request.js → impl/http-incoming.host.js} +24 -49
- package/cjs/http/{http-server-response.js → impl/http-outgoing.host.js} +9 -28
- package/cjs/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +23 -27
- package/cjs/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +18 -57
- package/cjs/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +11 -14
- package/cjs/http/interfaces/http-incoming.interface.js +25 -0
- package/cjs/http/interfaces/http-outgoing.interface.js +22 -0
- package/cjs/http/interfaces/node-incoming-message.interface.js +64 -0
- package/cjs/http/interfaces/node-outgoing-message.interface.js +15 -0
- package/cjs/http/utils/body-reader.js +217 -0
- package/cjs/http/{helpers → utils}/common.js +2 -1
- package/cjs/http/{helpers → utils}/convert-to-raw-headers.js +1 -2
- package/cjs/http/{helpers → utils}/match-known-fields.js +11 -9
- package/cjs/http/utils/wrap-exception.js +34 -0
- package/cjs/index.js +26 -26
- package/cjs/platform-adapter.js +21 -0
- package/cjs/type-guards.js +23 -0
- package/esm/augmentation/18n.augmentation.js +20 -7
- package/esm/augmentation/http-controller.augmentation.js +23 -0
- package/esm/constants.js +2 -0
- package/esm/execution-context.js +24 -13
- package/esm/{services → helpers}/logger.js +1 -2
- package/esm/{services/api-service.js → helpers/service-base.js} +6 -6
- package/esm/http/express-adapter.js +148 -0
- package/esm/http/http-adapter.js +23 -0
- package/esm/http/http-context.js +114 -0
- package/esm/http/impl/asset-cache.js +17 -0
- package/esm/http/impl/http-handler.js +579 -0
- package/esm/http/{http-server-request.js → impl/http-incoming.host.js} +20 -46
- package/esm/http/{http-server-response.js → impl/http-outgoing.host.js} +7 -27
- package/esm/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +21 -25
- package/esm/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +16 -55
- package/esm/http/impl/{http-outgoing-message.host.js → node-outgoing-message.host.js} +9 -12
- package/esm/http/interfaces/http-incoming.interface.js +22 -0
- package/esm/http/interfaces/http-outgoing.interface.js +19 -0
- package/esm/http/interfaces/node-incoming-message.interface.js +61 -0
- package/esm/http/interfaces/node-outgoing-message.interface.js +12 -0
- package/esm/http/utils/body-reader.js +212 -0
- package/esm/http/{helpers → utils}/common.js +2 -1
- package/esm/http/{helpers → utils}/convert-to-headers.js +1 -1
- package/esm/http/{helpers → utils}/convert-to-raw-headers.js +2 -3
- package/esm/http/{helpers → utils}/match-known-fields.js +11 -9
- package/esm/http/utils/wrap-exception.js +30 -0
- package/esm/index.js +26 -27
- package/esm/platform-adapter.js +19 -1
- package/esm/type-guards.js +16 -0
- package/package.json +31 -13
- package/types/augmentation/18n.augmentation.d.ts +31 -1
- package/types/augmentation/http-controller.augmentation.d.ts +21 -0
- package/types/constants.d.ts +2 -0
- package/types/execution-context.d.ts +22 -26
- package/types/helpers/service-base.d.ts +10 -0
- package/types/http/express-adapter.d.ts +13 -0
- package/types/http/http-adapter.d.ts +27 -0
- package/types/http/http-context.d.ts +44 -0
- package/types/http/impl/asset-cache.d.ts +5 -0
- package/types/http/impl/http-handler.d.ts +73 -0
- package/types/http/impl/http-incoming.host.d.ts +23 -0
- package/types/http/impl/http-outgoing.host.d.ts +17 -0
- package/types/http/{helpers/multipart-helper.d.ts → impl/multipart-reader.d.ts} +8 -6
- package/types/http/impl/{http-incoming-message.host.d.ts → node-incoming-message.host.d.ts} +10 -23
- package/types/http/impl/{http-outgoing-message.host.d.ts → node-outgoing-message.host.d.ts} +11 -27
- package/types/http/{http-server-request.d.ts → interfaces/http-incoming.interface.d.ts} +28 -17
- package/types/http/{http-server-response.d.ts → interfaces/http-outgoing.interface.d.ts} +17 -10
- package/types/http/interfaces/node-incoming-message.interface.d.ts +38 -0
- package/types/http/interfaces/node-outgoing-message.interface.d.ts +29 -0
- package/types/http/utils/body-reader.d.ts +41 -0
- package/types/http/utils/wrap-exception.d.ts +2 -0
- package/types/index.d.ts +25 -27
- package/types/platform-adapter.d.ts +20 -48
- package/types/type-guards.d.ts +8 -0
- package/cjs/augmentation/collection.augmentation.js +0 -2
- package/cjs/augmentation/container.augmentation.js +0 -2
- package/cjs/augmentation/resource.augmentation.js +0 -26
- package/cjs/augmentation/singleton.augmentation.js +0 -2
- package/cjs/augmentation/storage.augmentation.js +0 -2
- package/cjs/execution-context.host.js +0 -46
- package/cjs/http/adapters/express-adapter.host.js +0 -34
- package/cjs/http/adapters/express-adapter.js +0 -14
- package/cjs/http/adapters/node-http-adapter.host.js +0 -70
- package/cjs/http/adapters/node-http-adapter.js +0 -14
- package/cjs/http/helpers/json-body-loader.js +0 -29
- package/cjs/http/helpers/query-parsers.js +0 -16
- package/cjs/http/http-adapter-host.js +0 -715
- package/cjs/interfaces/interceptor.interface.js +0 -2
- package/cjs/interfaces/request-handler.interface.js +0 -2
- package/cjs/platform-adapter.host.js +0 -154
- package/cjs/request-context.js +0 -25
- package/cjs/request.host.js +0 -24
- package/cjs/request.js +0 -2
- package/cjs/response.host.js +0 -22
- package/cjs/response.js +0 -2
- package/esm/augmentation/collection.augmentation.js +0 -1
- package/esm/augmentation/container.augmentation.js +0 -1
- package/esm/augmentation/resource.augmentation.js +0 -24
- package/esm/augmentation/singleton.augmentation.js +0 -1
- package/esm/augmentation/storage.augmentation.js +0 -1
- package/esm/execution-context.host.js +0 -42
- package/esm/http/adapters/express-adapter.host.js +0 -30
- package/esm/http/adapters/express-adapter.js +0 -11
- package/esm/http/adapters/node-http-adapter.host.js +0 -65
- package/esm/http/adapters/node-http-adapter.js +0 -11
- package/esm/http/helpers/json-body-loader.js +0 -24
- package/esm/http/helpers/query-parsers.js +0 -12
- package/esm/http/http-adapter-host.js +0 -710
- package/esm/interfaces/interceptor.interface.js +0 -1
- package/esm/interfaces/request-handler.interface.js +0 -1
- package/esm/platform-adapter.host.js +0 -149
- package/esm/request-context.js +0 -22
- package/esm/request.host.js +0 -20
- package/esm/request.js +0 -1
- package/esm/response.host.js +0 -18
- package/esm/response.js +0 -1
- package/types/augmentation/collection.augmentation.d.ts +0 -146
- package/types/augmentation/container.augmentation.d.ts +0 -14
- package/types/augmentation/resource.augmentation.d.ts +0 -38
- package/types/augmentation/singleton.augmentation.d.ts +0 -83
- package/types/augmentation/storage.augmentation.d.ts +0 -50
- package/types/execution-context.host.d.ts +0 -25
- package/types/http/adapters/express-adapter.d.ts +0 -15
- package/types/http/adapters/express-adapter.host.d.ts +0 -12
- package/types/http/adapters/node-http-adapter.d.ts +0 -17
- package/types/http/adapters/node-http-adapter.host.d.ts +0 -19
- package/types/http/helpers/json-body-loader.d.ts +0 -5
- package/types/http/helpers/query-parsers.d.ts +0 -1
- package/types/http/http-adapter-host.d.ts +0 -34
- package/types/interfaces/interceptor.interface.d.ts +0 -2
- package/types/interfaces/request-handler.interface.d.ts +0 -4
- package/types/platform-adapter.host.d.ts +0 -43
- package/types/request-context.d.ts +0 -13
- package/types/request.d.ts +0 -14
- package/types/request.host.d.ts +0 -27
- package/types/response.d.ts +0 -22
- package/types/response.host.d.ts +0 -22
- package/types/services/api-service.d.ts +0 -10
- /package/cjs/http/{helpers → utils}/concat-readable.js +0 -0
- /package/cjs/http/{helpers → utils}/convert-to-headers.js +0 -0
- /package/esm/http/{helpers → utils}/concat-readable.js +0 -0
- /package/types/{services → helpers}/logger.d.ts +0 -0
- /package/types/http/{helpers → utils}/common.d.ts +0 -0
- /package/types/http/{helpers → utils}/concat-readable.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/convert-to-raw-headers.d.ts +0 -0
- /package/types/http/{helpers → utils}/match-known-fields.d.ts +0 -0
|
@@ -1,49 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpIncomingHost = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
2
5
|
/*
|
|
3
6
|
Some parts of this file contains codes from open source express library
|
|
4
7
|
https://github.com/expressjs
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
exports.HttpServerRequest = void 0;
|
|
8
|
-
const tslib_1 = require("tslib");
|
|
9
|
+
const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
|
|
9
10
|
const accepts_1 = tslib_1.__importDefault(require("accepts"));
|
|
10
11
|
const fresh_1 = tslib_1.__importDefault(require("fresh"));
|
|
11
12
|
const range_parser_1 = tslib_1.__importDefault(require("range-parser"));
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const http_incoming_message_host_js_1 = require("./impl/http-incoming-message.host.js");
|
|
15
|
-
function isHttpIncomingMessage(v) {
|
|
16
|
-
return v && Array.isArray(v.rawHeaders) && (0, common_1.isReadable)(v);
|
|
17
|
-
}
|
|
18
|
-
var HttpServerRequest;
|
|
19
|
-
(function (HttpServerRequest) {
|
|
20
|
-
function from(instance) {
|
|
21
|
-
if (!isHttpIncomingMessage(instance))
|
|
22
|
-
instance = http_incoming_message_host_js_1.HttpIncomingMessageHost.from(instance);
|
|
23
|
-
(0, common_1.mergePrototype)(instance, HttpServerRequestHost.prototype);
|
|
24
|
-
const req = instance;
|
|
25
|
-
req.baseUrl = req.baseUrl || '';
|
|
26
|
-
req.parsedUrl = req.parsedUrl || new common_1.OpraURL(req.url);
|
|
27
|
-
if (!req.searchParams)
|
|
28
|
-
Object.defineProperty(req, 'searchParams', {
|
|
29
|
-
get() {
|
|
30
|
-
return req.parsedUrl.searchParams;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
return req;
|
|
34
|
-
}
|
|
35
|
-
HttpServerRequest.from = from;
|
|
36
|
-
})(HttpServerRequest || (exports.HttpServerRequest = HttpServerRequest = {}));
|
|
37
|
-
class HttpServerRequestHost {
|
|
38
|
-
constructor() {
|
|
39
|
-
this.basePath = '/';
|
|
40
|
-
}
|
|
13
|
+
const body_reader_js_1 = require("../utils/body-reader.js");
|
|
14
|
+
class HttpIncomingHost {
|
|
41
15
|
get protocol() {
|
|
42
16
|
const proto = this.header('X-Forwarded-Proto') || 'http';
|
|
43
17
|
const index = proto.indexOf(',');
|
|
44
|
-
return index !== -1
|
|
45
|
-
? proto.substring(0, index).trim()
|
|
46
|
-
: proto.trim();
|
|
18
|
+
return index !== -1 ? proto.substring(0, index).trim() : proto.trim();
|
|
47
19
|
}
|
|
48
20
|
get secure() {
|
|
49
21
|
return this.protocol === 'https';
|
|
@@ -58,28 +30,25 @@ class HttpServerRequestHost {
|
|
|
58
30
|
// single value, but this is to be safe.
|
|
59
31
|
host = host.substring(0, host.indexOf(',')).trim();
|
|
60
32
|
}
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
? host.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return index !== -1
|
|
69
|
-
? host.substring(0, index)
|
|
70
|
-
: host;
|
|
33
|
+
if (host) {
|
|
34
|
+
// IPv6 literal support
|
|
35
|
+
const offset = host[0] === '[' ? host.indexOf(']') + 1 : 0;
|
|
36
|
+
const index = host.indexOf(':', offset);
|
|
37
|
+
return index !== -1 ? host.substring(0, index) : host;
|
|
38
|
+
}
|
|
39
|
+
return '';
|
|
71
40
|
}
|
|
72
41
|
get fresh() {
|
|
73
42
|
const method = this.method;
|
|
74
43
|
// GET or HEAD for weak freshness validation only
|
|
75
|
-
if ('GET'
|
|
44
|
+
if (method !== 'GET' && method !== 'HEAD')
|
|
76
45
|
return false;
|
|
77
46
|
const status = this.res?.statusCode;
|
|
78
47
|
// 2xx or 304 as per rfc2616 14.26
|
|
79
|
-
if ((status >= 200 && status < 300) ||
|
|
48
|
+
if ((status >= 200 && status < 300) || status === 304) {
|
|
80
49
|
return (0, fresh_1.default)(this.headers, {
|
|
81
|
-
|
|
82
|
-
'last-modified': this.res.getHeader('Last-Modified')
|
|
50
|
+
etag: this.res.getHeader('ETag'),
|
|
51
|
+
'last-modified': this.res.getHeader('Last-Modified'),
|
|
83
52
|
});
|
|
84
53
|
}
|
|
85
54
|
return false;
|
|
@@ -134,4 +103,10 @@ class HttpServerRequestHost {
|
|
|
134
103
|
return;
|
|
135
104
|
return (0, range_parser_1.default)(size, range, options);
|
|
136
105
|
}
|
|
106
|
+
async readBody(options) {
|
|
107
|
+
if (!this.complete)
|
|
108
|
+
this.body = await body_reader_js_1.BodyReader.read(this, options);
|
|
109
|
+
return this.body;
|
|
110
|
+
}
|
|
137
111
|
}
|
|
112
|
+
exports.HttpIncomingHost = HttpIncomingHost;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
https://github.com/expressjs
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.HttpOutgoingHost = void 0;
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
|
+
const common_1 = require("@opra/common");
|
|
9
10
|
const content_disposition_1 = tslib_1.__importDefault(require("content-disposition"));
|
|
10
11
|
const content_type_1 = tslib_1.__importDefault(require("content-type"));
|
|
11
12
|
const cookie_1 = tslib_1.__importDefault(require("cookie"));
|
|
@@ -15,23 +16,8 @@ const mime_types_1 = tslib_1.__importDefault(require("mime-types"));
|
|
|
15
16
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
17
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
17
18
|
const vary_1 = tslib_1.__importDefault(require("vary"));
|
|
18
|
-
const common_1 = require("@opra/common");
|
|
19
|
-
const http_outgoing_message_host_js_1 = require("./impl/http-outgoing-message.host.js");
|
|
20
19
|
const charsetRegExp = /;\s*charset\s*=/;
|
|
21
|
-
|
|
22
|
-
return v && typeof v.getHeaders === 'function' && (0, common_1.isStream)(v);
|
|
23
|
-
}
|
|
24
|
-
var HttpServerResponse;
|
|
25
|
-
(function (HttpServerResponse) {
|
|
26
|
-
function from(instance) {
|
|
27
|
-
if (!isHttpIncomingMessage(instance))
|
|
28
|
-
instance = new http_outgoing_message_host_js_1.HttpOutgoingMessageHost(instance);
|
|
29
|
-
(0, common_1.mergePrototype)(instance, HttpServerResponseHost.prototype);
|
|
30
|
-
return instance;
|
|
31
|
-
}
|
|
32
|
-
HttpServerResponse.from = from;
|
|
33
|
-
})(HttpServerResponse || (exports.HttpServerResponse = HttpServerResponse = {}));
|
|
34
|
-
class HttpServerResponseHost {
|
|
20
|
+
class HttpOutgoingHost {
|
|
35
21
|
attachment(filename) {
|
|
36
22
|
if (filename)
|
|
37
23
|
this.contentType(path_1.default.extname(filename));
|
|
@@ -39,9 +25,7 @@ class HttpServerResponseHost {
|
|
|
39
25
|
return this;
|
|
40
26
|
}
|
|
41
27
|
contentType(type) {
|
|
42
|
-
const ct = type.indexOf('/') === -1
|
|
43
|
-
? mime_types_1.default.lookup(type)
|
|
44
|
-
: type;
|
|
28
|
+
const ct = type.indexOf('/') === -1 ? mime_types_1.default.lookup(type) : type;
|
|
45
29
|
this.setHeader('Content-Type', ct);
|
|
46
30
|
return this;
|
|
47
31
|
}
|
|
@@ -54,9 +38,7 @@ class HttpServerResponseHost {
|
|
|
54
38
|
return this;
|
|
55
39
|
}
|
|
56
40
|
const fieldLower = field.toLowerCase();
|
|
57
|
-
let value = Array.isArray(val)
|
|
58
|
-
? val.map(String)
|
|
59
|
-
: (val ? String(val) : '');
|
|
41
|
+
let value = Array.isArray(val) ? val.map(String) : val ? String(val) : '';
|
|
60
42
|
// add charset to content-type
|
|
61
43
|
if (fieldLower === 'content-type') {
|
|
62
44
|
if (Array.isArray(value)) {
|
|
@@ -75,15 +57,13 @@ class HttpServerResponseHost {
|
|
|
75
57
|
const opts = {
|
|
76
58
|
expires: new Date(1),
|
|
77
59
|
path: '/',
|
|
78
|
-
...options
|
|
60
|
+
...options,
|
|
79
61
|
};
|
|
80
62
|
return this.cookie(name, '', opts);
|
|
81
63
|
}
|
|
82
64
|
cookie(name, value, options) {
|
|
83
65
|
const opts = { ...options };
|
|
84
|
-
let val = typeof value === 'object'
|
|
85
|
-
? 'j:' + JSON.stringify(value)
|
|
86
|
-
: String(value);
|
|
66
|
+
let val = typeof value === 'object' ? 'j:' + JSON.stringify(value) : String(value);
|
|
87
67
|
if (opts.signed) {
|
|
88
68
|
const secret = opts.secret || this.req?.secret;
|
|
89
69
|
if (!secret)
|
|
@@ -184,7 +164,7 @@ class HttpServerResponseHost {
|
|
|
184
164
|
if (req?.fresh)
|
|
185
165
|
this.statusCode = 304;
|
|
186
166
|
// strip irrelevant headers
|
|
187
|
-
if (
|
|
167
|
+
if (this.statusCode === 204 || this.statusCode === 304) {
|
|
188
168
|
this.removeHeader('Content-Type');
|
|
189
169
|
this.removeHeader('Content-Length');
|
|
190
170
|
this.removeHeader('Transfer-Encoding');
|
|
@@ -214,6 +194,7 @@ class HttpServerResponseHost {
|
|
|
214
194
|
return this;
|
|
215
195
|
}
|
|
216
196
|
}
|
|
197
|
+
exports.HttpOutgoingHost = HttpOutgoingHost;
|
|
217
198
|
function setCharset(type, charset) {
|
|
218
199
|
if (!(type && charset))
|
|
219
200
|
return type;
|
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MultipartReader = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const events_1 = require("events");
|
|
6
6
|
const formidable_1 = tslib_1.__importDefault(require("formidable"));
|
|
7
7
|
const promises_1 = tslib_1.__importDefault(require("fs/promises"));
|
|
8
|
-
class
|
|
9
|
-
constructor(options) {
|
|
8
|
+
class MultipartReader extends events_1.EventEmitter {
|
|
9
|
+
constructor(incoming, options) {
|
|
10
10
|
super();
|
|
11
|
+
this._started = false;
|
|
11
12
|
this._cancelled = false;
|
|
12
13
|
this._items = [];
|
|
13
14
|
this._stack = [];
|
|
14
15
|
this.setMaxListeners(1000);
|
|
15
|
-
|
|
16
|
+
this._incoming = incoming;
|
|
17
|
+
const form = (this._form = (0, formidable_1.default)({
|
|
16
18
|
...options,
|
|
17
|
-
filter: (part) =>
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
});
|
|
19
|
+
filter: (part) => !this._cancelled && (!options?.filter || options.filter(part)),
|
|
20
|
+
}));
|
|
21
21
|
form.once('error', () => {
|
|
22
22
|
this._cancelled = true;
|
|
23
23
|
if (this.listenerCount('error') > 0)
|
|
24
24
|
this.emit('error');
|
|
25
25
|
});
|
|
26
|
-
form.on('field', (
|
|
27
|
-
const item = { field, value };
|
|
26
|
+
form.on('field', (fieldName, value) => {
|
|
27
|
+
const item = { fieldName, type: 'field', value };
|
|
28
28
|
this._items.push(item);
|
|
29
29
|
this._stack.push(item);
|
|
30
|
+
this.emit('field', item);
|
|
30
31
|
this.emit('item', item);
|
|
31
32
|
});
|
|
32
|
-
form.on('file', (
|
|
33
|
-
const item = {
|
|
33
|
+
form.on('file', (fieldName, file) => {
|
|
34
|
+
const item = { fieldName, type: 'file', file };
|
|
34
35
|
this._items.push(item);
|
|
35
36
|
this._stack.push(item);
|
|
37
|
+
this.emit('file', item);
|
|
36
38
|
this.emit('item', item);
|
|
37
39
|
});
|
|
38
40
|
}
|
|
@@ -48,7 +50,7 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
48
50
|
if (this._form.ended)
|
|
49
51
|
return resolve(undefined);
|
|
50
52
|
this.once('item', () => resolve(this._stack.shift()));
|
|
51
|
-
this.once('error',
|
|
53
|
+
this.once('error', e => reject(e));
|
|
52
54
|
});
|
|
53
55
|
}
|
|
54
56
|
getAll() {
|
|
@@ -68,6 +70,8 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
68
70
|
this.resume();
|
|
69
71
|
}
|
|
70
72
|
resume() {
|
|
73
|
+
if (!this._started)
|
|
74
|
+
this._form.parse(this._incoming, () => undefined);
|
|
71
75
|
if (this._form.req)
|
|
72
76
|
this._form.resume();
|
|
73
77
|
}
|
|
@@ -75,10 +79,9 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
75
79
|
if (this._form.req)
|
|
76
80
|
this._form.pause();
|
|
77
81
|
}
|
|
78
|
-
async
|
|
82
|
+
async deleteTempFiles() {
|
|
79
83
|
const promises = [];
|
|
80
|
-
this._items
|
|
81
|
-
.forEach(item => {
|
|
84
|
+
this._items.forEach(item => {
|
|
82
85
|
if (!item.file)
|
|
83
86
|
return;
|
|
84
87
|
const file = item.file;
|
|
@@ -86,18 +89,11 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
86
89
|
if (file._writeStream.closed)
|
|
87
90
|
return resolve();
|
|
88
91
|
file._writeStream.once('close', resolve);
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return 0;
|
|
93
|
-
}));
|
|
92
|
+
})
|
|
93
|
+
.then(() => promises_1.default.unlink(file.filepath))
|
|
94
|
+
.then(() => 0));
|
|
94
95
|
});
|
|
95
96
|
return Promise.allSettled(promises);
|
|
96
97
|
}
|
|
97
|
-
static async create(incoming, options) {
|
|
98
|
-
const out = new MultipartIterator(options);
|
|
99
|
-
await out._form.parse(incoming);
|
|
100
|
-
return out;
|
|
101
|
-
}
|
|
102
98
|
}
|
|
103
|
-
exports.
|
|
99
|
+
exports.MultipartReader = MultipartReader;
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
This file contains code blocks from open source NodeJs project
|
|
4
|
-
https://github.com/nodejs/
|
|
5
|
-
*/
|
|
6
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
8
|
-
const stream_1 = require("stream");
|
|
9
|
-
const http_parser_1 = require("@browsery/http-parser");
|
|
3
|
+
exports.NodeIncomingMessageHost = exports.kHttpParser = exports.kTrailersDistinct = exports.kTrailers = exports.kHeadersDistinct = exports.kHeaders = exports.CRLF = void 0;
|
|
10
4
|
const common_1 = require("@opra/common");
|
|
11
|
-
const
|
|
12
|
-
const convert_to_headers_js_1 = require("../
|
|
13
|
-
const convert_to_raw_headers_js_1 = require("../
|
|
5
|
+
const stream_1 = require("stream");
|
|
6
|
+
const convert_to_headers_js_1 = require("../utils/convert-to-headers.js");
|
|
7
|
+
const convert_to_raw_headers_js_1 = require("../utils/convert-to-raw-headers.js");
|
|
14
8
|
exports.CRLF = Buffer.from('\r\n');
|
|
15
9
|
exports.kHeaders = Symbol.for('kHeaders');
|
|
16
10
|
exports.kHeadersDistinct = Symbol.for('kHeadersDistinct');
|
|
17
11
|
exports.kTrailers = Symbol.for('kTrailers');
|
|
18
12
|
exports.kTrailersDistinct = Symbol.for('kTrailersDistinct');
|
|
13
|
+
exports.kHttpParser = Symbol.for('kHttpParser');
|
|
19
14
|
/**
|
|
20
15
|
*
|
|
21
|
-
* @class
|
|
16
|
+
* @class NodeIncomingMessageHost
|
|
22
17
|
*/
|
|
23
|
-
class
|
|
18
|
+
class NodeIncomingMessageHost extends stream_1.Duplex {
|
|
24
19
|
constructor(init) {
|
|
25
20
|
super();
|
|
26
21
|
this.rawHeaders = [];
|
|
@@ -41,20 +36,24 @@ class HttpIncomingMessageHost extends stream_1.Duplex {
|
|
|
41
36
|
else
|
|
42
37
|
this.body = Buffer.from(JSON.stringify(init.body), 'utf-8');
|
|
43
38
|
}
|
|
44
|
-
if (init.headers)
|
|
39
|
+
if (init.headers) {
|
|
45
40
|
this.rawHeaders = Array.isArray(init.headers) ? init.headers : (0, convert_to_raw_headers_js_1.convertToRawHeaders)(init.headers);
|
|
46
|
-
|
|
41
|
+
}
|
|
42
|
+
if (init.trailers) {
|
|
47
43
|
this.rawTrailers = Array.isArray(init.trailers) ? init.trailers : (0, convert_to_raw_headers_js_1.convertToRawHeaders)(init.trailers);
|
|
44
|
+
}
|
|
48
45
|
this.ip = init.ip || '';
|
|
49
46
|
this.ips = init.ips || (this.ip ? [this.ip] : []);
|
|
50
47
|
if (this.body && !this.headers['content-length'])
|
|
51
48
|
this.headers['content-length'] = String(this.body.length);
|
|
49
|
+
if (init.params)
|
|
50
|
+
this.params = init.params;
|
|
51
|
+
if (init.cookies)
|
|
52
|
+
this.cookies = init.cookies;
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
get httpVersion() {
|
|
55
|
-
return this.httpVersionMajor
|
|
56
|
-
? this.httpVersionMajor + '.' + this.httpVersionMinor
|
|
57
|
-
: '';
|
|
56
|
+
return this.httpVersionMajor ? this.httpVersionMajor + '.' + this.httpVersionMinor : '';
|
|
58
57
|
}
|
|
59
58
|
get headers() {
|
|
60
59
|
if (!this[exports.kHeaders])
|
|
@@ -98,51 +97,13 @@ class HttpIncomingMessageHost extends stream_1.Duplex {
|
|
|
98
97
|
}
|
|
99
98
|
const chunk = this._readStream.read(size);
|
|
100
99
|
this.push(chunk);
|
|
101
|
-
// this.push(null);s
|
|
102
100
|
}
|
|
103
101
|
_write(chunk, encoding, callback) {
|
|
104
|
-
const error = this.
|
|
102
|
+
const error = this[exports.kHttpParser]?.execute(chunk);
|
|
105
103
|
if (error && typeof error === 'object')
|
|
106
104
|
callback(error);
|
|
107
105
|
else
|
|
108
106
|
callback();
|
|
109
107
|
}
|
|
110
|
-
static from(iterable) {
|
|
111
|
-
if (typeof iterable === 'object' && !((0, common_1.isIterable)(iterable) || (0, common_1.isAsyncIterable)(iterable)))
|
|
112
|
-
return new HttpIncomingMessageHost(iterable);
|
|
113
|
-
const msg = new HttpIncomingMessageHost();
|
|
114
|
-
const parser = msg._httpParser = new http_parser_1.HTTPParser(http_parser_1.HTTPParser.REQUEST);
|
|
115
|
-
let bodyChunks;
|
|
116
|
-
parser[http_parser_1.HTTPParser.kOnHeadersComplete] = (info) => {
|
|
117
|
-
msg.httpVersionMajor = info.versionMajor;
|
|
118
|
-
msg.httpVersionMinor = info.versionMinor;
|
|
119
|
-
msg.rawHeaders = info.headers;
|
|
120
|
-
msg.method = http_parser_1.HTTPParser.methods[info.method];
|
|
121
|
-
msg.url = info.url;
|
|
122
|
-
};
|
|
123
|
-
parser[http_parser_1.HTTPParser.kOnHeaders] = (trailers) => {
|
|
124
|
-
msg.rawTrailers = trailers;
|
|
125
|
-
};
|
|
126
|
-
parser[http_parser_1.HTTPParser.kOnBody] = (chunk, offset, length) => {
|
|
127
|
-
bodyChunks = bodyChunks || [];
|
|
128
|
-
bodyChunks.push(chunk.subarray(offset, offset + length));
|
|
129
|
-
};
|
|
130
|
-
parser[http_parser_1.HTTPParser.kOnMessageComplete] = () => {
|
|
131
|
-
msg.complete = true;
|
|
132
|
-
if (bodyChunks)
|
|
133
|
-
msg.body = Buffer.concat(bodyChunks);
|
|
134
|
-
};
|
|
135
|
-
const readable = (0, concat_readable_js_1.concatReadable)(stream_1.Readable.from(iterable), stream_1.Readable.from(exports.CRLF));
|
|
136
|
-
msg.once('finish', () => parser.finish());
|
|
137
|
-
readable.pipe(msg);
|
|
138
|
-
return msg;
|
|
139
|
-
}
|
|
140
|
-
static async fromAsync(iterable) {
|
|
141
|
-
return new Promise((resolve, reject) => {
|
|
142
|
-
const msg = this.from(iterable);
|
|
143
|
-
msg.once('finish', () => resolve(msg));
|
|
144
|
-
msg.once('error', (error) => reject(error));
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
108
|
}
|
|
148
|
-
exports.
|
|
109
|
+
exports.NodeIncomingMessageHost = NodeIncomingMessageHost;
|
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
https://github.com/nodejs/
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.NodeOutgoingMessageHost = exports.kOutTrailers = exports.kOutHeaders = void 0;
|
|
8
8
|
const stream_1 = require("stream");
|
|
9
|
-
const common_js_1 = require("../
|
|
9
|
+
const common_js_1 = require("../utils/common.js");
|
|
10
10
|
exports.kOutHeaders = Symbol.for('kOutHeaders');
|
|
11
11
|
exports.kOutTrailers = Symbol.for('kOutTrailers');
|
|
12
12
|
// noinspection JSUnusedLocalSymbols
|
|
13
13
|
/**
|
|
14
14
|
*
|
|
15
|
-
* @class
|
|
15
|
+
* @class NodeOutgoingMessageHost
|
|
16
16
|
*/
|
|
17
|
-
class
|
|
17
|
+
class NodeOutgoingMessageHost extends stream_1.Duplex {
|
|
18
18
|
constructor(init) {
|
|
19
19
|
super();
|
|
20
20
|
this._headersSent = false;
|
|
@@ -67,8 +67,7 @@ class HttpOutgoingMessageHost extends stream_1.Duplex {
|
|
|
67
67
|
}
|
|
68
68
|
addTrailers(headers) {
|
|
69
69
|
if (headers && typeof headers === 'object') {
|
|
70
|
-
const entries = typeof headers.entries === 'function'
|
|
71
|
-
? headers.entries() : Object.entries(headers);
|
|
70
|
+
const entries = typeof headers.entries === 'function' ? headers.entries() : Object.entries(headers);
|
|
72
71
|
let trailers = this[exports.kOutTrailers];
|
|
73
72
|
if (trailers == null)
|
|
74
73
|
this[exports.kOutTrailers] = trailers = { __proto__: null };
|
|
@@ -81,6 +80,9 @@ class HttpOutgoingMessageHost extends stream_1.Duplex {
|
|
|
81
80
|
}
|
|
82
81
|
throw new TypeError('Invalid "headers" argument. Value must be an object or raw headers array');
|
|
83
82
|
}
|
|
83
|
+
flushHeaders() {
|
|
84
|
+
// nothing to do
|
|
85
|
+
}
|
|
84
86
|
setHeader(name, value) {
|
|
85
87
|
if (this.headersSent)
|
|
86
88
|
throw new Error(`Cannot set headers after they are sent to the client`);
|
|
@@ -96,8 +98,7 @@ class HttpOutgoingMessageHost extends stream_1.Duplex {
|
|
|
96
98
|
if (this.headersSent)
|
|
97
99
|
throw new Error(`Cannot set headers after they are sent to the client`);
|
|
98
100
|
if (headers && typeof headers === 'object' && !Array.isArray(headers)) {
|
|
99
|
-
const entries = typeof headers.entries === 'function'
|
|
100
|
-
? headers.entries() : Object.entries(headers);
|
|
101
|
+
const entries = typeof headers.entries === 'function' ? headers.entries() : Object.entries(headers);
|
|
101
102
|
for (const entry of entries) {
|
|
102
103
|
this.setHeader(entry[0], entry[1]);
|
|
103
104
|
}
|
|
@@ -145,8 +146,7 @@ class HttpOutgoingMessageHost extends stream_1.Duplex {
|
|
|
145
146
|
}
|
|
146
147
|
hasHeader(name) {
|
|
147
148
|
(0, common_js_1.validateString)(name);
|
|
148
|
-
return this[exports.kOutHeaders] != null &&
|
|
149
|
-
!!this[exports.kOutHeaders][name.toLowerCase()];
|
|
149
|
+
return this[exports.kOutHeaders] != null && !!this[exports.kOutHeaders][name.toLowerCase()];
|
|
150
150
|
}
|
|
151
151
|
removeHeader(name) {
|
|
152
152
|
(0, common_js_1.validateString)(name);
|
|
@@ -191,8 +191,5 @@ class HttpOutgoingMessageHost extends stream_1.Duplex {
|
|
|
191
191
|
//
|
|
192
192
|
return this;
|
|
193
193
|
}
|
|
194
|
-
static from(init) {
|
|
195
|
-
return new HttpOutgoingMessageHost(init);
|
|
196
|
-
}
|
|
197
194
|
}
|
|
198
|
-
exports.
|
|
195
|
+
exports.NodeOutgoingMessageHost = NodeOutgoingMessageHost;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpIncoming = void 0;
|
|
4
|
+
const common_1 = require("@opra/common");
|
|
5
|
+
const type_guards_js_1 = require("../../type-guards.js");
|
|
6
|
+
const http_incoming_host_js_1 = require("../impl/http-incoming.host.js");
|
|
7
|
+
const node_incoming_message_interface_js_1 = require("./node-incoming-message.interface.js");
|
|
8
|
+
/**
|
|
9
|
+
* @namespace HttpIncoming
|
|
10
|
+
*/
|
|
11
|
+
var HttpIncoming;
|
|
12
|
+
(function (HttpIncoming) {
|
|
13
|
+
function from(instance) {
|
|
14
|
+
if ((0, type_guards_js_1.isHttpIncoming)(instance))
|
|
15
|
+
return instance;
|
|
16
|
+
if (!(0, type_guards_js_1.isNodeIncomingMessage)(instance))
|
|
17
|
+
instance = node_incoming_message_interface_js_1.NodeIncomingMessage.from(instance);
|
|
18
|
+
(0, common_1.mergePrototype)(instance, http_incoming_host_js_1.HttpIncomingHost.prototype);
|
|
19
|
+
const req = instance;
|
|
20
|
+
req.baseUrl = req.baseUrl || '';
|
|
21
|
+
req.params = req.params || {};
|
|
22
|
+
return req;
|
|
23
|
+
}
|
|
24
|
+
HttpIncoming.from = from;
|
|
25
|
+
})(HttpIncoming || (exports.HttpIncoming = HttpIncoming = {}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpOutgoing = void 0;
|
|
4
|
+
const common_1 = require("@opra/common");
|
|
5
|
+
const type_guards_js_1 = require("../../type-guards.js");
|
|
6
|
+
const http_outgoing_host_js_1 = require("../impl/http-outgoing.host.js");
|
|
7
|
+
const node_outgoing_message_interface_js_1 = require("./node-outgoing-message.interface.js");
|
|
8
|
+
/**
|
|
9
|
+
* @namespace HttpIncoming
|
|
10
|
+
*/
|
|
11
|
+
var HttpOutgoing;
|
|
12
|
+
(function (HttpOutgoing) {
|
|
13
|
+
function from(instance) {
|
|
14
|
+
if ((0, type_guards_js_1.isHttpOutgoing)(instance))
|
|
15
|
+
return instance;
|
|
16
|
+
if (!(0, type_guards_js_1.isNodeOutgoingMessage)(instance))
|
|
17
|
+
instance = node_outgoing_message_interface_js_1.NodeOutgoingMessage.from(instance);
|
|
18
|
+
(0, common_1.mergePrototype)(instance, http_outgoing_host_js_1.HttpOutgoingHost.prototype);
|
|
19
|
+
return instance;
|
|
20
|
+
}
|
|
21
|
+
HttpOutgoing.from = from;
|
|
22
|
+
})(HttpOutgoing || (exports.HttpOutgoing = HttpOutgoing = {}));
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeIncomingMessage = void 0;
|
|
4
|
+
const http_parser_1 = require("@browsery/http-parser");
|
|
5
|
+
const common_1 = require("@opra/common");
|
|
6
|
+
const stream_1 = require("stream");
|
|
7
|
+
const node_incoming_message_host_js_1 = require("../impl/node-incoming-message.host.js");
|
|
8
|
+
const concat_readable_js_1 = require("../utils/concat-readable.js");
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @namespace NodeIncomingMessage
|
|
12
|
+
*/
|
|
13
|
+
var NodeIncomingMessage;
|
|
14
|
+
(function (NodeIncomingMessage) {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new NodeIncomingMessage from given argument
|
|
17
|
+
* @param iterable
|
|
18
|
+
*/
|
|
19
|
+
function from(iterable) {
|
|
20
|
+
if (typeof iterable === 'object' && !((0, common_1.isIterable)(iterable) || (0, common_1.isAsyncIterable)(iterable))) {
|
|
21
|
+
return new node_incoming_message_host_js_1.NodeIncomingMessageHost(iterable);
|
|
22
|
+
}
|
|
23
|
+
const msg = new node_incoming_message_host_js_1.NodeIncomingMessageHost();
|
|
24
|
+
const parser = (msg[node_incoming_message_host_js_1.kHttpParser] = new http_parser_1.HTTPParser(http_parser_1.HTTPParser.REQUEST));
|
|
25
|
+
let bodyChunks;
|
|
26
|
+
parser[http_parser_1.HTTPParser.kOnHeadersComplete] = (info) => {
|
|
27
|
+
msg.httpVersionMajor = info.versionMajor;
|
|
28
|
+
msg.httpVersionMinor = info.versionMinor;
|
|
29
|
+
msg.rawHeaders = info.headers;
|
|
30
|
+
msg.method = http_parser_1.HTTPParser.methods[info.method];
|
|
31
|
+
msg.url = info.url;
|
|
32
|
+
msg.emit('headers');
|
|
33
|
+
};
|
|
34
|
+
parser[http_parser_1.HTTPParser.kOnHeaders] = (trailers) => {
|
|
35
|
+
msg.rawTrailers = trailers;
|
|
36
|
+
};
|
|
37
|
+
parser[http_parser_1.HTTPParser.kOnBody] = (chunk, offset, length) => {
|
|
38
|
+
bodyChunks = bodyChunks || [];
|
|
39
|
+
bodyChunks.push(chunk.subarray(offset, offset + length));
|
|
40
|
+
};
|
|
41
|
+
const readable = (0, concat_readable_js_1.concatReadable)(stream_1.Readable.from(iterable), stream_1.Readable.from(node_incoming_message_host_js_1.CRLF));
|
|
42
|
+
msg.once('finish', () => {
|
|
43
|
+
parser.finish();
|
|
44
|
+
msg.complete = true;
|
|
45
|
+
if (bodyChunks)
|
|
46
|
+
msg.body = Buffer.concat(bodyChunks);
|
|
47
|
+
});
|
|
48
|
+
readable.pipe(msg);
|
|
49
|
+
return msg;
|
|
50
|
+
}
|
|
51
|
+
NodeIncomingMessage.from = from;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new NodeIncomingMessage from given argument
|
|
54
|
+
* @param iterable
|
|
55
|
+
*/
|
|
56
|
+
async function fromAsync(iterable) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const msg = from(iterable);
|
|
59
|
+
msg.once('finish', () => resolve(msg));
|
|
60
|
+
msg.once('error', error => reject(error));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
NodeIncomingMessage.fromAsync = fromAsync;
|
|
64
|
+
})(NodeIncomingMessage || (exports.NodeIncomingMessage = NodeIncomingMessage = {}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeOutgoingMessage = void 0;
|
|
4
|
+
const node_outgoing_message_host_js_1 = require("../impl/node-outgoing-message.host.js");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @namespace NodeOutgoingMessage
|
|
8
|
+
*/
|
|
9
|
+
var NodeOutgoingMessage;
|
|
10
|
+
(function (NodeOutgoingMessage) {
|
|
11
|
+
function from(init) {
|
|
12
|
+
return new node_outgoing_message_host_js_1.NodeOutgoingMessageHost(init);
|
|
13
|
+
}
|
|
14
|
+
NodeOutgoingMessage.from = from;
|
|
15
|
+
})(NodeOutgoingMessage || (exports.NodeOutgoingMessage = NodeOutgoingMessage = {}));
|