@opra/common 0.19.0 → 0.20.1
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/browser.js +117 -683
- package/cjs/document/data-type/builtin/index.js +2 -0
- package/cjs/document/data-type/builtin/null.type.js +15 -0
- package/cjs/document/data-type/builtin/object-id.type.js +15 -0
- package/cjs/document/data-type/complex-type.js +1 -0
- package/cjs/document/data-type/enum-type.js +1 -0
- package/cjs/document/data-type/mapped-type.js +1 -0
- package/cjs/document/data-type/simple-type.js +1 -0
- package/cjs/document/data-type/union-type.js +1 -0
- package/cjs/document/factory/create-document.js +3 -3
- package/cjs/http/index.js +1 -2
- package/esm/document/data-type/builtin/index.js +2 -0
- package/esm/document/data-type/builtin/null.type.js +12 -0
- package/esm/document/data-type/builtin/object-id.type.js +12 -0
- package/esm/document/data-type/complex-type.js +1 -0
- package/esm/document/data-type/enum-type.js +1 -0
- package/esm/document/data-type/mapped-type.js +1 -0
- package/esm/document/data-type/simple-type.js +1 -0
- package/esm/document/data-type/union-type.js +1 -0
- package/esm/document/factory/create-document.js +4 -4
- package/esm/http/index.js +1 -2
- package/package.json +9 -24
- package/types/document/data-type/builtin/index.d.ts +2 -0
- package/types/document/data-type/builtin/null.type.d.ts +2 -0
- package/types/document/data-type/builtin/object-id.type.d.ts +2 -0
- package/types/document/data-type/complex-type.d.ts +1 -0
- package/types/document/data-type/enum-type.d.ts +1 -0
- package/types/document/data-type/mapped-type.d.ts +1 -0
- package/types/document/data-type/simple-type.d.ts +1 -0
- package/types/document/data-type/union-type.d.ts +1 -0
- package/types/exception/error-issue.d.ts +1 -1
- package/types/http/index.d.ts +1 -2
- package/cjs/http/http-message.host.js +0 -251
- package/cjs/http/http-request-message.js +0 -152
- package/cjs/http/http-response-message.js +0 -238
- package/cjs/http/interfaces/cookie-options.interface.js +0 -2
- package/esm/http/http-message.host.js +0 -246
- package/esm/http/http-request-message.js +0 -148
- package/esm/http/http-response-message.js +0 -233
- package/esm/http/interfaces/cookie-options.interface.js +0 -1
- package/types/http/http-message.host.d.ts +0 -122
- package/types/http/http-request-message.d.ts +0 -213
- package/types/http/http-response-message.d.ts +0 -318
- package/types/http/interfaces/cookie-options.interface.d.ts +0 -4
|
@@ -8,8 +8,10 @@ tslib_1.__exportStar(require("./boolean.type.js"), exports);
|
|
|
8
8
|
tslib_1.__exportStar(require("./date.type.js"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./uuid.type.js"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./integer.type.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./null.type.js"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./number.type.js"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./object.type.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./object-id.type.js"), exports);
|
|
13
15
|
tslib_1.__exportStar(require("./string.type.js"), exports);
|
|
14
16
|
tslib_1.__exportStar(require("./time.type.js"), exports);
|
|
15
17
|
tslib_1.__exportStar(require("./timestamp.type.js"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NullType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
|
+
const simple_type_js_1 = require("../simple-type.js");
|
|
7
|
+
let NullType = exports.NullType = class NullType {
|
|
8
|
+
};
|
|
9
|
+
exports.NullType = NullType = tslib_1.__decorate([
|
|
10
|
+
(0, simple_type_js_1.SimpleType)({
|
|
11
|
+
description: 'A Null value',
|
|
12
|
+
decoder: (0, valgen_1.isNull)(),
|
|
13
|
+
encoder: (0, valgen_1.isNull)()
|
|
14
|
+
})
|
|
15
|
+
], NullType);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObjectIdType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const valgen_1 = require("valgen");
|
|
6
|
+
const simple_type_js_1 = require("../simple-type.js");
|
|
7
|
+
let ObjectIdType = exports.ObjectIdType = class ObjectIdType {
|
|
8
|
+
};
|
|
9
|
+
exports.ObjectIdType = ObjectIdType = tslib_1.__decorate([
|
|
10
|
+
(0, simple_type_js_1.SimpleType)({
|
|
11
|
+
description: 'A MongoDB ObjectID value',
|
|
12
|
+
decoder: (0, valgen_1.isObjectId)(),
|
|
13
|
+
encoder: (0, valgen_1.pipe)((0, valgen_1.isObjectId)(), (0, valgen_1.isString)())
|
|
14
|
+
})
|
|
15
|
+
], ObjectIdType);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ComplexType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
5
6
|
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
7
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
8
|
const vg = tslib_1.__importStar(require("valgen"));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EnumType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
5
6
|
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
7
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
8
|
const vg = tslib_1.__importStar(require("valgen"));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OmitType = exports.PickType = exports.MappedType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
5
6
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
7
|
const vg = tslib_1.__importStar(require("valgen"));
|
|
7
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SimpleType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
5
6
|
const lodash_omit_1 = tslib_1.__importDefault(require("lodash.omit"));
|
|
6
7
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
7
8
|
const vg = tslib_1.__importStar(require("valgen"));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UnionType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
require("reflect-metadata");
|
|
5
6
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
7
|
const vg = tslib_1.__importStar(require("valgen"));
|
|
7
8
|
const index_js_1 = require("../../helpers/index.js");
|
|
@@ -4,7 +4,6 @@ exports.createBuiltinTypeDocument = exports.createDocumentFromUrl = exports.crea
|
|
|
4
4
|
const index_js_1 = require("../../schema/index.js");
|
|
5
5
|
const index_js_2 = require("../data-type/builtin/index.js");
|
|
6
6
|
async function createDocument(init, options) {
|
|
7
|
-
// const {document, typeQueue, curPath, resourceQueue} = this;
|
|
8
7
|
this.document.url = init.url;
|
|
9
8
|
if (init.info)
|
|
10
9
|
Object.assign(this.document.info, init.info);
|
|
@@ -72,8 +71,9 @@ async function createBuiltinTypeDocument() {
|
|
|
72
71
|
}
|
|
73
72
|
},
|
|
74
73
|
types: [index_js_2.AnyType, index_js_2.Base64Type, index_js_2.BigintType, index_js_2.BooleanType,
|
|
75
|
-
index_js_2.DateType, index_js_2.UuidType, index_js_2.IntegerType, index_js_2.
|
|
76
|
-
index_js_2.
|
|
74
|
+
index_js_2.DateType, index_js_2.UuidType, index_js_2.IntegerType, index_js_2.NullType,
|
|
75
|
+
index_js_2.NumberType, index_js_2.ObjectType, index_js_2.ObjectIdType, index_js_2.StringType,
|
|
76
|
+
index_js_2.TimeType, index_js_2.TimestampType
|
|
77
77
|
]
|
|
78
78
|
};
|
|
79
79
|
const factoryClass = Object.getPrototypeOf(this).constructor;
|
package/cjs/http/index.js
CHANGED
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./http-headers.js"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./http-params.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./http-response-message.js"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./http-request-message.js"), exports);
|
|
8
6
|
tslib_1.__exportStar(require("./enums/http-headers-codes.enum.js"), exports);
|
|
9
7
|
tslib_1.__exportStar(require("./enums/http-status-codes.enum.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./enums/http-status-messages.js"), exports);
|
|
10
9
|
tslib_1.__exportStar(require("./interfaces/client-http-headers.interface.js"), exports);
|
|
11
10
|
tslib_1.__exportStar(require("./interfaces/server-http-headers.interface.js"), exports);
|
|
12
11
|
tslib_1.__exportStar(require("./codecs/date-codec.js"), exports);
|
|
@@ -5,8 +5,10 @@ export * from './boolean.type.js';
|
|
|
5
5
|
export * from './date.type.js';
|
|
6
6
|
export * from './uuid.type.js';
|
|
7
7
|
export * from './integer.type.js';
|
|
8
|
+
export * from './null.type.js';
|
|
8
9
|
export * from './number.type.js';
|
|
9
10
|
export * from './object.type.js';
|
|
11
|
+
export * from './object-id.type.js';
|
|
10
12
|
export * from './string.type.js';
|
|
11
13
|
export * from './time.type.js';
|
|
12
14
|
export * from './timestamp.type.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { isNull } from 'valgen';
|
|
3
|
+
import { SimpleType } from '../simple-type.js';
|
|
4
|
+
export let NullType = class NullType {
|
|
5
|
+
};
|
|
6
|
+
NullType = __decorate([
|
|
7
|
+
SimpleType({
|
|
8
|
+
description: 'A Null value',
|
|
9
|
+
decoder: isNull(),
|
|
10
|
+
encoder: isNull()
|
|
11
|
+
})
|
|
12
|
+
], NullType);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { isObjectId, isString, pipe } from 'valgen';
|
|
3
|
+
import { SimpleType } from '../simple-type.js';
|
|
4
|
+
export let ObjectIdType = class ObjectIdType {
|
|
5
|
+
};
|
|
6
|
+
ObjectIdType = __decorate([
|
|
7
|
+
SimpleType({
|
|
8
|
+
description: 'A MongoDB ObjectID value',
|
|
9
|
+
decoder: isObjectId(),
|
|
10
|
+
encoder: pipe(isObjectId(), isString())
|
|
11
|
+
})
|
|
12
|
+
], ObjectIdType);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { OpraSchema } from '../../schema/index.js';
|
|
2
|
-
import { AnyType, Base64Type, BigintType, BooleanType, DateType, IntegerType, NumberType, ObjectType, StringType, TimestampType, TimeType, UuidType } from '../data-type/builtin/index.js';
|
|
2
|
+
import { AnyType, Base64Type, BigintType, BooleanType, DateType, IntegerType, NullType, NumberType, ObjectIdType, ObjectType, StringType, TimestampType, TimeType, UuidType } from '../data-type/builtin/index.js';
|
|
3
3
|
export async function createDocument(init, options) {
|
|
4
|
-
// const {document, typeQueue, curPath, resourceQueue} = this;
|
|
5
4
|
this.document.url = init.url;
|
|
6
5
|
if (init.info)
|
|
7
6
|
Object.assign(this.document.info, init.info);
|
|
@@ -67,8 +66,9 @@ export async function createBuiltinTypeDocument() {
|
|
|
67
66
|
}
|
|
68
67
|
},
|
|
69
68
|
types: [AnyType, Base64Type, BigintType, BooleanType,
|
|
70
|
-
DateType, UuidType, IntegerType,
|
|
71
|
-
ObjectType,
|
|
69
|
+
DateType, UuidType, IntegerType, NullType,
|
|
70
|
+
NumberType, ObjectType, ObjectIdType, StringType,
|
|
71
|
+
TimeType, TimestampType
|
|
72
72
|
]
|
|
73
73
|
};
|
|
74
74
|
const factoryClass = Object.getPrototypeOf(this).constructor;
|
package/esm/http/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export * from './http-headers.js';
|
|
2
2
|
export * from './http-params.js';
|
|
3
|
-
export * from './http-response-message.js';
|
|
4
|
-
export * from './http-request-message.js';
|
|
5
3
|
export * from './enums/http-headers-codes.enum.js';
|
|
6
4
|
export * from './enums/http-status-codes.enum.js';
|
|
5
|
+
export * from './enums/http-status-messages.js';
|
|
7
6
|
export * from './interfaces/client-http-headers.interface.js';
|
|
8
7
|
export * from './interfaces/server-http-headers.interface.js';
|
|
9
8
|
export * from './codecs/date-codec.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Opra
|
|
3
|
+
"version": "0.20.1",
|
|
4
|
+
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -41,42 +41,27 @@
|
|
|
41
41
|
"antlr4": "java -jar ./tools/antlr4-4.12.1-SNAPSHOT-complete.jar -Dlanguage=TypeScript ./src/filter/antlr/OpraFilter.g4 -visitor"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@browsery/antlr4": "^0.
|
|
45
|
-
"@browsery/highland": "^0.
|
|
44
|
+
"@browsery/antlr4": "^0.8.0",
|
|
45
|
+
"@browsery/highland": "^0.5.0",
|
|
46
46
|
"@browsery/http-parser": "^0.4.0",
|
|
47
|
-
"@browsery/i18next": "^0.
|
|
48
|
-
"accepts": "^1.3.8",
|
|
49
|
-
"content-disposition": "^0.5.4",
|
|
50
|
-
"cookie": "^0.5.0",
|
|
51
|
-
"cookie-signature": "^1.2.1",
|
|
52
|
-
"dayjs": "^1.11.8",
|
|
53
|
-
"encodeurl": "^1.0.2",
|
|
47
|
+
"@browsery/i18next": "^0.6.0",
|
|
54
48
|
"fast-tokenizer": "^1.2.2",
|
|
55
|
-
"fastest-validator": "^1.17.0",
|
|
56
49
|
"lodash.omit": "^4.5.0",
|
|
57
|
-
"
|
|
50
|
+
"path-browserify": "^1.0.1",
|
|
58
51
|
"putil-isplainobject": "^1.1.5",
|
|
59
52
|
"putil-merge": "^3.10.3",
|
|
60
53
|
"putil-promisify": "^1.10.0",
|
|
61
54
|
"putil-varhelpers": "^1.6.5",
|
|
62
55
|
"reflect-metadata": "^0.1.13",
|
|
63
|
-
"type-is": "^1.6.18",
|
|
64
56
|
"uid": "^2.0.1",
|
|
65
|
-
"valgen": "^4.0.0-alpha.
|
|
57
|
+
"valgen": "^4.0.0-alpha.6"
|
|
66
58
|
},
|
|
67
59
|
"devDependencies": {
|
|
68
60
|
"@browsery/fs": "^0.4.0",
|
|
69
|
-
"@browsery/stream": "^0.
|
|
61
|
+
"@browsery/stream": "^0.5.0",
|
|
70
62
|
"@browsery/util": "^0.4.0",
|
|
71
|
-
"@types/accepts": "^1.3.5",
|
|
72
|
-
"@types/content-disposition": "^0.5.5",
|
|
73
|
-
"@types/cookie": "^0.5.1",
|
|
74
|
-
"@types/cookie-signature": "^1.1.0",
|
|
75
63
|
"@types/encodeurl": "^1.0.0",
|
|
76
|
-
"@types/
|
|
77
|
-
"@types/type-is": "^1.6.3",
|
|
78
|
-
"crypto-browserify": "^3.12.0",
|
|
79
|
-
"path-browserify": "^1.0.1",
|
|
64
|
+
"@types/validator": "^13.7.17",
|
|
80
65
|
"ts-gems": "^2.4.0"
|
|
81
66
|
},
|
|
82
67
|
"engines": {
|
|
@@ -5,8 +5,10 @@ export * from './boolean.type.js';
|
|
|
5
5
|
export * from './date.type.js';
|
|
6
6
|
export * from './uuid.type.js';
|
|
7
7
|
export * from './integer.type.js';
|
|
8
|
+
export * from './null.type.js';
|
|
8
9
|
export * from './number.type.js';
|
|
9
10
|
export * from './object.type.js';
|
|
11
|
+
export * from './object-id.type.js';
|
|
10
12
|
export * from './string.type.js';
|
|
11
13
|
export * from './time.type.js';
|
|
12
14
|
export * from './timestamp.type.js';
|
package/types/http/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export * from './http-headers.js';
|
|
2
2
|
export * from './http-params.js';
|
|
3
|
-
export * from './http-response-message.js';
|
|
4
|
-
export * from './http-request-message.js';
|
|
5
3
|
export * from './enums/http-headers-codes.enum.js';
|
|
6
4
|
export * from './enums/http-status-codes.enum.js';
|
|
5
|
+
export * from './enums/http-status-messages.js';
|
|
7
6
|
export * from './interfaces/client-http-headers.interface.js';
|
|
8
7
|
export * from './interfaces/server-http-headers.interface.js';
|
|
9
8
|
export * from './codecs/date-codec.js';
|
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpMessageHost = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const stream_1 = tslib_1.__importDefault(require("stream"));
|
|
6
|
-
const http_parser_1 = require("@browsery/http-parser");
|
|
7
|
-
const http_headers_js_1 = require("./http-headers.js");
|
|
8
|
-
const kHeaders = Symbol('kHeaders');
|
|
9
|
-
const kHeadersProxy = Symbol('kHeadersProxy');
|
|
10
|
-
const kTrailers = Symbol('kTrailers');
|
|
11
|
-
const kTrailersProxy = Symbol('kTrailersProxy');
|
|
12
|
-
const kOnHeaderReceived = Symbol('kOnHeaderReceived');
|
|
13
|
-
const kOnTrailersReceived = Symbol('kOnTrailersReceived');
|
|
14
|
-
const kOnBodyChunk = Symbol('kOnBodyChunk');
|
|
15
|
-
const kOnReadComplete = Symbol('kOnReadComplete');
|
|
16
|
-
const crlfBuffer = Buffer.from('\r\n');
|
|
17
|
-
const HTTP_VERSION_PATTERN = /^(\d)\.(\d)$/;
|
|
18
|
-
class HttpMessageHost {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.complete = false;
|
|
21
|
-
stream_1.default.Duplex.apply(this);
|
|
22
|
-
this[kHeaders] = new http_headers_js_1.HttpHeaders(undefined, {
|
|
23
|
-
onChange: () => this._headersChanged = true
|
|
24
|
-
});
|
|
25
|
-
this[kTrailers] = new http_headers_js_1.HttpHeaders(undefined, {
|
|
26
|
-
onChange: () => this._trailersChanged = true
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
get httpVersion() {
|
|
30
|
-
return this.httpVersionMajor
|
|
31
|
-
? this.httpVersionMajor + '.' + (this.httpVersionMinor || 0)
|
|
32
|
-
: undefined;
|
|
33
|
-
}
|
|
34
|
-
set httpVersion(value) {
|
|
35
|
-
if (value) {
|
|
36
|
-
const m = HTTP_VERSION_PATTERN.exec(value);
|
|
37
|
-
if (!m)
|
|
38
|
-
throw new TypeError(`Invalid http version string (${value})`);
|
|
39
|
-
this.httpVersionMajor = parseInt(m[1], 10);
|
|
40
|
-
this.httpVersionMinor = parseInt(m[2], 10);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.httpVersionMajor = undefined;
|
|
44
|
-
this.httpVersionMinor = undefined;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
get headers() {
|
|
48
|
-
this._initHeaders();
|
|
49
|
-
return this[kHeadersProxy];
|
|
50
|
-
}
|
|
51
|
-
set headers(headers) {
|
|
52
|
-
this[kHeaders].clear();
|
|
53
|
-
this[kHeaders].set(headers);
|
|
54
|
-
}
|
|
55
|
-
get trailers() {
|
|
56
|
-
this._initTrailers();
|
|
57
|
-
return this[kTrailersProxy];
|
|
58
|
-
}
|
|
59
|
-
set trailers(trailers) {
|
|
60
|
-
this[kTrailers].clear();
|
|
61
|
-
this[kTrailers].set(trailers);
|
|
62
|
-
}
|
|
63
|
-
get rawHeaders() {
|
|
64
|
-
this._buildRawHeaders();
|
|
65
|
-
return this._rawHeaders;
|
|
66
|
-
}
|
|
67
|
-
set rawHeaders(headers) {
|
|
68
|
-
this[kHeadersProxy] = undefined;
|
|
69
|
-
this._headersChanged = false;
|
|
70
|
-
this._rawHeaders = headers;
|
|
71
|
-
}
|
|
72
|
-
get rawTrailers() {
|
|
73
|
-
this._buildRawTrailers();
|
|
74
|
-
return this._rawTrailers;
|
|
75
|
-
}
|
|
76
|
-
set rawTrailers(trailers) {
|
|
77
|
-
this[kTrailersProxy] = undefined;
|
|
78
|
-
this._trailersChanged = false;
|
|
79
|
-
this._rawTrailers = trailers;
|
|
80
|
-
}
|
|
81
|
-
getHeader(name) {
|
|
82
|
-
if (!name)
|
|
83
|
-
return;
|
|
84
|
-
this._initHeaders();
|
|
85
|
-
switch (name.toLowerCase()) {
|
|
86
|
-
case 'referer':
|
|
87
|
-
case 'referrer':
|
|
88
|
-
return this[kHeaders].get(name) ||
|
|
89
|
-
this[kHeaders].get('referrer') ||
|
|
90
|
-
this[kHeaders].get('referer');
|
|
91
|
-
default:
|
|
92
|
-
return this[kHeaders].get(name);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
get(name) {
|
|
96
|
-
this._initHeaders();
|
|
97
|
-
return this[kHeaders].get(name);
|
|
98
|
-
}
|
|
99
|
-
setHeader(arg0, arg1) {
|
|
100
|
-
this._initHeaders();
|
|
101
|
-
if (typeof arg0 === 'object')
|
|
102
|
-
this[kHeaders].set(arg0);
|
|
103
|
-
else
|
|
104
|
-
this[kHeaders].set(arg0, arg1);
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
set(arg0, arg1) {
|
|
108
|
-
return this.setHeader(arg0, arg1);
|
|
109
|
-
}
|
|
110
|
-
getHeaders() {
|
|
111
|
-
this._initHeaders();
|
|
112
|
-
return this[kHeaders].toObject();
|
|
113
|
-
}
|
|
114
|
-
getHeaderNames() {
|
|
115
|
-
this._initHeaders();
|
|
116
|
-
return Array.from(this[kHeaders].keys());
|
|
117
|
-
}
|
|
118
|
-
hasHeader(name) {
|
|
119
|
-
this._initHeaders();
|
|
120
|
-
return this[kHeaders].has(name);
|
|
121
|
-
}
|
|
122
|
-
removeHeader(name) {
|
|
123
|
-
this._initHeaders();
|
|
124
|
-
this[kHeaders].delete(name);
|
|
125
|
-
}
|
|
126
|
-
send(body) {
|
|
127
|
-
this.body = body;
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
end(body) {
|
|
131
|
-
if (body)
|
|
132
|
-
this.body = body;
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
setTimeout() {
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
_init(args) {
|
|
139
|
-
this.complete = true;
|
|
140
|
-
this.httpVersionMajor = args?.httpVersionMajor;
|
|
141
|
-
this.httpVersionMinor = args?.httpVersionMinor;
|
|
142
|
-
this._rawHeaders = args.rawHeaders;
|
|
143
|
-
this._rawTrailers = args.rawTrailers;
|
|
144
|
-
if (args.headers)
|
|
145
|
-
this[kHeaders].set(args.headers);
|
|
146
|
-
if (args.trailers)
|
|
147
|
-
this[kTrailers].set(args.trailers);
|
|
148
|
-
this.body = args.body;
|
|
149
|
-
}
|
|
150
|
-
_parseBuffer(buf, parserType) {
|
|
151
|
-
const parser = new http_parser_1.HTTPParser(parserType);
|
|
152
|
-
parser[http_parser_1.HTTPParser.kOnHeadersComplete] = this[kOnHeaderReceived].bind(this);
|
|
153
|
-
parser[http_parser_1.HTTPParser.kOnBody] = this[kOnBodyChunk].bind(this);
|
|
154
|
-
parser[http_parser_1.HTTPParser.kOnHeaders] = this[kOnTrailersReceived].bind(this);
|
|
155
|
-
parser[http_parser_1.HTTPParser.kOnMessageComplete] = this[kOnReadComplete].bind(this);
|
|
156
|
-
const buffer = Buffer.from(buf);
|
|
157
|
-
let x = parser.execute(buffer);
|
|
158
|
-
if (typeof x === 'object')
|
|
159
|
-
throw x;
|
|
160
|
-
if (!this.complete) {
|
|
161
|
-
x = parser.execute(crlfBuffer);
|
|
162
|
-
if (typeof x === 'object')
|
|
163
|
-
throw x;
|
|
164
|
-
}
|
|
165
|
-
parser.finish();
|
|
166
|
-
}
|
|
167
|
-
_initHeaders() {
|
|
168
|
-
if (!this[kHeadersProxy]) {
|
|
169
|
-
this[kHeadersProxy] = this[kHeaders].getProxy();
|
|
170
|
-
if (this._rawHeaders) {
|
|
171
|
-
const src = this._rawHeaders;
|
|
172
|
-
const l = Math.floor(src.length / 2);
|
|
173
|
-
for (let n = 0; n <= l; n += 2) {
|
|
174
|
-
this[kHeaders].append(src[n], src[n + 1]);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
_initTrailers() {
|
|
180
|
-
if (!this[kTrailersProxy]) {
|
|
181
|
-
this[kTrailersProxy] = this[kTrailers].getProxy();
|
|
182
|
-
if (this._rawTrailers) {
|
|
183
|
-
const src = this._rawTrailers;
|
|
184
|
-
const l = Math.floor(src.length / 2);
|
|
185
|
-
for (let n = 0; n <= l; n += 2) {
|
|
186
|
-
this[kTrailers].append(src[n], src[n + 1]);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
_buildRawHeaders() {
|
|
192
|
-
// Rebuild rawHeaders if headers object changed
|
|
193
|
-
if (this._headersChanged || !this._rawHeaders) {
|
|
194
|
-
this._headersChanged = false;
|
|
195
|
-
this._rawHeaders = Object.entries(this.headers)
|
|
196
|
-
.reduce((a, [k, v]) => {
|
|
197
|
-
if (Array.isArray(v))
|
|
198
|
-
v.forEach(x => a.push(k, String(x)));
|
|
199
|
-
else
|
|
200
|
-
a.push(k, String(v));
|
|
201
|
-
return a;
|
|
202
|
-
}, []);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
_buildRawTrailers() {
|
|
206
|
-
// Rebuild rawHeaders if headers object changed
|
|
207
|
-
if (this._trailersChanged || !this._rawTrailers) {
|
|
208
|
-
this._trailersChanged = false;
|
|
209
|
-
this._rawTrailers = Object.entries(this.trailers)
|
|
210
|
-
.reduce((a, [k, v]) => {
|
|
211
|
-
if (Array.isArray(v))
|
|
212
|
-
v.forEach(x => a.push(k, String(x)));
|
|
213
|
-
else
|
|
214
|
-
a.push(k, String(v));
|
|
215
|
-
return a;
|
|
216
|
-
}, []);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
[kOnHeaderReceived](info) {
|
|
220
|
-
this.httpVersionMajor = info.versionMajor;
|
|
221
|
-
this.httpVersionMinor = info.versionMinor;
|
|
222
|
-
this._rawHeaders = info.headers;
|
|
223
|
-
this.shouldKeepAlive = info.shouldKeepAlive;
|
|
224
|
-
this.upgrade = info.upgrade;
|
|
225
|
-
}
|
|
226
|
-
[kOnTrailersReceived](trailers) {
|
|
227
|
-
this._rawTrailers = trailers;
|
|
228
|
-
}
|
|
229
|
-
[kOnBodyChunk](chunk, offset, length) {
|
|
230
|
-
this._bodyChunks = this._bodyChunks || [];
|
|
231
|
-
this._bodyChunks.push(chunk.subarray(offset, offset + length));
|
|
232
|
-
}
|
|
233
|
-
[kOnReadComplete]() {
|
|
234
|
-
this.complete = true;
|
|
235
|
-
if (this._bodyChunks) {
|
|
236
|
-
this.body = Buffer.concat(this._bodyChunks);
|
|
237
|
-
this._bodyChunks = undefined;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
exports.HttpMessageHost = HttpMessageHost;
|
|
242
|
-
HttpMessageHost.kHeaders = kHeaders;
|
|
243
|
-
HttpMessageHost.kHeadersProxy = kHeadersProxy;
|
|
244
|
-
HttpMessageHost.kTrailers = kTrailers;
|
|
245
|
-
HttpMessageHost.kTrailersProxy = kTrailersProxy;
|
|
246
|
-
HttpMessageHost.kOnHeaderReceived = kOnHeaderReceived;
|
|
247
|
-
HttpMessageHost.kOnTrailersReceived = kOnTrailersReceived;
|
|
248
|
-
HttpMessageHost.kOnBodyChunk = kOnBodyChunk;
|
|
249
|
-
HttpMessageHost.kOnReadComplete = kOnReadComplete;
|
|
250
|
-
// Mixin with Duplex
|
|
251
|
-
Object.assign(HttpMessageHost.prototype, stream_1.default.Duplex.prototype);
|