@opra/core 0.33.13 → 1.0.0-alpha.2
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 +17 -4
- package/cjs/augmentation/http-controller.augmentation.js +25 -0
- package/cjs/constants.js +5 -0
- package/cjs/execution-context.js +25 -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 +164 -0
- package/cjs/http/http-adapter.js +27 -0
- package/cjs/http/http-context.js +116 -0
- package/cjs/http/impl/asset-cache.js +21 -0
- package/cjs/http/impl/http-handler.js +575 -0
- package/cjs/http/{http-server-request.js → impl/http-incoming.host.js} +21 -46
- package/cjs/http/{http-server-response.js → impl/http-outgoing.host.js} +7 -26
- package/cjs/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +24 -22
- package/cjs/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +13 -54
- 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 +63 -0
- package/cjs/http/interfaces/node-outgoing-message.interface.js +15 -0
- package/cjs/http/utils/body-reader.js +215 -0
- 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 +25 -25
- 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 +25 -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 +159 -0
- package/esm/http/http-adapter.js +23 -0
- package/esm/http/http-context.js +111 -0
- package/esm/http/impl/asset-cache.js +17 -0
- package/esm/http/impl/http-handler.js +570 -0
- package/esm/http/{http-server-request.js → impl/http-incoming.host.js} +17 -43
- package/esm/http/{http-server-response.js → impl/http-outgoing.host.js} +6 -26
- package/esm/http/{helpers/multipart-helper.js → impl/multipart-reader.js} +22 -20
- package/esm/http/impl/{http-incoming-message.host.js → node-incoming-message.host.js} +11 -52
- 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 +60 -0
- package/esm/http/interfaces/node-outgoing-message.interface.js +12 -0
- package/esm/http/utils/body-reader.js +210 -0
- 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 +25 -26
- package/esm/platform-adapter.js +19 -1
- package/esm/type-guards.js +16 -0
- package/package.json +22 -10
- package/types/augmentation/18n.augmentation.d.ts +32 -2
- package/types/augmentation/http-controller.augmentation.d.ts +21 -0
- package/types/constants.d.ts +2 -0
- package/types/execution-context.d.ts +24 -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} +9 -22
- 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 +24 -26
- 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/i18n/i18n/en/error.json +0 -21
- 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}/common.js +0 -0
- /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}/common.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
|
@@ -4,7 +4,7 @@
|
|
|
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
9
|
const content_disposition_1 = tslib_1.__importDefault(require("content-disposition"));
|
|
10
10
|
const content_type_1 = tslib_1.__importDefault(require("content-type"));
|
|
@@ -16,22 +16,8 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
16
16
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
17
17
|
const vary_1 = tslib_1.__importDefault(require("vary"));
|
|
18
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)
|
|
@@ -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,42 @@
|
|
|
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
19
|
filter: (part) => {
|
|
18
20
|
return !this._cancelled && (!options?.filter || options.filter(part));
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
+
},
|
|
22
|
+
}));
|
|
21
23
|
form.once('error', () => {
|
|
22
24
|
this._cancelled = true;
|
|
23
25
|
if (this.listenerCount('error') > 0)
|
|
24
26
|
this.emit('error');
|
|
25
27
|
});
|
|
26
|
-
form.on('field', (
|
|
27
|
-
const item = { field, value };
|
|
28
|
+
form.on('field', (fieldName, value) => {
|
|
29
|
+
const item = { fieldName, type: 'field', value };
|
|
28
30
|
this._items.push(item);
|
|
29
31
|
this._stack.push(item);
|
|
32
|
+
this.emit('field', item);
|
|
30
33
|
this.emit('item', item);
|
|
31
34
|
});
|
|
32
|
-
form.on('file', (
|
|
33
|
-
const item = {
|
|
35
|
+
form.on('file', (fieldName, file) => {
|
|
36
|
+
const item = { fieldName, type: 'file', file };
|
|
34
37
|
this._items.push(item);
|
|
35
38
|
this._stack.push(item);
|
|
39
|
+
this.emit('file', item);
|
|
36
40
|
this.emit('item', item);
|
|
37
41
|
});
|
|
38
42
|
}
|
|
@@ -48,7 +52,7 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
48
52
|
if (this._form.ended)
|
|
49
53
|
return resolve(undefined);
|
|
50
54
|
this.once('item', () => resolve(this._stack.shift()));
|
|
51
|
-
this.once('error',
|
|
55
|
+
this.once('error', e => reject(e));
|
|
52
56
|
});
|
|
53
57
|
}
|
|
54
58
|
getAll() {
|
|
@@ -68,6 +72,8 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
68
72
|
this.resume();
|
|
69
73
|
}
|
|
70
74
|
resume() {
|
|
75
|
+
if (!this._started)
|
|
76
|
+
this._form.parse(this._incoming, () => void 0);
|
|
71
77
|
if (this._form.req)
|
|
72
78
|
this._form.resume();
|
|
73
79
|
}
|
|
@@ -75,10 +81,9 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
75
81
|
if (this._form.req)
|
|
76
82
|
this._form.pause();
|
|
77
83
|
}
|
|
78
|
-
async
|
|
84
|
+
async deleteTempFiles() {
|
|
79
85
|
const promises = [];
|
|
80
|
-
this._items
|
|
81
|
-
.forEach(item => {
|
|
86
|
+
this._items.forEach(item => {
|
|
82
87
|
if (!item.file)
|
|
83
88
|
return;
|
|
84
89
|
const file = item.file;
|
|
@@ -86,18 +91,15 @@ class MultipartIterator extends events_1.EventEmitter {
|
|
|
86
91
|
if (file._writeStream.closed)
|
|
87
92
|
return resolve();
|
|
88
93
|
file._writeStream.once('close', resolve);
|
|
89
|
-
})
|
|
94
|
+
})
|
|
95
|
+
.then(() => {
|
|
90
96
|
return promises_1.default.unlink(file.filepath);
|
|
91
|
-
})
|
|
97
|
+
})
|
|
98
|
+
.then(() => {
|
|
92
99
|
return 0;
|
|
93
100
|
}));
|
|
94
101
|
});
|
|
95
102
|
return Promise.allSettled(promises);
|
|
96
103
|
}
|
|
97
|
-
static async create(incoming, options) {
|
|
98
|
-
const out = new MultipartIterator(options);
|
|
99
|
-
await out._form.parse(incoming);
|
|
100
|
-
return out;
|
|
101
|
-
}
|
|
102
104
|
}
|
|
103
|
-
exports.
|
|
105
|
+
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.
|
|
3
|
+
exports.NodeIncomingMessageHost = exports.kHttpParser = exports.kTrailersDistinct = exports.kTrailers = exports.kHeadersDistinct = exports.kHeaders = exports.CRLF = void 0;
|
|
8
4
|
const stream_1 = require("stream");
|
|
9
|
-
const http_parser_1 = require("@browsery/http-parser");
|
|
10
5
|
const common_1 = require("@opra/common");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const convert_to_raw_headers_js_1 = require("../helpers/convert-to-raw-headers.js");
|
|
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 = [];
|
|
@@ -49,12 +44,14 @@ class HttpIncomingMessageHost extends stream_1.Duplex {
|
|
|
49
44
|
this.ips = init.ips || (this.ip ? [this.ip] : []);
|
|
50
45
|
if (this.body && !this.headers['content-length'])
|
|
51
46
|
this.headers['content-length'] = String(this.body.length);
|
|
47
|
+
if (init.params)
|
|
48
|
+
this.params = init.params;
|
|
49
|
+
if (init.cookies)
|
|
50
|
+
this.cookies = init.cookies;
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
get httpVersion() {
|
|
55
|
-
return this.httpVersionMajor
|
|
56
|
-
? this.httpVersionMajor + '.' + this.httpVersionMinor
|
|
57
|
-
: '';
|
|
54
|
+
return this.httpVersionMajor ? this.httpVersionMajor + '.' + this.httpVersionMinor : '';
|
|
58
55
|
}
|
|
59
56
|
get headers() {
|
|
60
57
|
if (!this[exports.kHeaders])
|
|
@@ -98,51 +95,13 @@ class HttpIncomingMessageHost extends stream_1.Duplex {
|
|
|
98
95
|
}
|
|
99
96
|
const chunk = this._readStream.read(size);
|
|
100
97
|
this.push(chunk);
|
|
101
|
-
// this.push(null);s
|
|
102
98
|
}
|
|
103
99
|
_write(chunk, encoding, callback) {
|
|
104
|
-
const error = this.
|
|
100
|
+
const error = this[exports.kHttpParser]?.execute(chunk);
|
|
105
101
|
if (error && typeof error === 'object')
|
|
106
102
|
callback(error);
|
|
107
103
|
else
|
|
108
104
|
callback();
|
|
109
105
|
}
|
|
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
106
|
}
|
|
148
|
-
exports.
|
|
107
|
+
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,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeIncomingMessage = void 0;
|
|
4
|
+
const stream_1 = require("stream");
|
|
5
|
+
const http_parser_1 = require("@browsery/http-parser");
|
|
6
|
+
const common_1 = require("@opra/common");
|
|
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
|
+
const msg = new node_incoming_message_host_js_1.NodeIncomingMessageHost();
|
|
23
|
+
const parser = (msg[node_incoming_message_host_js_1.kHttpParser] = new http_parser_1.HTTPParser(http_parser_1.HTTPParser.REQUEST));
|
|
24
|
+
let bodyChunks;
|
|
25
|
+
parser[http_parser_1.HTTPParser.kOnHeadersComplete] = (info) => {
|
|
26
|
+
msg.httpVersionMajor = info.versionMajor;
|
|
27
|
+
msg.httpVersionMinor = info.versionMinor;
|
|
28
|
+
msg.rawHeaders = info.headers;
|
|
29
|
+
msg.method = http_parser_1.HTTPParser.methods[info.method];
|
|
30
|
+
msg.url = info.url;
|
|
31
|
+
msg.emit('headers');
|
|
32
|
+
};
|
|
33
|
+
parser[http_parser_1.HTTPParser.kOnHeaders] = (trailers) => {
|
|
34
|
+
msg.rawTrailers = trailers;
|
|
35
|
+
};
|
|
36
|
+
parser[http_parser_1.HTTPParser.kOnBody] = (chunk, offset, length) => {
|
|
37
|
+
bodyChunks = bodyChunks || [];
|
|
38
|
+
bodyChunks.push(chunk.subarray(offset, offset + length));
|
|
39
|
+
};
|
|
40
|
+
const readable = (0, concat_readable_js_1.concatReadable)(stream_1.Readable.from(iterable), stream_1.Readable.from(node_incoming_message_host_js_1.CRLF));
|
|
41
|
+
msg.once('finish', () => {
|
|
42
|
+
parser.finish();
|
|
43
|
+
msg.complete = true;
|
|
44
|
+
if (bodyChunks)
|
|
45
|
+
msg.body = Buffer.concat(bodyChunks);
|
|
46
|
+
});
|
|
47
|
+
readable.pipe(msg);
|
|
48
|
+
return msg;
|
|
49
|
+
}
|
|
50
|
+
NodeIncomingMessage.from = from;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new NodeIncomingMessage from given argument
|
|
53
|
+
* @param iterable
|
|
54
|
+
*/
|
|
55
|
+
async function fromAsync(iterable) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
const msg = from(iterable);
|
|
58
|
+
msg.once('finish', () => resolve(msg));
|
|
59
|
+
msg.once('error', error => reject(error));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
NodeIncomingMessage.fromAsync = fromAsync;
|
|
63
|
+
})(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 = {}));
|