@opra/core 0.18.4 → 0.20.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/http/http-message.host.js +251 -0
- package/cjs/adapter/http/http-request-message.js +152 -0
- package/cjs/adapter/http/http-response-message.js +238 -0
- package/cjs/adapter/internal/metadata.resource.js +2 -3
- package/cjs/index.js +2 -0
- package/esm/adapter/http/http-message.host.js +246 -0
- package/esm/adapter/http/http-request-message.js +148 -0
- package/esm/adapter/http/http-response-message.js +233 -0
- package/esm/adapter/internal/metadata.resource.js +1 -2
- package/esm/index.js +2 -0
- package/package.json +17 -5
- package/types/adapter/http/http-adapter.d.ts +2 -1
- package/types/adapter/http/http-message.host.d.ts +122 -0
- package/types/adapter/http/http-request-message.d.ts +213 -0
- package/types/adapter/http/http-request.host.d.ts +1 -1
- package/types/adapter/http/http-response-message.d.ts +321 -0
- package/types/adapter/http/http-response.host.d.ts +1 -1
- package/types/adapter/interfaces/request-context.interface.d.ts +3 -1
- package/types/adapter/interfaces/request.interface.d.ts +2 -1
- package/types/adapter/interfaces/response.interface.d.ts +1 -1
- package/types/adapter/request.host.d.ts +2 -1
- package/types/adapter/response.host.d.ts +1 -1
- package/types/index.d.ts +2 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { HttpRequestMessage, HttpResponseMessage } from '@opra/common';
|
|
2
1
|
import { OpraAdapter } from '../adapter.js';
|
|
3
2
|
import { ILogger } from '../interfaces/logger.interface.js';
|
|
4
3
|
import { Request } from '../interfaces/request.interface.js';
|
|
5
4
|
import { RequestContext } from '../interfaces/request-context.interface.js';
|
|
5
|
+
import { HttpRequestMessage } from './http-request-message.js';
|
|
6
|
+
import { HttpResponseMessage } from './http-response-message.js';
|
|
6
7
|
/**
|
|
7
8
|
* @namespace OpraHttpAdapter
|
|
8
9
|
*/
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import * as stream from 'stream';
|
|
4
|
+
import { HeaderInfo, ParserType } from '@browsery/http-parser';
|
|
5
|
+
import { HttpHeaders } from '@opra/common';
|
|
6
|
+
declare const kHeaders: unique symbol;
|
|
7
|
+
declare const kHeadersProxy: unique symbol;
|
|
8
|
+
declare const kTrailers: unique symbol;
|
|
9
|
+
declare const kTrailersProxy: unique symbol;
|
|
10
|
+
declare const kOnHeaderReceived: unique symbol;
|
|
11
|
+
declare const kOnTrailersReceived: unique symbol;
|
|
12
|
+
declare const kOnBodyChunk: unique symbol;
|
|
13
|
+
declare const kOnReadComplete: unique symbol;
|
|
14
|
+
export interface HttpMessage {
|
|
15
|
+
httpVersion?: string;
|
|
16
|
+
httpVersionMajor?: number;
|
|
17
|
+
httpVersionMinor?: number;
|
|
18
|
+
headers?: any;
|
|
19
|
+
trailers?: any;
|
|
20
|
+
rawHeaders?: string[];
|
|
21
|
+
rawTrailers?: string[];
|
|
22
|
+
body?: any;
|
|
23
|
+
complete?: boolean;
|
|
24
|
+
upgrade?: boolean;
|
|
25
|
+
end(body?: any): this;
|
|
26
|
+
send(body: any): this;
|
|
27
|
+
}
|
|
28
|
+
export declare namespace HttpMessage {
|
|
29
|
+
interface Initiator {
|
|
30
|
+
httpVersionMajor?: number;
|
|
31
|
+
httpVersionMinor?: number;
|
|
32
|
+
headers?: HttpHeaders.Initiator;
|
|
33
|
+
trailers?: HttpHeaders.Initiator;
|
|
34
|
+
rawHeaders?: string[];
|
|
35
|
+
rawTrailers?: string[];
|
|
36
|
+
body?: any;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export interface HttpMessageHost extends stream.Duplex {
|
|
40
|
+
}
|
|
41
|
+
export declare abstract class HttpMessageHost implements HttpMessage {
|
|
42
|
+
static kHeaders: symbol;
|
|
43
|
+
static kHeadersProxy: symbol;
|
|
44
|
+
static kTrailers: symbol;
|
|
45
|
+
static kTrailersProxy: symbol;
|
|
46
|
+
static kOnHeaderReceived: symbol;
|
|
47
|
+
static kOnTrailersReceived: symbol;
|
|
48
|
+
static kOnBodyChunk: symbol;
|
|
49
|
+
static kOnReadComplete: symbol;
|
|
50
|
+
protected [kHeaders]: HttpHeaders;
|
|
51
|
+
protected [kHeadersProxy]: any;
|
|
52
|
+
protected [kTrailers]: HttpHeaders;
|
|
53
|
+
protected [kTrailersProxy]: any;
|
|
54
|
+
protected _bodyChunks?: Buffer[];
|
|
55
|
+
protected _rawHeaders?: string[];
|
|
56
|
+
protected _rawTrailers?: string[];
|
|
57
|
+
protected _headersChanged?: boolean;
|
|
58
|
+
protected _trailersChanged?: boolean;
|
|
59
|
+
httpVersionMajor?: number;
|
|
60
|
+
httpVersionMinor?: number;
|
|
61
|
+
shouldKeepAlive?: boolean;
|
|
62
|
+
complete: boolean;
|
|
63
|
+
upgrade?: boolean;
|
|
64
|
+
body?: Buffer | ArrayBuffer;
|
|
65
|
+
protected constructor();
|
|
66
|
+
get httpVersion(): string | undefined;
|
|
67
|
+
set httpVersion(value: string | undefined);
|
|
68
|
+
get headers(): any;
|
|
69
|
+
set headers(headers: any);
|
|
70
|
+
get trailers(): any;
|
|
71
|
+
set trailers(trailers: any);
|
|
72
|
+
get rawHeaders(): string[];
|
|
73
|
+
set rawHeaders(headers: string[]);
|
|
74
|
+
get rawTrailers(): string[];
|
|
75
|
+
set rawTrailers(trailers: string[]);
|
|
76
|
+
getHeader(name: 'set-cookie' | 'Set-Cookie'): string[] | undefined;
|
|
77
|
+
getHeader(name: string): string | undefined;
|
|
78
|
+
get(name: 'set-cookie' | 'Set-Cookie'): string[] | undefined;
|
|
79
|
+
get(name: string): string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Set header `field` to `val`,
|
|
82
|
+
* or pass an object of header fields.
|
|
83
|
+
*
|
|
84
|
+
* Examples:
|
|
85
|
+
*
|
|
86
|
+
* msg.setHeader('Foo', ['bar', 'baz']);
|
|
87
|
+
* msg.setHeader('Accept', 'application/json');
|
|
88
|
+
* msg.setHeader({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
setHeader(name: 'set-cookie' | 'Set-Cookie', value: string | string[]): this;
|
|
93
|
+
setHeader(name: string, value: number | string | string[]): this;
|
|
94
|
+
setHeader(headers: HttpHeaders.Initiator): this;
|
|
95
|
+
/**
|
|
96
|
+
* Set header `field` to `val`,
|
|
97
|
+
* or pass an object of header fields.
|
|
98
|
+
* Alias as msg.setHeader()
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
set(name: 'set-cookie' | 'Set-Cookie', value: string | string[]): this;
|
|
102
|
+
set(name: string, value: number | string | string[]): this;
|
|
103
|
+
set(headers: Record<string, number | string | string[]>): this;
|
|
104
|
+
getHeaders(): Record<string, string>;
|
|
105
|
+
getHeaderNames(): string[];
|
|
106
|
+
hasHeader(name: string): boolean;
|
|
107
|
+
removeHeader(name: string): void;
|
|
108
|
+
send(body: any): this;
|
|
109
|
+
end(body?: any): this;
|
|
110
|
+
setTimeout(): this;
|
|
111
|
+
protected _init(args: HttpMessage.Initiator): void;
|
|
112
|
+
protected _parseBuffer(buf: Buffer | ArrayBuffer, parserType: ParserType): void;
|
|
113
|
+
protected _initHeaders(): void;
|
|
114
|
+
protected _initTrailers(): void;
|
|
115
|
+
protected _buildRawHeaders(): void;
|
|
116
|
+
protected _buildRawTrailers(): void;
|
|
117
|
+
protected [kOnHeaderReceived](info: HeaderInfo): void;
|
|
118
|
+
protected [kOnTrailersReceived](trailers: string[]): void;
|
|
119
|
+
protected [kOnBodyChunk](chunk: Buffer, offset: number, length: number): void;
|
|
120
|
+
protected [kOnReadComplete](): void;
|
|
121
|
+
}
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
import { IncomingHttpHeaders } from 'http';
|
|
6
|
+
import { Readable } from 'stream';
|
|
7
|
+
import { HttpMessage } from './http-message.host.js';
|
|
8
|
+
export interface HttpRequestMessage extends HttpMessage {
|
|
9
|
+
/**
|
|
10
|
+
* In case of server request, the HTTP version sent by the client. In the case of
|
|
11
|
+
* client response, the HTTP version of the connected-to server.
|
|
12
|
+
* Probably either `'1.1'` or `'1.0'`.
|
|
13
|
+
*
|
|
14
|
+
* Also `message.httpVersionMajor` is the first integer and`message.httpVersionMinor` is the second.
|
|
15
|
+
* @since v0.1.1
|
|
16
|
+
*/
|
|
17
|
+
httpVersion: string;
|
|
18
|
+
httpVersionMajor: number;
|
|
19
|
+
httpVersionMinor: number;
|
|
20
|
+
/**
|
|
21
|
+
* The request/response headers object.
|
|
22
|
+
*
|
|
23
|
+
* Key-value pairs of header names and values. Header names are lower-cased.
|
|
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.
|
|
32
|
+
*/
|
|
33
|
+
readonly trailers: NodeJS.Dict<string>;
|
|
34
|
+
/**
|
|
35
|
+
* The raw request/response trailer keys and values exactly as they were received.
|
|
36
|
+
*/
|
|
37
|
+
rawTrailers: string[];
|
|
38
|
+
readonly complete: boolean;
|
|
39
|
+
readonly upgrade?: any;
|
|
40
|
+
/**
|
|
41
|
+
* Return the protocol string "http" or "https"
|
|
42
|
+
* when requested with TLS. When the "trust proxy"
|
|
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.
|
|
47
|
+
*/
|
|
48
|
+
protocol: string;
|
|
49
|
+
/**
|
|
50
|
+
* Short-hand for:
|
|
51
|
+
*
|
|
52
|
+
* req.protocol == 'https'
|
|
53
|
+
*/
|
|
54
|
+
secure: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Return the remote address, or when
|
|
57
|
+
* "trust proxy" is `true` return
|
|
58
|
+
* the upstream addr.
|
|
59
|
+
*/
|
|
60
|
+
ip: string;
|
|
61
|
+
/**
|
|
62
|
+
* When "trust proxy" is `true`, parse
|
|
63
|
+
* the "X-Forwarded-For" ip address list.
|
|
64
|
+
*
|
|
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
|
+
*/
|
|
69
|
+
ips: string[];
|
|
70
|
+
/**
|
|
71
|
+
* Parse the "Host" header field hostname.
|
|
72
|
+
*/
|
|
73
|
+
hostname: string;
|
|
74
|
+
method: string;
|
|
75
|
+
url: string;
|
|
76
|
+
baseUrl: string;
|
|
77
|
+
query: Record<string, any>;
|
|
78
|
+
/**
|
|
79
|
+
* Return request header.
|
|
80
|
+
*
|
|
81
|
+
* The `Referrer` header field is special-cased,
|
|
82
|
+
* both `Referrer` and `Referer` are interchangeable.
|
|
83
|
+
*
|
|
84
|
+
* Examples:
|
|
85
|
+
*
|
|
86
|
+
* req.get('Content-Type');
|
|
87
|
+
* // => "text/plain"
|
|
88
|
+
*
|
|
89
|
+
* req.get('content-type');
|
|
90
|
+
* // => "text/plain"
|
|
91
|
+
*
|
|
92
|
+
* req.get('Something');
|
|
93
|
+
* // => undefined
|
|
94
|
+
*
|
|
95
|
+
* Aliased as `req.header()`.
|
|
96
|
+
*/
|
|
97
|
+
get(name: 'set-cookie'): string[] | undefined;
|
|
98
|
+
get(name: string): string | undefined;
|
|
99
|
+
header(name: 'set-cookie'): string[] | undefined;
|
|
100
|
+
header(name: string): string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Check if the given `type(s)` is acceptable, returning
|
|
103
|
+
* the best match when true, otherwise `undefined`, in which
|
|
104
|
+
* case you should respond with 406 "Not Acceptable".
|
|
105
|
+
*
|
|
106
|
+
* The `type` value may be a single mime type string
|
|
107
|
+
* such as "application/json", the extension name
|
|
108
|
+
* such as "json", a comma-delimted list such as "json, html, text/plain",
|
|
109
|
+
* or an array `["json", "html", "text/plain"]`. When a list
|
|
110
|
+
* or array is given the _best_ match, if any is returned.
|
|
111
|
+
*
|
|
112
|
+
* Examples:
|
|
113
|
+
*
|
|
114
|
+
* // Accept: text/html
|
|
115
|
+
* req.accepts('html');
|
|
116
|
+
* // => "html"
|
|
117
|
+
*
|
|
118
|
+
* // Accept: text/*, application/json
|
|
119
|
+
* req.accepts('html');
|
|
120
|
+
* // => "html"
|
|
121
|
+
* req.accepts('text/html');
|
|
122
|
+
* // => "text/html"
|
|
123
|
+
* req.accepts('json, text');
|
|
124
|
+
* // => "json"
|
|
125
|
+
* req.accepts('application/json');
|
|
126
|
+
* // => "application/json"
|
|
127
|
+
*
|
|
128
|
+
* // Accept: text/*, application/json
|
|
129
|
+
* req.accepts('image/png');
|
|
130
|
+
* req.accepts('png');
|
|
131
|
+
* // => undefined
|
|
132
|
+
*
|
|
133
|
+
* // Accept: text/*;q=.5, application/json
|
|
134
|
+
* req.accepts(['html', 'json']);
|
|
135
|
+
* req.accepts('html, json');
|
|
136
|
+
* // => "json"
|
|
137
|
+
*/
|
|
138
|
+
accepts(): string[];
|
|
139
|
+
accepts(type: string): string | false;
|
|
140
|
+
accepts(type: string[]): string | false;
|
|
141
|
+
accepts(...type: string[]): string | false;
|
|
142
|
+
/**
|
|
143
|
+
* Returns the first accepted charset of the specified character sets,
|
|
144
|
+
* based on the request's Accept-Charset HTTP header field.
|
|
145
|
+
* If none of the specified charsets is accepted, returns false.
|
|
146
|
+
*
|
|
147
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
148
|
+
*/
|
|
149
|
+
acceptsCharsets(): string[];
|
|
150
|
+
acceptsCharsets(charset: string): string | false;
|
|
151
|
+
acceptsCharsets(charset: string[]): string | false;
|
|
152
|
+
acceptsCharsets(...charset: string[]): string | false;
|
|
153
|
+
/**
|
|
154
|
+
* Returns the first accepted encoding of the specified encodings,
|
|
155
|
+
* based on the request's Accept-Encoding HTTP header field.
|
|
156
|
+
* If none of the specified encodings is accepted, returns false.
|
|
157
|
+
*
|
|
158
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
159
|
+
*/
|
|
160
|
+
acceptsEncodings(): string[];
|
|
161
|
+
acceptsEncodings(encoding: string): string | false;
|
|
162
|
+
acceptsEncodings(encoding: string[]): string | false;
|
|
163
|
+
acceptsEncodings(...encoding: string[]): string | false;
|
|
164
|
+
/**
|
|
165
|
+
* Returns the first accepted language of the specified languages,
|
|
166
|
+
* based on the request's Accept-Language HTTP header field.
|
|
167
|
+
* If none of the specified languages is accepted, returns false.
|
|
168
|
+
*
|
|
169
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
170
|
+
*/
|
|
171
|
+
acceptsLanguages(): string[];
|
|
172
|
+
acceptsLanguages(lang: string): string | false;
|
|
173
|
+
acceptsLanguages(lang: string[]): string | false;
|
|
174
|
+
acceptsLanguages(...lang: string[]): string | false;
|
|
175
|
+
/**
|
|
176
|
+
* Check if the incoming request contains the "Content-Type"
|
|
177
|
+
* header field, and it contains the give mime `type`.
|
|
178
|
+
*
|
|
179
|
+
* Examples:
|
|
180
|
+
*
|
|
181
|
+
* // With Content-Type: text/html; charset=utf-8
|
|
182
|
+
* req.is('html');
|
|
183
|
+
* req.is('text/html');
|
|
184
|
+
* req.is('text/*');
|
|
185
|
+
* // => true
|
|
186
|
+
*
|
|
187
|
+
* // When Content-Type is application/json
|
|
188
|
+
* req.is('json');
|
|
189
|
+
* req.is('application/json');
|
|
190
|
+
* req.is('application/*');
|
|
191
|
+
* // => true
|
|
192
|
+
*
|
|
193
|
+
* req.is('html');
|
|
194
|
+
* // => false
|
|
195
|
+
*/
|
|
196
|
+
is(type: string | string[]): string | false | null;
|
|
197
|
+
is(...types: string[]): string | false | null;
|
|
198
|
+
}
|
|
199
|
+
export declare namespace HttpRequestMessage {
|
|
200
|
+
interface Initiator extends HttpMessage.Initiator {
|
|
201
|
+
httpVersionMajor?: number;
|
|
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>;
|
|
213
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpRequestMessage } from '@opra/common';
|
|
2
1
|
import { RequestHost } from '../request.host.js';
|
|
2
|
+
import { HttpRequestMessage } from './http-request-message.js';
|
|
3
3
|
export declare class HttpRequestHost extends RequestHost {
|
|
4
4
|
protected _incoming: HttpRequestMessage;
|
|
5
5
|
constructor(init: RequestHost.Initiator, _incoming: HttpRequestMessage);
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import cookie from 'cookie';
|
|
4
|
+
import { Readable } from 'stream';
|
|
5
|
+
import { HttpMessage, HttpMessageHost } from './http-message.host.js';
|
|
6
|
+
import type { HttpRequestMessage } from './http-request-message.js';
|
|
7
|
+
export interface CookieOptions extends cookie.CookieSerializeOptions {
|
|
8
|
+
signed?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface HttpResponseMessage extends HttpMessage {
|
|
11
|
+
method?: string | undefined;
|
|
12
|
+
url?: string | undefined;
|
|
13
|
+
body?: any;
|
|
14
|
+
statusCode?: number;
|
|
15
|
+
statusMessage?: string;
|
|
16
|
+
readonly upgrade?: any;
|
|
17
|
+
/**
|
|
18
|
+
* Return request header.
|
|
19
|
+
*
|
|
20
|
+
* The `Referrer` header field is special-cased,
|
|
21
|
+
* both `Referrer` and `Referer` are interchangeable.
|
|
22
|
+
*
|
|
23
|
+
* Examples:
|
|
24
|
+
*
|
|
25
|
+
* req.get('Content-Type');
|
|
26
|
+
* // => "text/plain"
|
|
27
|
+
*
|
|
28
|
+
* req.get('content-type');
|
|
29
|
+
* // => "text/plain"
|
|
30
|
+
*
|
|
31
|
+
* req.get('Something');
|
|
32
|
+
* // => undefined
|
|
33
|
+
*
|
|
34
|
+
* Aliased as `req.header()`.
|
|
35
|
+
*/
|
|
36
|
+
get(field: string): string | undefined;
|
|
37
|
+
getHeader(name: string): number | string | string[] | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Set header `field` to `val`,
|
|
40
|
+
* or pass an object of header fields.
|
|
41
|
+
*
|
|
42
|
+
* Examples:
|
|
43
|
+
*
|
|
44
|
+
* msg.setHeader('Foo', ['bar', 'baz']);
|
|
45
|
+
* msg.setHeader('Accept', 'application/json');
|
|
46
|
+
* msg.setHeader({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
50
|
+
/**
|
|
51
|
+
* Set status `code`.
|
|
52
|
+
*/
|
|
53
|
+
status(code: number): this;
|
|
54
|
+
/**
|
|
55
|
+
* Set the response HTTP status code to `statusCode` and send its string representation as the response body.
|
|
56
|
+
* @link http://expressjs.com/4x/api.html#res.sendStatus
|
|
57
|
+
*
|
|
58
|
+
* Examples:
|
|
59
|
+
*
|
|
60
|
+
* res.sendStatus(200); // equivalent to res.status(200).send('OK')
|
|
61
|
+
* res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
|
|
62
|
+
* res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
|
|
63
|
+
* res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
|
|
64
|
+
*/
|
|
65
|
+
sendStatus(code: number): this;
|
|
66
|
+
/**
|
|
67
|
+
* Set Link header field with the given `links`.
|
|
68
|
+
*
|
|
69
|
+
* Examples:
|
|
70
|
+
*
|
|
71
|
+
* res.links({
|
|
72
|
+
* next: 'http://api.example.com/users?page=2',
|
|
73
|
+
* last: 'http://api.example.com/users?page=5'
|
|
74
|
+
* });
|
|
75
|
+
*/
|
|
76
|
+
links(links: any): this;
|
|
77
|
+
/**
|
|
78
|
+
* Send JSON response.
|
|
79
|
+
*
|
|
80
|
+
* Examples:
|
|
81
|
+
*
|
|
82
|
+
* res.json(null);
|
|
83
|
+
* res.json({ user: 'tj' });
|
|
84
|
+
* res.status(500).json('oh noes!');
|
|
85
|
+
* res.status(404).json('I dont have that');
|
|
86
|
+
*/
|
|
87
|
+
json(body: any): this;
|
|
88
|
+
/**
|
|
89
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
90
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
91
|
+
*
|
|
92
|
+
* Examples:
|
|
93
|
+
*
|
|
94
|
+
* res.type('.html');
|
|
95
|
+
* res.type('html');
|
|
96
|
+
* res.type('json');
|
|
97
|
+
* res.type('application/json');
|
|
98
|
+
* res.type('png');
|
|
99
|
+
*/
|
|
100
|
+
contentType(type: string): this;
|
|
101
|
+
/**
|
|
102
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
103
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
104
|
+
*
|
|
105
|
+
* Examples:
|
|
106
|
+
*
|
|
107
|
+
* res.type('.html');
|
|
108
|
+
* res.type('html');
|
|
109
|
+
* res.type('json');
|
|
110
|
+
* res.type('application/json');
|
|
111
|
+
* res.type('png');
|
|
112
|
+
*/
|
|
113
|
+
type(type: string): this;
|
|
114
|
+
/**
|
|
115
|
+
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
|
116
|
+
*/
|
|
117
|
+
attachment(filename?: string): this;
|
|
118
|
+
/**
|
|
119
|
+
* Set header `field` to `val`, or pass
|
|
120
|
+
* an object of header fields.
|
|
121
|
+
*
|
|
122
|
+
* Examples:
|
|
123
|
+
*
|
|
124
|
+
* res.set('Foo', ['bar', 'baz']);
|
|
125
|
+
* res.set('Accept', 'application/json');
|
|
126
|
+
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
127
|
+
*
|
|
128
|
+
* Aliased as `res.header()`.
|
|
129
|
+
*/
|
|
130
|
+
set(field: any): this;
|
|
131
|
+
set(field: string, value?: string | string[]): this;
|
|
132
|
+
header(field: any): this;
|
|
133
|
+
header(field: string, value?: string | string[]): this;
|
|
134
|
+
append(field: string, value?: string | string[]): this;
|
|
135
|
+
/** Clear cookie `name`. */
|
|
136
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
137
|
+
/**
|
|
138
|
+
* Set cookie `name` to `val`, with the given `options`.
|
|
139
|
+
*
|
|
140
|
+
* Options:
|
|
141
|
+
*
|
|
142
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
143
|
+
* - `signed` sign the cookie
|
|
144
|
+
* - `path` defaults to "/"
|
|
145
|
+
*
|
|
146
|
+
* Examples:
|
|
147
|
+
*
|
|
148
|
+
* // "Remember Me" for 15 minutes
|
|
149
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
150
|
+
*
|
|
151
|
+
* // save as above
|
|
152
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
153
|
+
*/
|
|
154
|
+
cookie(name: string, val: string, options: CookieOptions): this;
|
|
155
|
+
cookie(name: string, val: any, options: CookieOptions): this;
|
|
156
|
+
cookie(name: string, val: any): this;
|
|
157
|
+
/**
|
|
158
|
+
* Set the location header to `url`.
|
|
159
|
+
*
|
|
160
|
+
* The given `url` can also be the name of a mapped url, for
|
|
161
|
+
* example by default express supports "back" which redirects
|
|
162
|
+
* to the _Referrer_ or _Referer_ headers or "/".
|
|
163
|
+
*
|
|
164
|
+
* Examples:
|
|
165
|
+
*
|
|
166
|
+
* res.location('/foo/bar').;
|
|
167
|
+
* res.location('http://example.com');
|
|
168
|
+
* res.location('../login'); // /blog/post/1 -> /blog/login
|
|
169
|
+
*
|
|
170
|
+
* Mounting:
|
|
171
|
+
*
|
|
172
|
+
* When an application is mounted and `res.location()`
|
|
173
|
+
* is given a path that does _not_ lead with "/" it becomes
|
|
174
|
+
* relative to the mount-point. For example if the application
|
|
175
|
+
* is mounted at "/blog", the following would become "/blog/login".
|
|
176
|
+
*
|
|
177
|
+
* res.location('login');
|
|
178
|
+
*
|
|
179
|
+
* While the leading slash would result in a location of "/login":
|
|
180
|
+
*
|
|
181
|
+
* res.location('/login');
|
|
182
|
+
*/
|
|
183
|
+
location(url: string): this;
|
|
184
|
+
/**
|
|
185
|
+
* Redirect to the given `url` with optional response `status`
|
|
186
|
+
* defaulting to 302.
|
|
187
|
+
*
|
|
188
|
+
* The resulting `url` is determined by `res.location()`, so
|
|
189
|
+
* it will play nicely with mounted apps, relative paths,
|
|
190
|
+
* `"back"` etc.
|
|
191
|
+
*
|
|
192
|
+
* Examples:
|
|
193
|
+
*
|
|
194
|
+
* res.redirect('back');
|
|
195
|
+
* res.redirect('/foo/bar');
|
|
196
|
+
* res.redirect('http://example.com');
|
|
197
|
+
* res.redirect(301, 'http://example.com');
|
|
198
|
+
* res.redirect('http://example.com', 301);
|
|
199
|
+
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
|
200
|
+
*/
|
|
201
|
+
redirect(url: string): void;
|
|
202
|
+
redirect(status: number, url: string): void;
|
|
203
|
+
/** @deprecated use res.redirect(status, url) instead */
|
|
204
|
+
redirect(url: string, status: number): void;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* @namespace HttpResponseMessage
|
|
208
|
+
*/
|
|
209
|
+
export declare namespace HttpResponseMessage {
|
|
210
|
+
interface Initiator extends HttpMessage.Initiator {
|
|
211
|
+
statusCode?: number;
|
|
212
|
+
statusMessage?: string;
|
|
213
|
+
req?: HttpRequestMessage;
|
|
214
|
+
chunkedEncoding?: boolean;
|
|
215
|
+
}
|
|
216
|
+
function create(init: Initiator): HttpResponseMessage;
|
|
217
|
+
function fromBuffer(buffer: Buffer | ArrayBuffer): HttpResponseMessage;
|
|
218
|
+
function fromStream(readable: Readable): Promise<HttpResponseMessage>;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* @class HttpResponseMessageHost
|
|
222
|
+
*/
|
|
223
|
+
export declare class HttpResponseMessageHost extends HttpMessageHost implements HttpResponseMessage {
|
|
224
|
+
chunkedEncoding?: boolean;
|
|
225
|
+
req?: HttpRequestMessage;
|
|
226
|
+
statusCode?: number;
|
|
227
|
+
statusMessage?: string;
|
|
228
|
+
constructor();
|
|
229
|
+
header(name: 'set-cookie' | 'Set-Cookie', value: string | string[]): this;
|
|
230
|
+
header(name: string, value: number | string): this;
|
|
231
|
+
header(headers: Record<string, number | string | string[]>): this;
|
|
232
|
+
append(name: string, value: string | string[]): this;
|
|
233
|
+
/**
|
|
234
|
+
* Set "Content-Disposition" header to "attachment" with optional `filename`.
|
|
235
|
+
*/
|
|
236
|
+
attachment(filename?: string): this;
|
|
237
|
+
/**
|
|
238
|
+
* Alias for msg.type()
|
|
239
|
+
*/
|
|
240
|
+
contentType(type: string): this;
|
|
241
|
+
/**
|
|
242
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
243
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
244
|
+
*
|
|
245
|
+
* Examples:
|
|
246
|
+
*
|
|
247
|
+
* res.type('.html');
|
|
248
|
+
* res.type('html');
|
|
249
|
+
* res.type('json');
|
|
250
|
+
* res.type('application/json');
|
|
251
|
+
* res.type('png');
|
|
252
|
+
*/
|
|
253
|
+
type(type: string): this;
|
|
254
|
+
/**
|
|
255
|
+
* Set cookie `name` to `value`, with the given `options`.
|
|
256
|
+
*
|
|
257
|
+
* Options:
|
|
258
|
+
*
|
|
259
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
260
|
+
* - `signed` sign the cookie
|
|
261
|
+
* - `path` defaults to "/"
|
|
262
|
+
*
|
|
263
|
+
* Examples:
|
|
264
|
+
*
|
|
265
|
+
* // "Remember Me" for 15 minutes
|
|
266
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
267
|
+
*
|
|
268
|
+
* // same as above
|
|
269
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
270
|
+
*
|
|
271
|
+
*/
|
|
272
|
+
cookie(name: string, value: string, options?: CookieOptions): this;
|
|
273
|
+
/**
|
|
274
|
+
* Clear cookie `name`.
|
|
275
|
+
*/
|
|
276
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
277
|
+
/**
|
|
278
|
+
* Set Link header field with the given `links`.
|
|
279
|
+
*
|
|
280
|
+
* Examples:
|
|
281
|
+
*
|
|
282
|
+
* res.links({
|
|
283
|
+
* next: 'http://api.example.com/users?page=2',
|
|
284
|
+
* last: 'http://api.example.com/users?page=5'
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
*/
|
|
288
|
+
links(links: Record<string, string>): this;
|
|
289
|
+
redirect(url: string): any;
|
|
290
|
+
redirect(status: number, url: string): any;
|
|
291
|
+
/**
|
|
292
|
+
* Send JSON response.
|
|
293
|
+
*
|
|
294
|
+
* Examples:
|
|
295
|
+
*
|
|
296
|
+
* res.json(null);
|
|
297
|
+
* res.json({ user: 'tj' });
|
|
298
|
+
*/
|
|
299
|
+
json(obj: any): this;
|
|
300
|
+
location(url: string): this;
|
|
301
|
+
/**
|
|
302
|
+
* Set status `code`.
|
|
303
|
+
*/
|
|
304
|
+
status(code: number): this;
|
|
305
|
+
/**
|
|
306
|
+
* Set the response HTTP status code to `statusCode` and send its string representation as the response body.
|
|
307
|
+
* @link http://expressjs.com/4x/api.html#res.sendStatus
|
|
308
|
+
*
|
|
309
|
+
* Examples:
|
|
310
|
+
*
|
|
311
|
+
* res.sendStatus(200); // equivalent to res.status(200).send('OK')
|
|
312
|
+
* res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
|
|
313
|
+
* res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
|
|
314
|
+
* res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
|
|
315
|
+
*/
|
|
316
|
+
sendStatus(statusCode: number): this;
|
|
317
|
+
protected _init(init: HttpResponseMessage.Initiator): void;
|
|
318
|
+
static create(init: HttpResponseMessage.Initiator): HttpResponseMessage;
|
|
319
|
+
static fromBuffer(buffer: Buffer | ArrayBuffer): HttpResponseMessage;
|
|
320
|
+
static fromStream(readable: Readable): Promise<HttpResponseMessage>;
|
|
321
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpResponseMessage } from '@opra/common';
|
|
2
1
|
import { ResponseHost } from '../response.host.js';
|
|
2
|
+
import { HttpResponseMessage } from './http-response-message.js';
|
|
3
3
|
export declare class HttpResponseHost extends ResponseHost {
|
|
4
4
|
protected _outgoing: HttpResponseMessage;
|
|
5
5
|
constructor(init: ResponseHost.Initiator, _outgoing: HttpResponseMessage);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ApiDocument
|
|
1
|
+
import { ApiDocument } from '@opra/common';
|
|
2
|
+
import { HttpRequestMessage } from '../http/http-request-message.js';
|
|
3
|
+
import { HttpResponseMessage } from '../http/http-response-message.js';
|
|
2
4
|
import { Request } from './request.interface.js';
|
|
3
5
|
import { Response } from './response.interface.js';
|
|
4
6
|
export declare namespace RequestContext {
|