@opra/core 0.20.3 → 0.21.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 +76 -438
- 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 +77 -439
- 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 +20 -16
- 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,9 +1,10 @@
|
|
|
1
|
+
import { Task } from 'power-tasks';
|
|
1
2
|
import { OpraAdapter } from '../adapter.js';
|
|
2
3
|
import { ILogger } from '../interfaces/logger.interface.js';
|
|
3
4
|
import { Request } from '../interfaces/request.interface.js';
|
|
4
5
|
import { RequestContext } from '../interfaces/request-context.interface.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { HttpServerRequest } from './impl/http-server-request.js';
|
|
7
|
+
import { HttpServerResponse } from './impl/http-server-response.js';
|
|
7
8
|
/**
|
|
8
9
|
* @namespace OpraHttpAdapter
|
|
9
10
|
*/
|
|
@@ -24,15 +25,9 @@ export declare abstract class OpraHttpAdapter extends OpraAdapter {
|
|
|
24
25
|
* @param outgoing
|
|
25
26
|
* @protected
|
|
26
27
|
*/
|
|
27
|
-
protected handler(incoming:
|
|
28
|
-
protected
|
|
29
|
-
protected log(logType: keyof ILogger, incoming: HttpRequestMessage, message: string, ...optionalParams: any[]): void;
|
|
28
|
+
protected handler(incoming: HttpServerRequest, outgoing: HttpServerResponse): Promise<void>;
|
|
29
|
+
protected createRequestTask(request: Request, outgoing: HttpServerResponse): Task;
|
|
30
30
|
protected executeRequest(context: RequestContext): Promise<void>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @param incoming
|
|
34
|
-
* @protected
|
|
35
|
-
*/
|
|
36
|
-
protected parseRequest(incoming: HttpRequestMessage): Promise<Request>;
|
|
37
|
-
protected sendResponse(context: RequestContext): Promise<void>;
|
|
31
|
+
protected handleError(incoming: HttpServerRequest, outgoing: HttpServerResponse, errors: any[]): Promise<void>;
|
|
32
|
+
protected log(logType: keyof ILogger, incoming: HttpServerRequest, message: string, ...optionalParams: any[]): void;
|
|
38
33
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import http, { IncomingHttpHeaders } from 'http';
|
|
6
|
+
import * as stream from 'stream';
|
|
7
|
+
import { Readable } from 'stream';
|
|
8
|
+
export declare const CRLF: Buffer;
|
|
9
|
+
export declare const kHeaders: unique symbol;
|
|
10
|
+
export declare const kHeadersDistinct: unique symbol;
|
|
11
|
+
export declare const kTrailers: unique symbol;
|
|
12
|
+
export declare const kTrailersDistinct: unique symbol;
|
|
13
|
+
export interface HttpIncomingMessage extends Pick<http.IncomingMessage, 'httpVersion' | 'httpVersionMajor' | 'httpVersionMinor' | 'complete' | 'headers' | 'trailers' | 'rawHeaders' | 'rawTrailers' | 'method' | 'url'>, stream.Readable {
|
|
14
|
+
}
|
|
15
|
+
export declare namespace HttpIncomingMessageHost {
|
|
16
|
+
interface Initiator {
|
|
17
|
+
httpVersionMajor?: number;
|
|
18
|
+
httpVersionMinor?: number;
|
|
19
|
+
method?: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
headers?: Record<string, any> | string[];
|
|
22
|
+
trailers?: Record<string, any> | string[];
|
|
23
|
+
body?: any;
|
|
24
|
+
ip?: string;
|
|
25
|
+
ips?: string[];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export interface HttpIncomingMessageHost extends stream.Readable {
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @class HttpIncomingMessageHost
|
|
33
|
+
*/
|
|
34
|
+
export declare class HttpIncomingMessageHost implements HttpIncomingMessage {
|
|
35
|
+
httpVersionMajor: number;
|
|
36
|
+
httpVersionMinor: number;
|
|
37
|
+
method: string;
|
|
38
|
+
url: string;
|
|
39
|
+
rawHeaders: string[];
|
|
40
|
+
rawTrailers: string[];
|
|
41
|
+
body?: any;
|
|
42
|
+
complete: boolean;
|
|
43
|
+
ip?: string;
|
|
44
|
+
ips?: string[];
|
|
45
|
+
joinDuplicateHeaders: boolean;
|
|
46
|
+
constructor();
|
|
47
|
+
get httpVersion(): string;
|
|
48
|
+
get headers(): IncomingHttpHeaders;
|
|
49
|
+
set headers(headers: IncomingHttpHeaders);
|
|
50
|
+
get headersDistinct(): NodeJS.Dict<string[]>;
|
|
51
|
+
get trailers(): NodeJS.Dict<string>;
|
|
52
|
+
set trailers(trailers: NodeJS.Dict<string>);
|
|
53
|
+
get trailersDistinct(): NodeJS.Dict<string[]>;
|
|
54
|
+
protected _readConfig(init: HttpIncomingMessageHost.Initiator): void;
|
|
55
|
+
protected _readBuffer(buf: Buffer | ArrayBuffer): void;
|
|
56
|
+
_readStream(readable: Readable): void;
|
|
57
|
+
static create(init?: HttpIncomingMessageHost.Initiator | Buffer | stream.Readable): HttpIncomingMessageHost;
|
|
58
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import http, { OutgoingHttpHeaders } from 'http';
|
|
5
|
+
import * as stream from 'stream';
|
|
6
|
+
import type { HttpIncomingMessage } from './http-incoming-message-host.js';
|
|
7
|
+
export declare const kOutHeaders: unique symbol;
|
|
8
|
+
export declare const kOutTrailers: unique symbol;
|
|
9
|
+
export declare const kErrored: unique symbol;
|
|
10
|
+
declare global {
|
|
11
|
+
interface Headers {
|
|
12
|
+
keys(): IterableIterator<string>;
|
|
13
|
+
entries(): IterableIterator<[string, any]>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export interface HttpOutgoingMessage extends Pick<http.ServerResponse, 'addTrailers' | 'getHeader' | 'getHeaders' | 'getHeaderNames' | 'removeHeader' | 'hasHeader' | 'headersSent' | 'statusCode' | 'statusMessage' | 'sendDate'>, stream.Writable {
|
|
17
|
+
req?: HttpIncomingMessage;
|
|
18
|
+
appendHeader(name: string, value: string | readonly string[]): this;
|
|
19
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
20
|
+
}
|
|
21
|
+
export declare namespace HttpOutgoingMessageHost {
|
|
22
|
+
interface Initiator {
|
|
23
|
+
req?: HttpIncomingMessage;
|
|
24
|
+
statusCode?: number;
|
|
25
|
+
statusMessage?: string;
|
|
26
|
+
headers?: OutgoingHttpHeaders | Headers | Map<string, any> | string[];
|
|
27
|
+
chunkedEncoding?: boolean;
|
|
28
|
+
sendDate?: boolean;
|
|
29
|
+
strictContentLength?: boolean;
|
|
30
|
+
body?: any;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export interface HttpOutgoingMessageHost extends stream.Writable {
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @class HttpOutgoingMessageHost
|
|
38
|
+
*/
|
|
39
|
+
export declare class HttpOutgoingMessageHost {
|
|
40
|
+
protected _headersSent: boolean;
|
|
41
|
+
protected _closed: boolean;
|
|
42
|
+
protected [kErrored]: Error | null;
|
|
43
|
+
protected [kOutHeaders]: Record<string, any>;
|
|
44
|
+
protected [kOutTrailers]: Record<string, any>;
|
|
45
|
+
finished: boolean;
|
|
46
|
+
req?: HttpIncomingMessage;
|
|
47
|
+
statusCode: number;
|
|
48
|
+
statusMessage: string;
|
|
49
|
+
chunkedEncoding: boolean;
|
|
50
|
+
sendDate: boolean;
|
|
51
|
+
strictContentLength: boolean;
|
|
52
|
+
body?: any;
|
|
53
|
+
constructor();
|
|
54
|
+
get headersSent(): boolean;
|
|
55
|
+
get closed(): boolean;
|
|
56
|
+
get errored(): Error | null;
|
|
57
|
+
appendHeader(name: string, value: number | string | readonly string[]): this;
|
|
58
|
+
addTrailers(headers: OutgoingHttpHeaders | [string, string][] | readonly [string, string][]): void;
|
|
59
|
+
setHeader(name: any, value: any): this;
|
|
60
|
+
setHeaders(headers: Headers | Map<string, any> | Record<string, any>): this;
|
|
61
|
+
getHeader(name: string): any;
|
|
62
|
+
getHeaderNames(): string[];
|
|
63
|
+
getRawHeaderNames(): any[];
|
|
64
|
+
getHeaders(): OutgoingHttpHeaders;
|
|
65
|
+
hasHeader(name: string): boolean;
|
|
66
|
+
removeHeader(name: string): void;
|
|
67
|
+
end(cb?: () => void): this;
|
|
68
|
+
end(chunk: any, cb?: () => void): this;
|
|
69
|
+
end(chunk: any, encoding: BufferEncoding, cb?: () => void): this;
|
|
70
|
+
protected _readConfig(init: HttpOutgoingMessageHost.Initiator): void;
|
|
71
|
+
static create(init?: HttpOutgoingMessageHost.Initiator): HttpOutgoingMessageHost;
|
|
72
|
+
}
|
|
@@ -1,88 +1,71 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { Options as RangeParserOptions, Ranges as RangeParserRanges, Result as RangeParserResult } from 'range-parser';
|
|
4
|
+
import stream from 'stream';
|
|
5
|
+
import { HttpIncomingMessage, HttpIncomingMessageHost } from './http-incoming-message-host.js';
|
|
6
|
+
import type { HttpServerResponse } from './http-server-response.js';
|
|
7
|
+
export declare namespace HttpServerRequest {
|
|
8
|
+
function create(instance?: HttpIncomingMessage | HttpIncomingMessageHost.Initiator | Buffer | stream.Readable): HttpServerRequest;
|
|
9
|
+
}
|
|
10
|
+
export interface HttpServerRequest extends HttpIncomingMessage {
|
|
11
|
+
res: HttpServerResponse;
|
|
12
|
+
body?: any;
|
|
9
13
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* Also `message.httpVersionMajor` is the first integer and`message.httpVersionMinor` is the second.
|
|
15
|
-
* @since v0.1.1
|
|
14
|
+
* Return the protocol string "http" or "https"
|
|
15
|
+
* When the "X-Forwarded-Proto" header field will be trusted
|
|
16
|
+
* and used if present.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
httpVersionMajor: number;
|
|
19
|
-
httpVersionMinor: number;
|
|
18
|
+
protocol: string;
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
20
|
+
* Return the remote address from the trusted proxy.
|
|
22
21
|
*
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
readonly headers: IncomingHttpHeaders;
|
|
26
|
-
/**
|
|
27
|
-
* The raw request/response headers list exactly as they were received.
|
|
28
|
-
*/
|
|
29
|
-
rawHeaders: string[];
|
|
30
|
-
/**
|
|
31
|
-
* The request/response trailers object.
|
|
22
|
+
* This is the remote address on the socket unless "trust proxy" is set.
|
|
32
23
|
*/
|
|
33
|
-
|
|
24
|
+
ip: string;
|
|
34
25
|
/**
|
|
35
|
-
*
|
|
26
|
+
* When "trust proxy" is set, trusted proxy addresses + client.
|
|
27
|
+
*
|
|
28
|
+
* For example if the value were "client, proxy1, proxy2"
|
|
29
|
+
* you would receive the array `["client", "proxy1", "proxy2"]`
|
|
30
|
+
* where "proxy2" is the furthest down-stream and "proxy1" and
|
|
31
|
+
* "proxy2" were trusted.
|
|
36
32
|
*/
|
|
37
|
-
|
|
38
|
-
readonly complete: boolean;
|
|
39
|
-
readonly upgrade?: any;
|
|
33
|
+
ips: string[];
|
|
40
34
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* setting is enabled the "X-Forwarded-Proto" header
|
|
44
|
-
* field will be trusted. If you're running behind
|
|
45
|
-
* a reverse proxy that supplies https for you this
|
|
46
|
-
* may be enabled.
|
|
35
|
+
* Short-hand for:
|
|
36
|
+
* req.protocol === 'https'
|
|
47
37
|
*/
|
|
48
|
-
|
|
38
|
+
secure: boolean;
|
|
49
39
|
/**
|
|
50
|
-
*
|
|
40
|
+
* Parse the "Host" header field to a hostname.
|
|
51
41
|
*
|
|
52
|
-
*
|
|
42
|
+
* When the "trust proxy" setting trusts the socket
|
|
43
|
+
* address, the "X-Forwarded-Host" header field will
|
|
44
|
+
* be trusted.
|
|
53
45
|
*/
|
|
54
|
-
|
|
46
|
+
hostname?: string;
|
|
55
47
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* the upstream addr.
|
|
48
|
+
* Check if the request is fresh, aka
|
|
49
|
+
* Last-Modified and/or the ETag still match.
|
|
59
50
|
*/
|
|
60
|
-
|
|
51
|
+
fresh: boolean;
|
|
61
52
|
/**
|
|
62
|
-
*
|
|
63
|
-
* the "X-Forwarded-For" ip address list.
|
|
53
|
+
* Check if the request was an _XMLHttpRequest_.
|
|
64
54
|
*
|
|
65
|
-
* For example if the value were "client, proxy1, proxy2"
|
|
66
|
-
* you would receive the array `["client", "proxy1", "proxy2"]`
|
|
67
|
-
* where "proxy2" is the furthest down-stream.
|
|
68
55
|
*/
|
|
69
|
-
|
|
56
|
+
xhr: boolean;
|
|
70
57
|
/**
|
|
71
|
-
*
|
|
58
|
+
* Secret value for cookie encryption
|
|
59
|
+
*
|
|
72
60
|
*/
|
|
73
|
-
|
|
74
|
-
method: string;
|
|
75
|
-
url: string;
|
|
76
|
-
baseUrl: string;
|
|
77
|
-
query: Record<string, any>;
|
|
61
|
+
secret?: string;
|
|
78
62
|
/**
|
|
79
63
|
* Return request header.
|
|
80
64
|
*
|
|
81
65
|
* The `Referrer` header field is special-cased,
|
|
82
66
|
* both `Referrer` and `Referer` are interchangeable.
|
|
83
67
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
68
|
+
* @example
|
|
86
69
|
* req.get('Content-Type');
|
|
87
70
|
* // => "text/plain"
|
|
88
71
|
*
|
|
@@ -92,12 +75,11 @@ export interface HttpRequestMessage extends HttpMessage {
|
|
|
92
75
|
* req.get('Something');
|
|
93
76
|
* // => undefined
|
|
94
77
|
*
|
|
95
|
-
* Aliased as `req.header()`.
|
|
96
78
|
*/
|
|
97
|
-
get(name: 'set-cookie'): string[] | undefined;
|
|
98
|
-
get(name: string): string | undefined;
|
|
99
79
|
header(name: 'set-cookie'): string[] | undefined;
|
|
100
80
|
header(name: string): string | undefined;
|
|
81
|
+
get(name: 'set-cookie'): string[] | undefined;
|
|
82
|
+
get(name: string): string | undefined;
|
|
101
83
|
/**
|
|
102
84
|
* Check if the given `type(s)` is acceptable, returning
|
|
103
85
|
* the best match when true, otherwise `undefined`, in which
|
|
@@ -105,12 +87,11 @@ export interface HttpRequestMessage extends HttpMessage {
|
|
|
105
87
|
*
|
|
106
88
|
* The `type` value may be a single mime type string
|
|
107
89
|
* such as "application/json", the extension name
|
|
108
|
-
* such as "json", a comma-
|
|
90
|
+
* such as "json", a comma-delimited list such as "json, html, text/plain",
|
|
109
91
|
* or an array `["json", "html", "text/plain"]`. When a list
|
|
110
92
|
* or array is given the _best_ match, if any is returned.
|
|
111
93
|
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
94
|
+
* @example
|
|
114
95
|
* // Accept: text/html
|
|
115
96
|
* req.accepts('html');
|
|
116
97
|
* // => "html"
|
|
@@ -147,8 +128,7 @@ export interface HttpRequestMessage extends HttpMessage {
|
|
|
147
128
|
* For more information, or if you have issues or concerns, see accepts.
|
|
148
129
|
*/
|
|
149
130
|
acceptsCharsets(): string[];
|
|
150
|
-
acceptsCharsets(
|
|
151
|
-
acceptsCharsets(charset: string[]): string | false;
|
|
131
|
+
acceptsCharsets(charsets: string[]): string | false;
|
|
152
132
|
acceptsCharsets(...charset: string[]): string | false;
|
|
153
133
|
/**
|
|
154
134
|
* Returns the first accepted encoding of the specified encodings,
|
|
@@ -158,8 +138,7 @@ export interface HttpRequestMessage extends HttpMessage {
|
|
|
158
138
|
* For more information, or if you have issues or concerns, see accepts.
|
|
159
139
|
*/
|
|
160
140
|
acceptsEncodings(): string[];
|
|
161
|
-
acceptsEncodings(
|
|
162
|
-
acceptsEncodings(encoding: string[]): string | false;
|
|
141
|
+
acceptsEncodings(encodings: string[]): string | false;
|
|
163
142
|
acceptsEncodings(...encoding: string[]): string | false;
|
|
164
143
|
/**
|
|
165
144
|
* Returns the first accepted language of the specified languages,
|
|
@@ -176,8 +155,7 @@ export interface HttpRequestMessage extends HttpMessage {
|
|
|
176
155
|
* Check if the incoming request contains the "Content-Type"
|
|
177
156
|
* header field, and it contains the give mime `type`.
|
|
178
157
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
158
|
+
* @example
|
|
181
159
|
* // With Content-Type: text/html; charset=utf-8
|
|
182
160
|
* req.is('html');
|
|
183
161
|
* req.is('text/html');
|
|
@@ -195,19 +173,8 @@ export interface HttpRequestMessage extends HttpMessage {
|
|
|
195
173
|
*/
|
|
196
174
|
is(type: string | string[]): string | false | null;
|
|
197
175
|
is(...types: string[]): string | false | null;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
httpVersionMinor?: number;
|
|
203
|
-
method: string;
|
|
204
|
-
url: string;
|
|
205
|
-
protocol?: string;
|
|
206
|
-
baseUrl?: string;
|
|
207
|
-
ip?: string;
|
|
208
|
-
ips?: [];
|
|
209
|
-
}
|
|
210
|
-
function create(init: Initiator): HttpRequestMessage;
|
|
211
|
-
function fromBuffer(buffer: Buffer | ArrayBuffer): HttpRequestMessage;
|
|
212
|
-
function fromStream(readable: Readable): Promise<HttpRequestMessage>;
|
|
176
|
+
/**
|
|
177
|
+
* Parse Range header field, capping to the given `size`.
|
|
178
|
+
*/
|
|
179
|
+
range(size: number, options?: RangeParserOptions): RangeParserRanges | RangeParserResult | undefined;
|
|
213
180
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { HttpOutgoingMessage, HttpOutgoingMessageHost } from './http-outgoing-message-host.js';
|
|
2
|
+
import type { HttpServerRequest } from './http-server-request.js';
|
|
3
|
+
export declare namespace HttpServerResponse {
|
|
4
|
+
function create(instance?: HttpOutgoingMessage | HttpOutgoingMessageHost.Initiator): HttpServerResponse;
|
|
5
|
+
}
|
|
6
|
+
export interface HttpServerResponse extends HttpOutgoingMessage {
|
|
7
|
+
req?: HttpServerRequest;
|
|
8
|
+
/**
|
|
9
|
+
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
|
10
|
+
*/
|
|
11
|
+
attachment(this: HttpServerResponse, filename?: string): this;
|
|
12
|
+
/** Clear cookie `name`. */
|
|
13
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
14
|
+
/**
|
|
15
|
+
* Set cookie `name` to `val`, with the given `options`.
|
|
16
|
+
*
|
|
17
|
+
* Options:
|
|
18
|
+
*
|
|
19
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
20
|
+
* - `signed` sign the cookie
|
|
21
|
+
* - `path` defaults to "/"
|
|
22
|
+
*
|
|
23
|
+
* Examples:
|
|
24
|
+
*
|
|
25
|
+
* // "Remember Me" for 15 minutes
|
|
26
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
27
|
+
*
|
|
28
|
+
* // save as above
|
|
29
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
30
|
+
*/
|
|
31
|
+
cookie(name: string, val: string, options: CookieOptions): this;
|
|
32
|
+
cookie(name: string, val: any, options: CookieOptions): this;
|
|
33
|
+
cookie(name: string, val: any): this;
|
|
34
|
+
/**
|
|
35
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
36
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* res.type('.html');
|
|
40
|
+
* res.type('html');
|
|
41
|
+
* res.type('json');
|
|
42
|
+
* res.type('application/json');
|
|
43
|
+
* res.type('png');
|
|
44
|
+
*/
|
|
45
|
+
contentType(type: string): this;
|
|
46
|
+
/**
|
|
47
|
+
* Set Link header field with the given `links`.
|
|
48
|
+
*
|
|
49
|
+
* Examples:
|
|
50
|
+
*
|
|
51
|
+
* res.links({
|
|
52
|
+
* next: 'http://api.example.com/users?page=2',
|
|
53
|
+
* last: 'http://api.example.com/users?page=5'
|
|
54
|
+
* });
|
|
55
|
+
*/
|
|
56
|
+
links(links: Record<string, string>): this;
|
|
57
|
+
/**
|
|
58
|
+
* Set the location header to `url`.
|
|
59
|
+
*
|
|
60
|
+
* The given `url` can also be the name of a mapped url, for
|
|
61
|
+
* example by default express supports "back" which redirects
|
|
62
|
+
* to the _Referrer_ or _Referer_ headers or "/".
|
|
63
|
+
*
|
|
64
|
+
* Examples:
|
|
65
|
+
*
|
|
66
|
+
* res.location('/foo/bar').;
|
|
67
|
+
* res.location('http://example.com');
|
|
68
|
+
* res.location('../login'); // /blog/post/1 -> /blog/login
|
|
69
|
+
*
|
|
70
|
+
* Mounting:
|
|
71
|
+
*
|
|
72
|
+
* When an application is mounted and `res.location()`
|
|
73
|
+
* is given a path that does _not_ lead with "/" it becomes
|
|
74
|
+
* relative to the mount-point. For example if the application
|
|
75
|
+
* is mounted at "/blog", the following would become "/blog/login".
|
|
76
|
+
*
|
|
77
|
+
* res.location('login');
|
|
78
|
+
*
|
|
79
|
+
* While the leading slash would result in a location of "/login":
|
|
80
|
+
*
|
|
81
|
+
* res.location('/login');
|
|
82
|
+
*/
|
|
83
|
+
location(url: string): this;
|
|
84
|
+
/**
|
|
85
|
+
* Redirect to the given `url` with optional response `status`
|
|
86
|
+
* defaulting to 302.
|
|
87
|
+
*
|
|
88
|
+
* The resulting `url` is determined by `res.location()`, so
|
|
89
|
+
* it will play nicely with mounted apps, relative paths,
|
|
90
|
+
* `"back"` etc.
|
|
91
|
+
*
|
|
92
|
+
* Examples:
|
|
93
|
+
*
|
|
94
|
+
* res.redirect('back');
|
|
95
|
+
* res.redirect('/foo/bar');
|
|
96
|
+
* res.redirect('http://example.com');
|
|
97
|
+
* res.redirect(301, 'http://example.com');
|
|
98
|
+
* res.redirect('http://example.com', 301);
|
|
99
|
+
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
|
100
|
+
*/
|
|
101
|
+
redirect(url: string): void;
|
|
102
|
+
redirect(status: number, url: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Set status `code`.
|
|
105
|
+
*/
|
|
106
|
+
status(code: number): this;
|
|
107
|
+
/**
|
|
108
|
+
* Send given HTTP status code.
|
|
109
|
+
*
|
|
110
|
+
* Sets the response status to `statusCode` and the body of the
|
|
111
|
+
* response to the standard description from node's http.STATUS_CODES
|
|
112
|
+
* or the statusCode number if no description.
|
|
113
|
+
*/
|
|
114
|
+
sendStatus(statusCode: number): any;
|
|
115
|
+
/**
|
|
116
|
+
* Send a response.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* res.send(new Buffer('wahoo'));
|
|
120
|
+
* res.send({ some: 'json' });
|
|
121
|
+
* res.send('<p>some html</p>');
|
|
122
|
+
* res.status(404).send('Sorry, cant find that');
|
|
123
|
+
*/
|
|
124
|
+
send(body?: any): this;
|
|
125
|
+
}
|
|
126
|
+
export interface CookieOptions {
|
|
127
|
+
secret?: string;
|
|
128
|
+
maxAge?: number;
|
|
129
|
+
signed?: boolean;
|
|
130
|
+
expires?: Date;
|
|
131
|
+
httpOnly?: boolean;
|
|
132
|
+
path?: string;
|
|
133
|
+
domain?: string;
|
|
134
|
+
secure?: boolean;
|
|
135
|
+
encode?: ((val: string) => string);
|
|
136
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
137
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Collection, OpraURL } from '@opra/common';
|
|
2
|
+
import { Request } from '../../interfaces/request.interface.js';
|
|
3
|
+
import { HttpServerRequest } from '../impl/http-server-request.js';
|
|
4
|
+
export declare function parseCollectionRequest(incoming: HttpServerRequest, resource: Collection, url: OpraURL): Promise<Request>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ApiDocument } from '@opra/common';
|
|
2
|
+
import { Request } from '../../interfaces/request.interface.js';
|
|
3
|
+
import { HttpServerRequest } from '../impl/http-server-request.js';
|
|
4
|
+
export declare function parseRequest(api: ApiDocument, incoming: HttpServerRequest): Promise<Request>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { OpraURL, Singleton } from '@opra/common';
|
|
2
|
+
import { Request } from '../../interfaces/request.interface.js';
|
|
3
|
+
import { HttpServerRequest } from '../impl/http-server-request.js';
|
|
4
|
+
export declare function parseSingletonRequest(incoming: HttpServerRequest, resource: Singleton, url: OpraURL): Promise<Request>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiDocument } from '@opra/common';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { HttpServerRequest } from '../http/impl/http-server-request.js';
|
|
3
|
+
import { HttpServerResponse } from '../http/impl/http-server-response.js';
|
|
4
4
|
import { Request } from './request.interface.js';
|
|
5
5
|
import { Response } from './response.interface.js';
|
|
6
6
|
export declare namespace RequestContext {
|
|
@@ -13,15 +13,19 @@ export interface RequestContext {
|
|
|
13
13
|
readonly request: Request;
|
|
14
14
|
readonly response: Response;
|
|
15
15
|
user?: any;
|
|
16
|
-
switchToHttp():
|
|
17
|
-
switchToWs():
|
|
18
|
-
switchToRpc():
|
|
16
|
+
switchToHttp(): HttpMessageContext;
|
|
17
|
+
switchToWs(): WsMessageContext;
|
|
18
|
+
switchToRpc(): RpcMessageContext;
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
21
|
-
readonly
|
|
22
|
-
readonly
|
|
20
|
+
export interface HttpMessageContext {
|
|
21
|
+
readonly platform: string;
|
|
22
|
+
readonly request: HttpServerRequest;
|
|
23
|
+
readonly response: HttpServerResponse;
|
|
24
|
+
switchToContext(): RequestContext;
|
|
23
25
|
}
|
|
24
|
-
export interface
|
|
26
|
+
export interface WsMessageContext {
|
|
27
|
+
switchToContext(): RequestContext;
|
|
25
28
|
}
|
|
26
|
-
export interface
|
|
29
|
+
export interface RpcMessageContext {
|
|
30
|
+
switchToContext(): RequestContext;
|
|
27
31
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { OpraSchema, Resource } from '@opra/common';
|
|
2
|
-
import
|
|
2
|
+
import { HttpServerRequest } from '../http/impl/http-server-request.js';
|
|
3
3
|
export interface Request {
|
|
4
|
+
readonly contentId: string;
|
|
4
5
|
readonly kind: string;
|
|
5
6
|
readonly resource: Resource;
|
|
6
7
|
readonly resourceKind: OpraSchema.Resource.Kind;
|
|
@@ -8,7 +9,7 @@ export interface Request {
|
|
|
8
9
|
readonly crud: 'create' | 'read' | 'update' | 'delete';
|
|
9
10
|
readonly many: boolean;
|
|
10
11
|
readonly args: any;
|
|
11
|
-
switchToHttp():
|
|
12
|
+
switchToHttp(): HttpServerRequest;
|
|
12
13
|
switchToWs(): never;
|
|
13
14
|
switchToRpc(): never;
|
|
14
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { HttpServerResponse } from '../http/impl/http-server-response.js';
|
|
2
2
|
export interface Response {
|
|
3
3
|
/**
|
|
4
4
|
* Result value
|
|
@@ -16,7 +16,7 @@ export interface Response {
|
|
|
16
16
|
* Total count of matched entities. (Used in "search" operation with "count" option
|
|
17
17
|
*/
|
|
18
18
|
count?: number;
|
|
19
|
-
switchToHttp():
|
|
19
|
+
switchToHttp(): HttpServerResponse;
|
|
20
20
|
switchToWs(): never;
|
|
21
21
|
switchToRpc(): never;
|
|
22
22
|
}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { AsyncEventEmitter } from 'strict-typed-events';
|
|
2
2
|
import { ApiDocument } from '@opra/common';
|
|
3
3
|
import { Request } from './interfaces/request.interface.js';
|
|
4
|
-
import {
|
|
4
|
+
import { HttpMessageContext, RequestContext, RpcMessageContext, WsMessageContext } from './interfaces/request-context.interface.js';
|
|
5
5
|
import { Response } from './interfaces/response.interface.js';
|
|
6
|
-
export declare
|
|
6
|
+
export declare class RequestContextHost extends AsyncEventEmitter implements RequestContext {
|
|
7
7
|
readonly protocol: RequestContext.Protocol;
|
|
8
8
|
readonly platform: string;
|
|
9
9
|
readonly api: ApiDocument;
|
|
10
10
|
protected _request: Request;
|
|
11
11
|
protected _response: Response;
|
|
12
12
|
user?: any;
|
|
13
|
-
protected
|
|
13
|
+
protected _http?: HttpMessageContext;
|
|
14
|
+
protected _ws?: WsMessageContext;
|
|
15
|
+
protected _rpc?: RpcMessageContext;
|
|
16
|
+
constructor(protocol: RequestContext.Protocol, platform: string, api: ApiDocument, _request: Request, _response: Response);
|
|
14
17
|
get request(): Request;
|
|
15
18
|
get response(): Response;
|
|
16
|
-
switchToHttp():
|
|
17
|
-
switchToWs():
|
|
18
|
-
switchToRpc():
|
|
19
|
+
switchToHttp(): HttpMessageContext;
|
|
20
|
+
switchToWs(): WsMessageContext;
|
|
21
|
+
switchToRpc(): RpcMessageContext;
|
|
19
22
|
}
|