@opra/core 0.20.3 → 0.22.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/adapter.js +2 -2
- package/cjs/adapter/http/express-adapter.js +29 -7
- package/cjs/adapter/http/helpers/common.js +66 -0
- package/cjs/adapter/http/helpers/convert-to-headers.js +65 -0
- package/cjs/adapter/http/helpers/convert-to-raw-headers.js +25 -0
- package/cjs/adapter/http/helpers/match-known-fields.js +47 -0
- package/cjs/adapter/http/http-adapter.js +82 -440
- package/cjs/adapter/http/impl/http-incoming-message-host.js +127 -0
- package/cjs/adapter/http/impl/http-outgoing-message-host.js +210 -0
- package/cjs/adapter/http/impl/http-server-request.js +125 -0
- package/cjs/adapter/http/impl/http-server-response.js +226 -0
- package/cjs/adapter/http/request-parsers/batch-request-parser.js +169 -0
- package/cjs/adapter/http/request-parsers/parse-collection-request.js +165 -0
- package/cjs/adapter/http/request-parsers/parse-request.js +24 -0
- package/cjs/adapter/http/request-parsers/parse-singleton-request.js +96 -0
- package/cjs/adapter/request-context.host.js +17 -3
- package/cjs/adapter/request.host.js +6 -3
- package/cjs/adapter/response.host.js +5 -3
- package/cjs/index.js +4 -2
- package/esm/adapter/adapter.js +2 -2
- package/esm/adapter/http/express-adapter.js +6 -6
- package/esm/adapter/http/helpers/common.js +60 -0
- package/esm/adapter/http/helpers/convert-to-headers.js +60 -0
- package/esm/adapter/http/helpers/convert-to-raw-headers.js +21 -0
- package/esm/adapter/http/helpers/match-known-fields.js +43 -0
- package/esm/adapter/http/http-adapter.js +83 -441
- package/esm/adapter/http/impl/http-incoming-message-host.js +122 -0
- package/esm/adapter/http/impl/http-outgoing-message-host.js +205 -0
- package/esm/adapter/http/impl/http-server-request.js +121 -0
- package/esm/adapter/http/impl/http-server-response.js +222 -0
- package/esm/adapter/http/request-parsers/batch-request-parser.js +169 -0
- package/esm/adapter/http/request-parsers/parse-collection-request.js +161 -0
- package/esm/adapter/http/request-parsers/parse-request.js +20 -0
- package/esm/adapter/http/request-parsers/parse-singleton-request.js +92 -0
- package/esm/adapter/request-context.host.js +17 -3
- package/esm/adapter/request.host.js +6 -3
- package/esm/adapter/response.host.js +5 -3
- package/esm/index.js +4 -2
- package/package.json +19 -15
- package/types/adapter/adapter.d.ts +1 -1
- package/types/adapter/http/helpers/common.d.ts +17 -0
- package/types/adapter/http/helpers/convert-to-headers.d.ts +2 -0
- package/types/adapter/http/helpers/convert-to-raw-headers.d.ts +3 -0
- package/types/adapter/http/helpers/match-known-fields.d.ts +6 -0
- package/types/adapter/http/http-adapter.d.ts +7 -12
- package/types/adapter/http/impl/http-incoming-message-host.d.ts +58 -0
- package/types/adapter/http/impl/http-outgoing-message-host.d.ts +72 -0
- package/types/adapter/http/{http-request-message.d.ts → impl/http-server-request.d.ts} +52 -85
- package/types/adapter/http/impl/http-server-response.d.ts +137 -0
- package/types/adapter/http/request-parsers/batch-request-parser.d.ts +0 -0
- package/types/adapter/http/request-parsers/parse-collection-request.d.ts +4 -0
- package/types/adapter/http/request-parsers/parse-request.d.ts +4 -0
- package/types/adapter/http/request-parsers/parse-singleton-request.d.ts +4 -0
- package/types/adapter/interfaces/request-context.interface.d.ts +14 -10
- package/types/adapter/interfaces/request.interface.d.ts +3 -2
- package/types/adapter/interfaces/response.interface.d.ts +2 -2
- package/types/adapter/request-context.host.d.ts +9 -6
- package/types/adapter/request.host.d.ts +8 -4
- package/types/adapter/response.host.d.ts +6 -4
- package/types/index.d.ts +4 -2
- package/cjs/adapter/http/http-message.host.js +0 -251
- package/cjs/adapter/http/http-request-context.host.js +0 -28
- package/cjs/adapter/http/http-request-message.js +0 -152
- package/cjs/adapter/http/http-request.host.js +0 -14
- package/cjs/adapter/http/http-response-message.js +0 -238
- package/cjs/adapter/http/http-response.host.js +0 -14
- package/esm/adapter/http/http-message.host.js +0 -246
- package/esm/adapter/http/http-request-context.host.js +0 -24
- package/esm/adapter/http/http-request-message.js +0 -148
- package/esm/adapter/http/http-request.host.js +0 -10
- package/esm/adapter/http/http-response-message.js +0 -233
- package/esm/adapter/http/http-response.host.js +0 -10
- package/types/adapter/http/http-message.host.d.ts +0 -122
- package/types/adapter/http/http-request-context.host.d.ts +0 -16
- package/types/adapter/http/http-request.host.d.ts +0 -7
- package/types/adapter/http/http-response-message.d.ts +0 -321
- package/types/adapter/http/http-response.host.d.ts +0 -7
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import type { Resource } from '@opra/common';
|
|
2
2
|
import { OpraSchema } from '@opra/common';
|
|
3
|
-
import {
|
|
3
|
+
import { HttpServerRequest } from './http/impl/http-server-request.js';
|
|
4
4
|
import type { Request } from './interfaces/request.interface.js';
|
|
5
5
|
export declare namespace RequestHost {
|
|
6
6
|
interface Initiator {
|
|
7
|
+
contentId?: string;
|
|
7
8
|
kind: string;
|
|
8
9
|
resource: Resource;
|
|
9
10
|
operation: string;
|
|
10
11
|
crud: 'create' | 'read' | 'update' | 'delete';
|
|
11
12
|
many: boolean;
|
|
12
13
|
args: any;
|
|
14
|
+
http?: HttpServerRequest;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
|
-
export declare
|
|
17
|
+
export declare class RequestHost implements Request {
|
|
18
|
+
readonly contentId: string;
|
|
16
19
|
readonly kind: string;
|
|
17
20
|
readonly resource: Resource;
|
|
18
21
|
readonly resourceKind: OpraSchema.Resource.Kind;
|
|
@@ -20,8 +23,9 @@ export declare abstract class RequestHost implements Request {
|
|
|
20
23
|
readonly crud: 'create' | 'read' | 'update' | 'delete';
|
|
21
24
|
readonly many: boolean;
|
|
22
25
|
readonly args: any;
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
readonly http?: HttpServerRequest;
|
|
27
|
+
constructor(init: RequestHost.Initiator);
|
|
28
|
+
switchToHttp(): HttpServerRequest;
|
|
25
29
|
switchToWs(): never;
|
|
26
30
|
switchToRpc(): never;
|
|
27
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpServerResponse } from './http/impl/http-server-response.js';
|
|
2
2
|
import { Response } from './interfaces/response.interface.js';
|
|
3
3
|
export declare namespace ResponseHost {
|
|
4
4
|
interface Initiator {
|
|
@@ -6,15 +6,17 @@ export declare namespace ResponseHost {
|
|
|
6
6
|
errors?: Error[];
|
|
7
7
|
continueOnError?: boolean;
|
|
8
8
|
count?: number;
|
|
9
|
+
http?: HttpServerResponse;
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
|
-
export declare
|
|
12
|
+
export declare class ResponseHost implements Response {
|
|
12
13
|
value?: any;
|
|
13
14
|
errors: Error[];
|
|
14
15
|
continueOnError?: boolean;
|
|
15
16
|
count?: number;
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
http?: HttpServerResponse;
|
|
18
|
+
constructor(init: ResponseHost.Initiator);
|
|
19
|
+
switchToHttp(): HttpServerResponse;
|
|
18
20
|
switchToWs(): never;
|
|
19
21
|
switchToRpc(): never;
|
|
20
22
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ export * from './types.js';
|
|
|
4
4
|
export * from './adapter/adapter.js';
|
|
5
5
|
export * from './adapter/http/express-adapter.js';
|
|
6
6
|
export * from './adapter/http/http-adapter.js';
|
|
7
|
-
export * from './adapter/http/http-request
|
|
8
|
-
export * from './adapter/http/http-response
|
|
7
|
+
export * from './adapter/http/impl/http-server-request.js';
|
|
8
|
+
export * from './adapter/http/impl/http-server-response.js';
|
|
9
|
+
export * from './adapter/http/impl/http-incoming-message-host.js';
|
|
10
|
+
export * from './adapter/http/impl/http-outgoing-message-host.js';
|
|
9
11
|
export * from './adapter/interfaces/request-context.interface.js';
|
|
10
12
|
export * from './adapter/interfaces/logger.interface.js';
|
|
11
13
|
export * from './adapter/interfaces/request.interface.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 = tslib_1.__importStar(require("stream"));
|
|
6
|
-
const http_parser_1 = require("@browsery/http-parser");
|
|
7
|
-
const common_1 = require("@opra/common");
|
|
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.Duplex.apply(this);
|
|
22
|
-
this[kHeaders] = new common_1.HttpHeaders(undefined, {
|
|
23
|
-
onChange: () => this._headersChanged = true
|
|
24
|
-
});
|
|
25
|
-
this[kTrailers] = new common_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.Duplex.prototype);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpRequestContextHost = void 0;
|
|
4
|
-
const request_context_host_js_1 = require("../request-context.host.js");
|
|
5
|
-
class HttpRequestContextHost extends request_context_host_js_1.RequestContextHost {
|
|
6
|
-
constructor(platform, api, _request, _response) {
|
|
7
|
-
super('http', platform, api, _request, _response);
|
|
8
|
-
this.platform = platform;
|
|
9
|
-
this.api = api;
|
|
10
|
-
this._request = _request;
|
|
11
|
-
this._response = _response;
|
|
12
|
-
}
|
|
13
|
-
switchToHttp() {
|
|
14
|
-
const obj = {
|
|
15
|
-
request: this._request.switchToHttp(),
|
|
16
|
-
response: this._response.switchToHttp()
|
|
17
|
-
};
|
|
18
|
-
Object.setPrototypeOf(obj, this);
|
|
19
|
-
return obj;
|
|
20
|
-
}
|
|
21
|
-
switchToWs() {
|
|
22
|
-
throw new TypeError('Not executing in an "WebSocket" protocol');
|
|
23
|
-
}
|
|
24
|
-
switchToRpc() {
|
|
25
|
-
throw new TypeError('Not executing in an "RPC" protocol');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.HttpRequestContextHost = HttpRequestContextHost;
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpRequestMessage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const accepts_1 = tslib_1.__importDefault(require("accepts"));
|
|
6
|
-
const type_is_1 = tslib_1.__importDefault(require("type-is"));
|
|
7
|
-
const http_parser_1 = require("@browsery/http-parser");
|
|
8
|
-
const common_1 = require("@opra/common");
|
|
9
|
-
const http_message_host_js_1 = require("./http-message.host.js");
|
|
10
|
-
const HTTP_VERSION_PATTERN = /^(\d)\.(\d)$/;
|
|
11
|
-
var HttpRequestMessage;
|
|
12
|
-
(function (HttpRequestMessage) {
|
|
13
|
-
function create(init) {
|
|
14
|
-
return HttpRequestMessageHost.create(init);
|
|
15
|
-
}
|
|
16
|
-
HttpRequestMessage.create = create;
|
|
17
|
-
function fromBuffer(buffer) {
|
|
18
|
-
return HttpRequestMessageHost.fromBuffer(buffer);
|
|
19
|
-
}
|
|
20
|
-
HttpRequestMessage.fromBuffer = fromBuffer;
|
|
21
|
-
async function fromStream(readable) {
|
|
22
|
-
return HttpRequestMessageHost.fromStream(readable);
|
|
23
|
-
}
|
|
24
|
-
HttpRequestMessage.fromStream = fromStream;
|
|
25
|
-
})(HttpRequestMessage || (exports.HttpRequestMessage = HttpRequestMessage = {}));
|
|
26
|
-
const kQuery = Symbol('kQuery');
|
|
27
|
-
const kQueryProxy = Symbol('kQueryProxy');
|
|
28
|
-
const kProtocol = Symbol('kProtocol');
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
class HttpRequestMessageHost extends http_message_host_js_1.HttpMessageHost {
|
|
33
|
-
constructor() {
|
|
34
|
-
super();
|
|
35
|
-
this.httpVersionMajor = 1;
|
|
36
|
-
this.httpVersionMinor = 0;
|
|
37
|
-
this[kQuery] = new common_1.HttpParams();
|
|
38
|
-
this[kQueryProxy] = this[kQuery].getProxy();
|
|
39
|
-
}
|
|
40
|
-
get httpVersion() {
|
|
41
|
-
return this.httpVersionMajor + '.' + this.httpVersionMinor;
|
|
42
|
-
}
|
|
43
|
-
set httpVersion(value) {
|
|
44
|
-
const m = HTTP_VERSION_PATTERN.exec(value);
|
|
45
|
-
if (!m)
|
|
46
|
-
throw new TypeError(`Invalid http version string (${value})`);
|
|
47
|
-
this.httpVersionMajor = parseInt(m[1], 10);
|
|
48
|
-
this.httpVersionMinor = parseInt(m[2], 10);
|
|
49
|
-
}
|
|
50
|
-
get hostname() {
|
|
51
|
-
let host = this.get('X-Forwarded-Host') || this.get('Host');
|
|
52
|
-
if (host && host.indexOf(',') !== -1) {
|
|
53
|
-
// Note: X-Forwarded-Host is normally only ever a single value, but this is to be safe.
|
|
54
|
-
host = host.substring(0, host.indexOf(',')).trimEnd();
|
|
55
|
-
}
|
|
56
|
-
if (!host)
|
|
57
|
-
return '';
|
|
58
|
-
// IPv6 literal support
|
|
59
|
-
const offset = host[0] === '['
|
|
60
|
-
? host.indexOf(']') + 1
|
|
61
|
-
: 0;
|
|
62
|
-
const index = host.indexOf(':', offset);
|
|
63
|
-
return index !== -1
|
|
64
|
-
? host.substring(0, index)
|
|
65
|
-
: host;
|
|
66
|
-
}
|
|
67
|
-
get protocol() {
|
|
68
|
-
if (this[kProtocol])
|
|
69
|
-
return this[kProtocol];
|
|
70
|
-
// Note: X-Forwarded-Proto is normally only ever a
|
|
71
|
-
// single value, but this is to be safe.
|
|
72
|
-
const header = this.get('X-Forwarded-Proto');
|
|
73
|
-
if (header) {
|
|
74
|
-
const index = header.indexOf(',');
|
|
75
|
-
return index !== -1
|
|
76
|
-
? header.substring(0, index).trim()
|
|
77
|
-
: header.trim();
|
|
78
|
-
}
|
|
79
|
-
return 'http';
|
|
80
|
-
}
|
|
81
|
-
set protocol(v) {
|
|
82
|
-
this[kProtocol] = v;
|
|
83
|
-
}
|
|
84
|
-
get secure() {
|
|
85
|
-
return this.protocol === 'https';
|
|
86
|
-
}
|
|
87
|
-
get query() {
|
|
88
|
-
return this[kQueryProxy];
|
|
89
|
-
}
|
|
90
|
-
set query(value) {
|
|
91
|
-
this[kQuery].clear();
|
|
92
|
-
this[kQuery].appendAll(value);
|
|
93
|
-
}
|
|
94
|
-
header(name) {
|
|
95
|
-
return this.getHeader(name);
|
|
96
|
-
}
|
|
97
|
-
accepts(...type) {
|
|
98
|
-
const accept = (0, accepts_1.default)(this);
|
|
99
|
-
// eslint-disable-next-line prefer-spread
|
|
100
|
-
return accept.types.apply(accept, type);
|
|
101
|
-
}
|
|
102
|
-
acceptsCharsets(...charset) {
|
|
103
|
-
const accept = (0, accepts_1.default)(this);
|
|
104
|
-
// eslint-disable-next-line prefer-spread
|
|
105
|
-
return accept.charsets.apply(accept, charset);
|
|
106
|
-
}
|
|
107
|
-
acceptsEncodings(...encoding) {
|
|
108
|
-
const accept = (0, accepts_1.default)(this);
|
|
109
|
-
// eslint-disable-next-line prefer-spread
|
|
110
|
-
return accept.encodings.apply(accept, encoding);
|
|
111
|
-
}
|
|
112
|
-
acceptsLanguages(...lang) {
|
|
113
|
-
const accept = (0, accepts_1.default)(this);
|
|
114
|
-
// eslint-disable-next-line prefer-spread
|
|
115
|
-
return accept.languages.apply(accept, lang);
|
|
116
|
-
}
|
|
117
|
-
is(type, ...otherTypes) {
|
|
118
|
-
const types = Array.isArray(type) ? type : [type];
|
|
119
|
-
if (otherTypes.length)
|
|
120
|
-
types.push(...otherTypes);
|
|
121
|
-
const contentType = this.getHeader('content-type');
|
|
122
|
-
return contentType ? type_is_1.default.is(contentType, types) : null;
|
|
123
|
-
}
|
|
124
|
-
_init(init) {
|
|
125
|
-
super._init(init);
|
|
126
|
-
this.method = init.method.toUpperCase();
|
|
127
|
-
this.url = init.url;
|
|
128
|
-
this.baseUrl = init.baseUrl || this.url;
|
|
129
|
-
this.protocol = init.protocol;
|
|
130
|
-
}
|
|
131
|
-
[http_message_host_js_1.HttpMessageHost.kOnHeaderReceived](info) {
|
|
132
|
-
super[http_message_host_js_1.HttpMessageHost.kOnHeaderReceived](info);
|
|
133
|
-
this.method = http_parser_1.HTTPParser.methods[info.method];
|
|
134
|
-
this.url = info.url;
|
|
135
|
-
this.baseUrl = info.url;
|
|
136
|
-
}
|
|
137
|
-
static create(init) {
|
|
138
|
-
const msg = new HttpRequestMessageHost();
|
|
139
|
-
msg._init(init);
|
|
140
|
-
return msg;
|
|
141
|
-
}
|
|
142
|
-
static fromBuffer(buffer) {
|
|
143
|
-
const msg = new HttpRequestMessageHost();
|
|
144
|
-
msg._parseBuffer(buffer, http_parser_1.HTTPParser.REQUEST);
|
|
145
|
-
return msg;
|
|
146
|
-
}
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
148
|
-
static async fromStream(readable) {
|
|
149
|
-
throw new Error('fromStream is not implemented yet');
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
HttpRequestMessageHost.kQuery = kQuery;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpRequestHost = void 0;
|
|
4
|
-
const request_host_js_1 = require("../request.host.js");
|
|
5
|
-
class HttpRequestHost extends request_host_js_1.RequestHost {
|
|
6
|
-
constructor(init, _incoming) {
|
|
7
|
-
super(init);
|
|
8
|
-
this._incoming = _incoming;
|
|
9
|
-
}
|
|
10
|
-
switchToHttp() {
|
|
11
|
-
return this._incoming;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.HttpRequestHost = HttpRequestHost;
|