@opra/core 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/adapter/execution-context.host.js +48 -0
- package/cjs/adapter/http/express-adapter.host.js +24 -0
- package/cjs/adapter/http/express-adapter.js +12 -45
- package/cjs/adapter/http/helpers/concat-readable.js +20 -0
- package/cjs/adapter/http/helpers/multipart-helper.js +96 -0
- package/cjs/adapter/http/helpers/query-parsers.js +16 -0
- package/cjs/adapter/http/http-adapter-base.js +127 -0
- package/cjs/adapter/http/http-adapter.host.js +57 -0
- package/cjs/adapter/http/http-adapter.js +11 -129
- package/cjs/adapter/http/{impl/http-server-request.js → http-server-request.js} +11 -5
- package/cjs/adapter/http/{impl/http-server-response.js → http-server-response.js} +22 -22
- package/cjs/adapter/http/impl/http-incoming-message.host.js +148 -0
- package/cjs/adapter/http/impl/{http-outgoing-message-host.js → http-outgoing-message.host.js} +26 -38
- package/cjs/adapter/http/request-handlers/entity-request-handler.js +378 -0
- package/cjs/adapter/http/request-handlers/request-handler-base.js +27 -0
- package/cjs/adapter/http/request-handlers/storage-request-handler.js +134 -0
- package/cjs/adapter/operation-context.js +16 -0
- package/cjs/adapter/platform-adapter.host.js +107 -0
- package/cjs/adapter/request.host.js +1 -2
- package/cjs/adapter/request.js +2 -0
- package/cjs/adapter/response.js +2 -0
- package/cjs/adapter/services/logger.js +36 -0
- package/cjs/augmentation/collection.augmentation.js +2 -0
- package/cjs/augmentation/singleton.augmentation.js +2 -0
- package/cjs/augmentation/storage.augmentation.js +2 -0
- package/cjs/index.js +15 -9
- package/esm/adapter/execution-context.host.js +44 -0
- package/esm/adapter/http/express-adapter.host.js +20 -0
- package/esm/adapter/http/express-adapter.js +11 -20
- package/esm/adapter/http/helpers/concat-readable.js +16 -0
- package/esm/adapter/http/helpers/multipart-helper.js +91 -0
- package/esm/adapter/http/helpers/query-parsers.js +12 -0
- package/esm/adapter/http/http-adapter-base.js +123 -0
- package/esm/adapter/http/http-adapter.host.js +52 -0
- package/esm/adapter/http/http-adapter.js +11 -128
- package/esm/adapter/http/{impl/http-server-request.js → http-server-request.js} +12 -6
- package/esm/adapter/http/{impl/http-server-response.js → http-server-response.js} +22 -22
- package/esm/adapter/http/impl/http-incoming-message.host.js +144 -0
- package/esm/adapter/http/impl/{http-outgoing-message-host.js → http-outgoing-message.host.js} +25 -36
- package/esm/adapter/http/request-handlers/entity-request-handler.js +373 -0
- package/esm/adapter/http/request-handlers/request-handler-base.js +23 -0
- package/esm/adapter/http/request-handlers/storage-request-handler.js +129 -0
- package/esm/adapter/operation-context.js +13 -0
- package/esm/adapter/platform-adapter.host.js +102 -0
- package/esm/adapter/request.host.js +1 -2
- package/esm/adapter/request.js +1 -0
- package/esm/adapter/response.js +1 -0
- package/esm/adapter/services/logger.js +32 -0
- package/esm/augmentation/collection.augmentation.js +1 -0
- package/esm/augmentation/singleton.augmentation.js +1 -0
- package/esm/augmentation/storage.augmentation.js +1 -0
- package/esm/index.js +15 -9
- package/i18n/en/error.json +5 -2
- package/package.json +8 -7
- package/types/adapter/execution-context.d.ts +31 -0
- package/types/adapter/execution-context.host.d.ts +27 -0
- package/types/adapter/http/express-adapter.d.ts +12 -8
- package/types/adapter/http/express-adapter.host.d.ts +11 -0
- package/types/adapter/http/helpers/concat-readable.d.ts +3 -0
- package/types/adapter/http/helpers/multipart-helper.d.ts +25 -0
- package/types/adapter/http/helpers/query-parsers.d.ts +1 -0
- package/types/adapter/http/http-adapter-base.d.ts +23 -0
- package/types/adapter/http/http-adapter.d.ts +13 -29
- package/types/adapter/http/http-adapter.host.d.ts +18 -0
- package/types/adapter/http/{impl/http-server-request.d.ts → http-server-request.d.ts} +7 -6
- package/types/adapter/http/{impl/http-server-response.d.ts → http-server-response.d.ts} +2 -2
- package/types/adapter/http/impl/{http-incoming-message-host.d.ts → http-incoming-message.host.d.ts} +16 -12
- package/types/adapter/http/impl/{http-outgoing-message-host.d.ts → http-outgoing-message.host.d.ts} +12 -16
- package/types/adapter/http/request-handlers/entity-request-handler.d.ts +24 -0
- package/types/adapter/http/request-handlers/request-handler-base.d.ts +15 -0
- package/types/adapter/http/request-handlers/storage-request-handler.d.ts +23 -0
- package/types/adapter/interfaces/logger.interface.d.ts +7 -6
- package/types/adapter/interfaces/request-handler.interface.d.ts +4 -0
- package/types/adapter/operation-context.d.ts +11 -0
- package/types/adapter/{adapter.d.ts → platform-adapter.d.ts} +18 -28
- package/types/adapter/platform-adapter.host.d.ts +31 -0
- package/types/adapter/request.d.ts +11 -0
- package/types/adapter/request.host.d.ts +12 -21
- package/types/adapter/{interfaces/response.interface.d.ts → response.d.ts} +2 -2
- package/types/adapter/response.host.d.ts +2 -2
- package/types/adapter/services/logger.d.ts +14 -0
- package/types/augmentation/collection.augmentation.d.ts +112 -0
- package/types/augmentation/singleton.augmentation.d.ts +64 -0
- package/types/augmentation/storage.augmentation.d.ts +39 -0
- package/types/index.d.ts +15 -9
- package/cjs/adapter/adapter.js +0 -118
- package/cjs/adapter/http/impl/http-incoming-message-host.js +0 -127
- package/cjs/adapter/http/request-parsers/parse-collection-request.js +0 -165
- package/cjs/adapter/http/request-parsers/parse-request.js +0 -24
- package/cjs/adapter/http/request-parsers/parse-singleton-request.js +0 -96
- package/cjs/adapter/internal/metadata.resource.js +0 -26
- package/cjs/adapter/request-context.host.js +0 -44
- package/cjs/shared/collection-resource-base.js +0 -20
- package/esm/adapter/adapter.js +0 -113
- package/esm/adapter/http/impl/http-incoming-message-host.js +0 -122
- package/esm/adapter/http/request-parsers/parse-collection-request.js +0 -161
- package/esm/adapter/http/request-parsers/parse-request.js +0 -20
- package/esm/adapter/http/request-parsers/parse-singleton-request.js +0 -92
- package/esm/adapter/internal/metadata.resource.js +0 -23
- package/esm/adapter/request-context.host.js +0 -40
- package/esm/shared/collection-resource-base.js +0 -16
- package/types/adapter/http/request-parsers/parse-collection-request.d.ts +0 -4
- package/types/adapter/http/request-parsers/parse-request.d.ts +0 -4
- package/types/adapter/http/request-parsers/parse-singleton-request.d.ts +0 -4
- package/types/adapter/interfaces/request-context.interface.d.ts +0 -31
- package/types/adapter/interfaces/request.interface.d.ts +0 -15
- package/types/adapter/internal/metadata.resource.d.ts +0 -7
- package/types/adapter/request-context.host.d.ts +0 -22
- package/types/shared/collection-resource-base.d.ts +0 -11
- /package/cjs/adapter/{interfaces/request-context.interface.js → execution-context.js} +0 -0
- /package/cjs/adapter/http/{request-parsers/batch-request-parser.js → request-handlers/parse-batch-request.js} +0 -0
- /package/cjs/adapter/interfaces/{request.interface.js → request-handler.interface.js} +0 -0
- /package/cjs/adapter/{interfaces/response.interface.js → platform-adapter.js} +0 -0
- /package/esm/adapter/{interfaces/request-context.interface.js → execution-context.js} +0 -0
- /package/esm/adapter/http/{request-parsers/batch-request-parser.js → request-handlers/parse-batch-request.js} +0 -0
- /package/esm/adapter/interfaces/{request.interface.js → request-handler.interface.js} +0 -0
- /package/esm/adapter/{interfaces/response.interface.js → platform-adapter.js} +0 -0
- /package/types/adapter/http/{request-parsers/batch-request-parser.d.ts → request-handlers/parse-batch-request.d.ts} +0 -0
|
@@ -16,20 +16,20 @@ 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("./http-outgoing-message
|
|
19
|
+
const http_outgoing_message_host_js_1 = require("./impl/http-outgoing-message.host.js");
|
|
20
20
|
const charsetRegExp = /;\s*charset\s*=/;
|
|
21
21
|
function isHttpIncomingMessage(v) {
|
|
22
22
|
return v && typeof v.getHeaders === 'function' && (0, common_1.isStream)(v);
|
|
23
23
|
}
|
|
24
24
|
var HttpServerResponse;
|
|
25
25
|
(function (HttpServerResponse) {
|
|
26
|
-
function
|
|
26
|
+
function from(instance) {
|
|
27
27
|
if (!isHttpIncomingMessage(instance))
|
|
28
|
-
instance = http_outgoing_message_host_js_1.HttpOutgoingMessageHost
|
|
28
|
+
instance = new http_outgoing_message_host_js_1.HttpOutgoingMessageHost(instance);
|
|
29
29
|
(0, common_1.mergePrototype)(instance, HttpServerResponseHost.prototype);
|
|
30
30
|
return instance;
|
|
31
31
|
}
|
|
32
|
-
HttpServerResponse.
|
|
32
|
+
HttpServerResponse.from = from;
|
|
33
33
|
})(HttpServerResponse || (exports.HttpServerResponse = HttpServerResponse = {}));
|
|
34
34
|
class HttpServerResponseHost {
|
|
35
35
|
attachment(filename) {
|
|
@@ -47,28 +47,28 @@ class HttpServerResponseHost {
|
|
|
47
47
|
}
|
|
48
48
|
setHeader(field, val) {
|
|
49
49
|
const setHeader = Object.getPrototypeOf(this).setHeader;
|
|
50
|
-
if (typeof field === '
|
|
51
|
-
let value = Array.isArray(val)
|
|
52
|
-
? val.map(String)
|
|
53
|
-
: (val ? String(val) : '');
|
|
54
|
-
// add charset to content-type
|
|
55
|
-
if (field.toLowerCase() === 'content-type') {
|
|
56
|
-
if (Array.isArray(value)) {
|
|
57
|
-
throw new TypeError('Content-Type cannot be set to an Array');
|
|
58
|
-
}
|
|
59
|
-
if (!charsetRegExp.test(value)) {
|
|
60
|
-
const charset = mime_types_1.default.charsets.lookup(value.split(';')[0]);
|
|
61
|
-
if (charset)
|
|
62
|
-
value += '; charset=' + charset.toLowerCase();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
setHeader.call(this, field, value);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
50
|
+
if (typeof field === 'object') {
|
|
68
51
|
for (const [k, v] of Object.entries(field)) {
|
|
69
52
|
this.setHeader(k, v);
|
|
70
53
|
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
const fieldLower = field.toLowerCase();
|
|
57
|
+
let value = Array.isArray(val)
|
|
58
|
+
? val.map(String)
|
|
59
|
+
: (val ? String(val) : '');
|
|
60
|
+
// add charset to content-type
|
|
61
|
+
if (fieldLower === 'content-type') {
|
|
62
|
+
if (Array.isArray(value)) {
|
|
63
|
+
throw new TypeError('Content-Type cannot be set to an Array');
|
|
64
|
+
}
|
|
65
|
+
if (!charsetRegExp.test(value)) {
|
|
66
|
+
const charset = mime_types_1.default.charsets.lookup(value.split(';')[0]);
|
|
67
|
+
if (charset)
|
|
68
|
+
value += '; charset=' + charset.toLowerCase();
|
|
69
|
+
}
|
|
71
70
|
}
|
|
71
|
+
setHeader.call(this, field, value);
|
|
72
72
|
return this;
|
|
73
73
|
}
|
|
74
74
|
clearCookie(name, options) {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
This file contains code blocks from open source NodeJs project
|
|
4
|
+
https://github.com/nodejs/
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.HttpIncomingMessageHost = exports.kTrailersDistinct = exports.kTrailers = exports.kHeadersDistinct = exports.kHeaders = exports.CRLF = void 0;
|
|
8
|
+
const stream_1 = require("stream");
|
|
9
|
+
const http_parser_1 = require("@browsery/http-parser");
|
|
10
|
+
const common_1 = require("@opra/common");
|
|
11
|
+
const concat_readable_js_1 = require("../helpers/concat-readable.js");
|
|
12
|
+
const convert_to_headers_js_1 = require("../helpers/convert-to-headers.js");
|
|
13
|
+
const convert_to_raw_headers_js_1 = require("../helpers/convert-to-raw-headers.js");
|
|
14
|
+
exports.CRLF = Buffer.from('\r\n');
|
|
15
|
+
exports.kHeaders = Symbol.for('kHeaders');
|
|
16
|
+
exports.kHeadersDistinct = Symbol.for('kHeadersDistinct');
|
|
17
|
+
exports.kTrailers = Symbol.for('kTrailers');
|
|
18
|
+
exports.kTrailersDistinct = Symbol.for('kTrailersDistinct');
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @class HttpIncomingMessageHost
|
|
22
|
+
*/
|
|
23
|
+
class HttpIncomingMessageHost extends stream_1.Duplex {
|
|
24
|
+
constructor(init) {
|
|
25
|
+
super();
|
|
26
|
+
this.rawHeaders = [];
|
|
27
|
+
this.rawTrailers = [];
|
|
28
|
+
this.complete = false;
|
|
29
|
+
this.joinDuplicateHeaders = false;
|
|
30
|
+
if (init) {
|
|
31
|
+
this.complete = true;
|
|
32
|
+
this.httpVersionMajor = init.httpVersionMajor || 1;
|
|
33
|
+
this.httpVersionMinor = init.httpVersionMinor || 0;
|
|
34
|
+
this.method = (init.method || 'GET').toUpperCase();
|
|
35
|
+
this.url = init.url || '';
|
|
36
|
+
if (init.body != null) {
|
|
37
|
+
if (Buffer.isBuffer(init.body))
|
|
38
|
+
this.body = init.body;
|
|
39
|
+
else if (typeof init.body === 'string')
|
|
40
|
+
this.body = Buffer.from(init.body, 'utf-8');
|
|
41
|
+
else
|
|
42
|
+
this.body = Buffer.from(JSON.stringify(init.body), 'utf-8');
|
|
43
|
+
}
|
|
44
|
+
if (init.headers)
|
|
45
|
+
this.rawHeaders = Array.isArray(init.headers) ? init.headers : (0, convert_to_raw_headers_js_1.convertToRawHeaders)(init.headers);
|
|
46
|
+
if (init.trailers)
|
|
47
|
+
this.rawTrailers = Array.isArray(init.trailers) ? init.trailers : (0, convert_to_raw_headers_js_1.convertToRawHeaders)(init.trailers);
|
|
48
|
+
this.ip = init.ip || '';
|
|
49
|
+
this.ips = init.ips || (this.ip ? [this.ip] : []);
|
|
50
|
+
if (this.body && !this.headers['content-length'])
|
|
51
|
+
this.headers['content-length'] = String(this.body.length);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
get httpVersion() {
|
|
55
|
+
return this.httpVersionMajor
|
|
56
|
+
? this.httpVersionMajor + '.' + this.httpVersionMinor
|
|
57
|
+
: '';
|
|
58
|
+
}
|
|
59
|
+
get headers() {
|
|
60
|
+
if (!this[exports.kHeaders])
|
|
61
|
+
this[exports.kHeaders] = (0, convert_to_headers_js_1.convertToHeaders)(this.rawHeaders, {}, this.joinDuplicateHeaders);
|
|
62
|
+
return this[exports.kHeaders];
|
|
63
|
+
}
|
|
64
|
+
set headers(headers) {
|
|
65
|
+
this[exports.kHeaders] = headers;
|
|
66
|
+
}
|
|
67
|
+
get headersDistinct() {
|
|
68
|
+
if (!this[exports.kHeadersDistinct])
|
|
69
|
+
this[exports.kHeadersDistinct] = (0, convert_to_headers_js_1.convertToHeadersDistinct)(this.rawHeaders, {});
|
|
70
|
+
return this[exports.kHeadersDistinct];
|
|
71
|
+
}
|
|
72
|
+
get trailers() {
|
|
73
|
+
if (!this[exports.kTrailers])
|
|
74
|
+
this[exports.kTrailers] = (0, convert_to_headers_js_1.convertToHeaders)(this.rawTrailers, {}, this.joinDuplicateHeaders);
|
|
75
|
+
return this[exports.kTrailers];
|
|
76
|
+
}
|
|
77
|
+
set trailers(trailers) {
|
|
78
|
+
this[exports.kTrailers] = trailers;
|
|
79
|
+
}
|
|
80
|
+
get trailersDistinct() {
|
|
81
|
+
if (!this[exports.kTrailersDistinct])
|
|
82
|
+
this[exports.kTrailersDistinct] = (0, convert_to_headers_js_1.convertToHeadersDistinct)(this.rawTrailers, {});
|
|
83
|
+
return this[exports.kTrailersDistinct];
|
|
84
|
+
}
|
|
85
|
+
_read(size) {
|
|
86
|
+
if (!this.body) {
|
|
87
|
+
this.push(null);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!this._readStream) {
|
|
91
|
+
if ((0, common_1.isIterable)(this.body) || (0, common_1.isAsyncIterable)(this.body))
|
|
92
|
+
this._readStream = stream_1.Readable.from(this.body);
|
|
93
|
+
else if (typeof this.body === 'string') {
|
|
94
|
+
this._readStream = stream_1.Readable.from(Buffer.from(this.body, 'utf-8'));
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
this._readStream = stream_1.Readable.from(Buffer.from(JSON.stringify(this.body), 'utf-8'));
|
|
98
|
+
}
|
|
99
|
+
const chunk = this._readStream.read(size);
|
|
100
|
+
this.push(chunk);
|
|
101
|
+
// this.push(null);s
|
|
102
|
+
}
|
|
103
|
+
_write(chunk, encoding, callback) {
|
|
104
|
+
const error = this._httpParser?.execute(chunk);
|
|
105
|
+
if (error && typeof error === 'object')
|
|
106
|
+
callback(error);
|
|
107
|
+
else
|
|
108
|
+
callback();
|
|
109
|
+
}
|
|
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
|
+
}
|
|
148
|
+
exports.HttpIncomingMessageHost = HttpIncomingMessageHost;
|
package/cjs/adapter/http/impl/{http-outgoing-message-host.js → http-outgoing-message.host.js}
RENAMED
|
@@ -3,36 +3,42 @@
|
|
|
3
3
|
This file contains code blocks from open source NodeJs project
|
|
4
4
|
https://github.com/nodejs/
|
|
5
5
|
*/
|
|
6
|
-
var _a;
|
|
7
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.HttpOutgoingMessageHost = exports.
|
|
9
|
-
const
|
|
10
|
-
const stream = tslib_1.__importStar(require("stream"));
|
|
7
|
+
exports.HttpOutgoingMessageHost = exports.kOutTrailers = exports.kOutHeaders = void 0;
|
|
8
|
+
const stream_1 = require("stream");
|
|
11
9
|
const common_js_1 = require("../helpers/common.js");
|
|
12
|
-
exports.kOutHeaders = Symbol('kOutHeaders');
|
|
13
|
-
exports.kOutTrailers = Symbol('kOutTrailers');
|
|
14
|
-
exports.kErrored = Symbol('kErrored');
|
|
10
|
+
exports.kOutHeaders = Symbol.for('kOutHeaders');
|
|
11
|
+
exports.kOutTrailers = Symbol.for('kOutTrailers');
|
|
15
12
|
// noinspection JSUnusedLocalSymbols
|
|
16
13
|
/**
|
|
17
14
|
*
|
|
18
15
|
* @class HttpOutgoingMessageHost
|
|
19
16
|
*/
|
|
20
|
-
class HttpOutgoingMessageHost {
|
|
21
|
-
constructor() {
|
|
17
|
+
class HttpOutgoingMessageHost extends stream_1.Duplex {
|
|
18
|
+
constructor(init) {
|
|
19
|
+
super();
|
|
22
20
|
this._headersSent = false;
|
|
23
|
-
this._closed = false;
|
|
24
|
-
this[_a] = null;
|
|
25
21
|
this.finished = false;
|
|
26
|
-
|
|
22
|
+
if (init) {
|
|
23
|
+
this.req = init.req;
|
|
24
|
+
this.statusCode = init?.statusCode || 0;
|
|
25
|
+
this.statusMessage = init?.statusMessage || '';
|
|
26
|
+
this.chunkedEncoding = !!init?.chunkedEncoding;
|
|
27
|
+
this.sendDate = !!init?.sendDate;
|
|
28
|
+
this.strictContentLength = !!init?.strictContentLength;
|
|
29
|
+
if (init.headers)
|
|
30
|
+
this.setHeaders(Array.isArray(init.headers) ? new Map([init.headers]) : init.headers);
|
|
31
|
+
this.body = init.body;
|
|
32
|
+
}
|
|
27
33
|
}
|
|
28
|
-
get
|
|
29
|
-
return this.
|
|
34
|
+
get httpVersionMajor() {
|
|
35
|
+
return this.req?.httpVersionMajor || this._httpVersionMajor;
|
|
30
36
|
}
|
|
31
|
-
get
|
|
32
|
-
return this.
|
|
37
|
+
get httpVersionMinor() {
|
|
38
|
+
return this.req?.httpVersionMinor || this._httpVersionMinor;
|
|
33
39
|
}
|
|
34
|
-
get
|
|
35
|
-
return this
|
|
40
|
+
get headersSent() {
|
|
41
|
+
return this._headersSent;
|
|
36
42
|
}
|
|
37
43
|
appendHeader(name, value) {
|
|
38
44
|
if (this.headersSent)
|
|
@@ -185,26 +191,8 @@ class HttpOutgoingMessageHost {
|
|
|
185
191
|
//
|
|
186
192
|
return this;
|
|
187
193
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this.statusCode = init?.statusCode || 0;
|
|
191
|
-
this.statusMessage = init?.statusMessage || '';
|
|
192
|
-
this.chunkedEncoding = !!init?.chunkedEncoding;
|
|
193
|
-
this.sendDate = !!init?.sendDate;
|
|
194
|
-
this.strictContentLength = !!init?.strictContentLength;
|
|
195
|
-
if (init.headers) {
|
|
196
|
-
this.setHeaders(Array.isArray(init.headers) ? new Map([init.headers]) : init.headers);
|
|
197
|
-
}
|
|
198
|
-
this.body = init.body;
|
|
199
|
-
}
|
|
200
|
-
static create(init) {
|
|
201
|
-
const msg = new HttpOutgoingMessageHost();
|
|
202
|
-
if (init)
|
|
203
|
-
msg._readConfig(init);
|
|
204
|
-
return msg;
|
|
194
|
+
static from(init) {
|
|
195
|
+
return new HttpOutgoingMessageHost(init);
|
|
205
196
|
}
|
|
206
197
|
}
|
|
207
198
|
exports.HttpOutgoingMessageHost = HttpOutgoingMessageHost;
|
|
208
|
-
_a = exports.kErrored;
|
|
209
|
-
// Apply mixins
|
|
210
|
-
Object.assign(HttpOutgoingMessageHost.prototype, stream.Stream.prototype);
|