@eggjs/koa 3.1.0-beta.19 → 3.1.0-beta.20
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/dist/index.d.ts +917 -5
- package/dist/index.js +1363 -4
- package/package.json +2 -2
- package/dist/application.d.ts +0 -131
- package/dist/application.js +0 -233
- package/dist/context.d.ts +0 -230
- package/dist/context.js +0 -304
- package/dist/request.d.ts +0 -343
- package/dist/request.js +0 -459
- package/dist/response.d.ts +0 -231
- package/dist/response.js +0 -387
- package/dist/types.d.ts +0 -14
package/dist/context.js
DELETED
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import util from "node:util";
|
|
2
|
-
import statuses from "statuses";
|
|
3
|
-
import createError from "http-errors";
|
|
4
|
-
import Cookies from "cookies";
|
|
5
|
-
|
|
6
|
-
//#region src/context.ts
|
|
7
|
-
var Context = class {
|
|
8
|
-
app;
|
|
9
|
-
req;
|
|
10
|
-
res;
|
|
11
|
-
request;
|
|
12
|
-
response;
|
|
13
|
-
originalUrl;
|
|
14
|
-
respond;
|
|
15
|
-
#state = {};
|
|
16
|
-
constructor(app, req, res) {
|
|
17
|
-
this.app = app;
|
|
18
|
-
this.req = req;
|
|
19
|
-
this.res = res;
|
|
20
|
-
this.request = new app.RequestClass(app, this, req, res);
|
|
21
|
-
this.response = new app.ResponseClass(app, this, req, res);
|
|
22
|
-
this.request.response = this.response;
|
|
23
|
-
this.response.request = this.request;
|
|
24
|
-
this.originalUrl = req.url ?? "/";
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* util.inspect() implementation, which
|
|
28
|
-
* just returns the JSON output.
|
|
29
|
-
*/
|
|
30
|
-
inspect() {
|
|
31
|
-
return this.toJSON();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Custom inspection implementation for newer Node.js versions.
|
|
35
|
-
*/
|
|
36
|
-
[util.inspect.custom]() {
|
|
37
|
-
return this.inspect();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Return JSON representation.
|
|
41
|
-
*
|
|
42
|
-
* Here we explicitly invoke .toJSON() on each
|
|
43
|
-
* object, as iteration will otherwise fail due
|
|
44
|
-
* to the getters and cause utilities such as
|
|
45
|
-
* clone() to fail.
|
|
46
|
-
*/
|
|
47
|
-
toJSON() {
|
|
48
|
-
return {
|
|
49
|
-
request: this.request.toJSON(),
|
|
50
|
-
response: this.response.toJSON(),
|
|
51
|
-
app: this.app.toJSON(),
|
|
52
|
-
originalUrl: this.originalUrl,
|
|
53
|
-
req: "<original node req>",
|
|
54
|
-
res: "<original node res>",
|
|
55
|
-
socket: "<original node socket>"
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
assert(value, status, errorMessageOrProps, errorProps) {
|
|
59
|
-
if (value) return;
|
|
60
|
-
status = status ?? 500;
|
|
61
|
-
if (typeof errorMessageOrProps === "string") throw createError(status, errorMessageOrProps, errorProps ?? {});
|
|
62
|
-
throw createError(status, errorMessageOrProps ?? {});
|
|
63
|
-
}
|
|
64
|
-
throw(arg1, arg2, errorProps) {
|
|
65
|
-
const args = [];
|
|
66
|
-
if (typeof arg2 === "number") {
|
|
67
|
-
args.push(arg2);
|
|
68
|
-
args.push(arg1);
|
|
69
|
-
} else {
|
|
70
|
-
args.push(arg1);
|
|
71
|
-
if (arg2) args.push(arg2);
|
|
72
|
-
}
|
|
73
|
-
if (errorProps) args.push(errorProps);
|
|
74
|
-
throw createError(...args);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Default error handling.
|
|
78
|
-
* @private
|
|
79
|
-
*/
|
|
80
|
-
onerror(err) {
|
|
81
|
-
if (err === null || err === void 0) return;
|
|
82
|
-
if (!(err instanceof Error || Object.prototype.toString.call(err) === "[object Error]")) err = new Error(util.format("non-error thrown: %j", err));
|
|
83
|
-
let headerSent = false;
|
|
84
|
-
if (this.response.headerSent || !this.response.writable) {
|
|
85
|
-
headerSent = true;
|
|
86
|
-
err.headerSent = true;
|
|
87
|
-
}
|
|
88
|
-
this.app.emit("error", err, this);
|
|
89
|
-
if (headerSent) return;
|
|
90
|
-
const res = this.res;
|
|
91
|
-
for (const name of res.getHeaderNames()) res.removeHeader(name);
|
|
92
|
-
if (err.headers) this.response.set(err.headers);
|
|
93
|
-
this.response.type = "text";
|
|
94
|
-
let statusCode = err.status || err.statusCode;
|
|
95
|
-
if (err.code === "ENOENT") statusCode = 404;
|
|
96
|
-
if (typeof statusCode !== "number" || !statuses.message[statusCode]) statusCode = 500;
|
|
97
|
-
const statusMessage = statuses.message[statusCode];
|
|
98
|
-
const msg = err.expose ? err.message : statusMessage;
|
|
99
|
-
err.status = statusCode;
|
|
100
|
-
this.response.status = statusCode;
|
|
101
|
-
this.response.length = Buffer.byteLength(msg);
|
|
102
|
-
res.end(msg);
|
|
103
|
-
}
|
|
104
|
-
_cookies;
|
|
105
|
-
get cookies() {
|
|
106
|
-
if (!this._cookies) this._cookies = new Cookies(this.req, this.res, {
|
|
107
|
-
keys: this.app.keys,
|
|
108
|
-
secure: this.request.secure
|
|
109
|
-
});
|
|
110
|
-
return this._cookies;
|
|
111
|
-
}
|
|
112
|
-
set cookies(cookies) {
|
|
113
|
-
this._cookies = cookies;
|
|
114
|
-
}
|
|
115
|
-
get state() {
|
|
116
|
-
return this.#state;
|
|
117
|
-
}
|
|
118
|
-
acceptsLanguages(languages, ...others) {
|
|
119
|
-
return this.request.acceptsLanguages(languages, ...others);
|
|
120
|
-
}
|
|
121
|
-
acceptsEncodings(encodings, ...others) {
|
|
122
|
-
return this.request.acceptsEncodings(encodings, ...others);
|
|
123
|
-
}
|
|
124
|
-
acceptsCharsets(charsets, ...others) {
|
|
125
|
-
return this.request.acceptsCharsets(charsets, ...others);
|
|
126
|
-
}
|
|
127
|
-
accepts(args, ...others) {
|
|
128
|
-
return this.request.accepts(args, ...others);
|
|
129
|
-
}
|
|
130
|
-
get(field) {
|
|
131
|
-
return this.request.get(field);
|
|
132
|
-
}
|
|
133
|
-
is(type, ...types) {
|
|
134
|
-
return this.request.is(type, ...types);
|
|
135
|
-
}
|
|
136
|
-
get querystring() {
|
|
137
|
-
return this.request.querystring;
|
|
138
|
-
}
|
|
139
|
-
set querystring(str) {
|
|
140
|
-
this.request.querystring = str;
|
|
141
|
-
}
|
|
142
|
-
get idempotent() {
|
|
143
|
-
return this.request.idempotent;
|
|
144
|
-
}
|
|
145
|
-
get socket() {
|
|
146
|
-
return this.request.socket;
|
|
147
|
-
}
|
|
148
|
-
get search() {
|
|
149
|
-
return this.request.search;
|
|
150
|
-
}
|
|
151
|
-
set search(str) {
|
|
152
|
-
this.request.search = str;
|
|
153
|
-
}
|
|
154
|
-
get method() {
|
|
155
|
-
return this.request.method;
|
|
156
|
-
}
|
|
157
|
-
set method(method) {
|
|
158
|
-
this.request.method = method;
|
|
159
|
-
}
|
|
160
|
-
get query() {
|
|
161
|
-
return this.request.query;
|
|
162
|
-
}
|
|
163
|
-
set query(obj) {
|
|
164
|
-
this.request.query = obj;
|
|
165
|
-
}
|
|
166
|
-
get path() {
|
|
167
|
-
return this.request.path;
|
|
168
|
-
}
|
|
169
|
-
set path(path) {
|
|
170
|
-
this.request.path = path;
|
|
171
|
-
}
|
|
172
|
-
get url() {
|
|
173
|
-
return this.request.url;
|
|
174
|
-
}
|
|
175
|
-
set url(url) {
|
|
176
|
-
this.request.url = url;
|
|
177
|
-
}
|
|
178
|
-
get accept() {
|
|
179
|
-
return this.request.accept;
|
|
180
|
-
}
|
|
181
|
-
set accept(accept) {
|
|
182
|
-
this.request.accept = accept;
|
|
183
|
-
}
|
|
184
|
-
get origin() {
|
|
185
|
-
return this.request.origin;
|
|
186
|
-
}
|
|
187
|
-
get href() {
|
|
188
|
-
return this.request.href;
|
|
189
|
-
}
|
|
190
|
-
get subdomains() {
|
|
191
|
-
return this.request.subdomains;
|
|
192
|
-
}
|
|
193
|
-
get protocol() {
|
|
194
|
-
return this.request.protocol;
|
|
195
|
-
}
|
|
196
|
-
get host() {
|
|
197
|
-
return this.request.host;
|
|
198
|
-
}
|
|
199
|
-
get hostname() {
|
|
200
|
-
return this.request.hostname;
|
|
201
|
-
}
|
|
202
|
-
get URL() {
|
|
203
|
-
return this.request.URL;
|
|
204
|
-
}
|
|
205
|
-
get header() {
|
|
206
|
-
return this.request.header;
|
|
207
|
-
}
|
|
208
|
-
get headers() {
|
|
209
|
-
return this.request.headers;
|
|
210
|
-
}
|
|
211
|
-
get secure() {
|
|
212
|
-
return this.request.secure;
|
|
213
|
-
}
|
|
214
|
-
get stale() {
|
|
215
|
-
return this.request.stale;
|
|
216
|
-
}
|
|
217
|
-
get fresh() {
|
|
218
|
-
return this.request.fresh;
|
|
219
|
-
}
|
|
220
|
-
get ips() {
|
|
221
|
-
return this.request.ips;
|
|
222
|
-
}
|
|
223
|
-
get ip() {
|
|
224
|
-
return this.request.ip;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Response delegation.
|
|
228
|
-
*/
|
|
229
|
-
attachment(...args) {
|
|
230
|
-
return this.response.attachment(...args);
|
|
231
|
-
}
|
|
232
|
-
redirect(...args) {
|
|
233
|
-
return this.response.redirect(...args);
|
|
234
|
-
}
|
|
235
|
-
remove(...args) {
|
|
236
|
-
return this.response.remove(...args);
|
|
237
|
-
}
|
|
238
|
-
vary(...args) {
|
|
239
|
-
return this.response.vary(...args);
|
|
240
|
-
}
|
|
241
|
-
has(...args) {
|
|
242
|
-
return this.response.has(...args);
|
|
243
|
-
}
|
|
244
|
-
set(...args) {
|
|
245
|
-
return this.response.set(...args);
|
|
246
|
-
}
|
|
247
|
-
append(...args) {
|
|
248
|
-
return this.response.append(...args);
|
|
249
|
-
}
|
|
250
|
-
flushHeaders(...args) {
|
|
251
|
-
return this.response.flushHeaders(...args);
|
|
252
|
-
}
|
|
253
|
-
get status() {
|
|
254
|
-
return this.response.status;
|
|
255
|
-
}
|
|
256
|
-
set status(status) {
|
|
257
|
-
this.response.status = status;
|
|
258
|
-
}
|
|
259
|
-
get message() {
|
|
260
|
-
return this.response.message;
|
|
261
|
-
}
|
|
262
|
-
set message(msg) {
|
|
263
|
-
this.response.message = msg;
|
|
264
|
-
}
|
|
265
|
-
get body() {
|
|
266
|
-
return this.response.body;
|
|
267
|
-
}
|
|
268
|
-
set body(val) {
|
|
269
|
-
this.response.body = val;
|
|
270
|
-
}
|
|
271
|
-
get length() {
|
|
272
|
-
return this.response.length;
|
|
273
|
-
}
|
|
274
|
-
set length(n) {
|
|
275
|
-
this.response.length = n;
|
|
276
|
-
}
|
|
277
|
-
get type() {
|
|
278
|
-
return this.response.type;
|
|
279
|
-
}
|
|
280
|
-
set type(type) {
|
|
281
|
-
this.response.type = type;
|
|
282
|
-
}
|
|
283
|
-
get lastModified() {
|
|
284
|
-
return this.response.lastModified;
|
|
285
|
-
}
|
|
286
|
-
set lastModified(val) {
|
|
287
|
-
this.response.lastModified = val;
|
|
288
|
-
}
|
|
289
|
-
get etag() {
|
|
290
|
-
return this.response.etag;
|
|
291
|
-
}
|
|
292
|
-
set etag(val) {
|
|
293
|
-
this.response.etag = val;
|
|
294
|
-
}
|
|
295
|
-
get headerSent() {
|
|
296
|
-
return this.response.headerSent;
|
|
297
|
-
}
|
|
298
|
-
get writable() {
|
|
299
|
-
return this.response.writable;
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
//#endregion
|
|
304
|
-
export { Context };
|
package/dist/request.d.ts
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { Response } from "./response.js";
|
|
2
|
-
import { Context } from "./context.js";
|
|
3
|
-
import { Application } from "./application.js";
|
|
4
|
-
import util from "node:util";
|
|
5
|
-
import { IncomingMessage, ServerResponse } from "node:http";
|
|
6
|
-
import { Socket } from "node:net";
|
|
7
|
-
import { ParsedUrlQuery } from "node:querystring";
|
|
8
|
-
import { Accepts } from "accepts";
|
|
9
|
-
import * as http7 from "http";
|
|
10
|
-
|
|
11
|
-
//#region src/request.d.ts
|
|
12
|
-
interface RequestSocket extends Socket {
|
|
13
|
-
encrypted: boolean;
|
|
14
|
-
}
|
|
15
|
-
declare class Request {
|
|
16
|
-
[key: symbol]: unknown;
|
|
17
|
-
app: Application;
|
|
18
|
-
req: IncomingMessage;
|
|
19
|
-
res: ServerResponse;
|
|
20
|
-
ctx: Context;
|
|
21
|
-
response: Response;
|
|
22
|
-
originalUrl: string;
|
|
23
|
-
constructor(app: Application, ctx: Context, req: IncomingMessage, res: ServerResponse);
|
|
24
|
-
/**
|
|
25
|
-
* Return request header.
|
|
26
|
-
*/
|
|
27
|
-
get header(): http7.IncomingHttpHeaders;
|
|
28
|
-
/**
|
|
29
|
-
* Set request header.
|
|
30
|
-
*/
|
|
31
|
-
set header(val: http7.IncomingHttpHeaders);
|
|
32
|
-
/**
|
|
33
|
-
* Return request header, alias as request.header
|
|
34
|
-
*/
|
|
35
|
-
get headers(): http7.IncomingHttpHeaders;
|
|
36
|
-
/**
|
|
37
|
-
* Set request header, alias as request.header
|
|
38
|
-
*/
|
|
39
|
-
set headers(val: http7.IncomingHttpHeaders);
|
|
40
|
-
/**
|
|
41
|
-
* Get request URL.
|
|
42
|
-
*/
|
|
43
|
-
get url(): string;
|
|
44
|
-
/**
|
|
45
|
-
* Set request URL.
|
|
46
|
-
*/
|
|
47
|
-
set url(val: string);
|
|
48
|
-
/**
|
|
49
|
-
* Get origin of URL.
|
|
50
|
-
*/
|
|
51
|
-
get origin(): string;
|
|
52
|
-
/**
|
|
53
|
-
* Get full request URL.
|
|
54
|
-
*/
|
|
55
|
-
get href(): string;
|
|
56
|
-
/**
|
|
57
|
-
* Get request method.
|
|
58
|
-
*/
|
|
59
|
-
get method(): string;
|
|
60
|
-
/**
|
|
61
|
-
* Set request method.
|
|
62
|
-
*/
|
|
63
|
-
set method(val: string);
|
|
64
|
-
/**
|
|
65
|
-
* Get request pathname.
|
|
66
|
-
*/
|
|
67
|
-
get path(): string;
|
|
68
|
-
/**
|
|
69
|
-
* Set pathname, retaining the query string when present.
|
|
70
|
-
*/
|
|
71
|
-
set path(pathname: string);
|
|
72
|
-
protected _parsedUrlQueryCache: Record<string, ParsedUrlQuery> | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Get parsed query string.
|
|
75
|
-
*/
|
|
76
|
-
get query(): ParsedUrlQuery;
|
|
77
|
-
/**
|
|
78
|
-
* Set query string as an object.
|
|
79
|
-
*/
|
|
80
|
-
set query(obj: ParsedUrlQuery);
|
|
81
|
-
/**
|
|
82
|
-
* Get query string.
|
|
83
|
-
*/
|
|
84
|
-
get querystring(): string;
|
|
85
|
-
/**
|
|
86
|
-
* Set query string.
|
|
87
|
-
*/
|
|
88
|
-
set querystring(str: string);
|
|
89
|
-
/**
|
|
90
|
-
* Get the search string. Same as the query string
|
|
91
|
-
* except it includes the leading ?.
|
|
92
|
-
*/
|
|
93
|
-
get search(): string;
|
|
94
|
-
/**
|
|
95
|
-
* Set the search string. Same as
|
|
96
|
-
* request.querystring= but included for ubiquity.
|
|
97
|
-
*/
|
|
98
|
-
set search(str: string);
|
|
99
|
-
/**
|
|
100
|
-
* Parse the "Host" header field host
|
|
101
|
-
* and support X-Forwarded-Host when a
|
|
102
|
-
* proxy is enabled.
|
|
103
|
-
* return `hostname:port` format
|
|
104
|
-
*/
|
|
105
|
-
get host(): string;
|
|
106
|
-
/**
|
|
107
|
-
* Parse the "Host" header field hostname
|
|
108
|
-
* and support X-Forwarded-Host when a
|
|
109
|
-
* proxy is enabled.
|
|
110
|
-
*/
|
|
111
|
-
get hostname(): string;
|
|
112
|
-
protected _memoizedURL: URL | undefined;
|
|
113
|
-
/**
|
|
114
|
-
* Get WHATWG parsed URL.
|
|
115
|
-
* Lazily memoized.
|
|
116
|
-
*/
|
|
117
|
-
get URL(): URL;
|
|
118
|
-
/**
|
|
119
|
-
* Check if the request is fresh, aka
|
|
120
|
-
* Last-Modified and/or the ETag
|
|
121
|
-
* still match.
|
|
122
|
-
*/
|
|
123
|
-
get fresh(): boolean;
|
|
124
|
-
/**
|
|
125
|
-
* Check if the request is stale, aka
|
|
126
|
-
* "Last-Modified" and / or the "ETag" for the
|
|
127
|
-
* resource has changed.
|
|
128
|
-
*/
|
|
129
|
-
get stale(): boolean;
|
|
130
|
-
/**
|
|
131
|
-
* Check if the request is idempotent.
|
|
132
|
-
*/
|
|
133
|
-
get idempotent(): boolean;
|
|
134
|
-
/**
|
|
135
|
-
* Return the request socket.
|
|
136
|
-
*/
|
|
137
|
-
get socket(): RequestSocket;
|
|
138
|
-
/**
|
|
139
|
-
* Get the charset when present or undefined.
|
|
140
|
-
*/
|
|
141
|
-
get charset(): string;
|
|
142
|
-
/**
|
|
143
|
-
* Return parsed Content-Length when present.
|
|
144
|
-
*/
|
|
145
|
-
get length(): number | undefined;
|
|
146
|
-
/**
|
|
147
|
-
* Return the protocol string "http" or "https"
|
|
148
|
-
* when requested with TLS. When the proxy setting
|
|
149
|
-
* is enabled the "X-Forwarded-Proto" header
|
|
150
|
-
* field will be trusted. If you're running behind
|
|
151
|
-
* a reverse proxy that supplies https for you this
|
|
152
|
-
* may be enabled.
|
|
153
|
-
*/
|
|
154
|
-
get protocol(): string;
|
|
155
|
-
/**
|
|
156
|
-
* Shorthand for:
|
|
157
|
-
*
|
|
158
|
-
* this.protocol == 'https'
|
|
159
|
-
*/
|
|
160
|
-
get secure(): boolean;
|
|
161
|
-
/**
|
|
162
|
-
* When `app.proxy` is `true`, parse
|
|
163
|
-
* the "X-Forwarded-For" ip address list.
|
|
164
|
-
*
|
|
165
|
-
* For example if the value was "client, proxy1, proxy2"
|
|
166
|
-
* you would receive the array `["client", "proxy1", "proxy2"]`
|
|
167
|
-
* where "proxy2" is the furthest down-stream.
|
|
168
|
-
*/
|
|
169
|
-
get ips(): string[];
|
|
170
|
-
protected _ip: string;
|
|
171
|
-
/**
|
|
172
|
-
* Return request's remote address
|
|
173
|
-
* When `app.proxy` is `true`, parse
|
|
174
|
-
* the "X-Forwarded-For" ip address list and return the first one
|
|
175
|
-
*/
|
|
176
|
-
get ip(): string;
|
|
177
|
-
set ip(ip: string);
|
|
178
|
-
/**
|
|
179
|
-
* Return subdomains as an array.
|
|
180
|
-
*
|
|
181
|
-
* Subdomains are the dot-separated parts of the host before the main domain
|
|
182
|
-
* of the app. By default, the domain of the app is assumed to be the last two
|
|
183
|
-
* parts of the host. This can be changed by setting `app.subdomainOffset`.
|
|
184
|
-
*
|
|
185
|
-
* For example, if the domain is "tobi.ferrets.example.com":
|
|
186
|
-
* If `app.subdomainOffset` is not set, this.subdomains is
|
|
187
|
-
* `["ferrets", "tobi"]`.
|
|
188
|
-
* If `app.subdomainOffset` is 3, this.subdomains is `["tobi"]`.
|
|
189
|
-
*/
|
|
190
|
-
get subdomains(): string[];
|
|
191
|
-
protected _accept: Accepts;
|
|
192
|
-
/**
|
|
193
|
-
* Get accept object.
|
|
194
|
-
* Lazily memoized.
|
|
195
|
-
*/
|
|
196
|
-
get accept(): Accepts;
|
|
197
|
-
/**
|
|
198
|
-
* Set accept object.
|
|
199
|
-
*/
|
|
200
|
-
set accept(obj: Accepts);
|
|
201
|
-
/**
|
|
202
|
-
* Check if the given `type(s)` is acceptable, returning
|
|
203
|
-
* the best match when true, otherwise `false`, in which
|
|
204
|
-
* case you should respond with 406 "Not Acceptable".
|
|
205
|
-
*
|
|
206
|
-
* The `type` value may be a single mime type string
|
|
207
|
-
* such as "application/json", the extension name
|
|
208
|
-
* such as "json" or an array `["json", "html", "text/plain"]`. When a list
|
|
209
|
-
* or array is given the _best_ match, if any is returned.
|
|
210
|
-
*
|
|
211
|
-
* Examples:
|
|
212
|
-
*
|
|
213
|
-
* // Accept: text/html
|
|
214
|
-
* this.accepts('html');
|
|
215
|
-
* // => "html"
|
|
216
|
-
*
|
|
217
|
-
* // Accept: text/*, application/json
|
|
218
|
-
* this.accepts('html');
|
|
219
|
-
* // => "html"
|
|
220
|
-
* this.accepts('text/html');
|
|
221
|
-
* // => "text/html"
|
|
222
|
-
* this.accepts('json', 'text');
|
|
223
|
-
* // => "json"
|
|
224
|
-
* this.accepts('application/json');
|
|
225
|
-
* // => "application/json"
|
|
226
|
-
*
|
|
227
|
-
* // Accept: text/*, application/json
|
|
228
|
-
* this.accepts('image/png');
|
|
229
|
-
* this.accepts('png');
|
|
230
|
-
* // => false
|
|
231
|
-
*
|
|
232
|
-
* // Accept: text/*;q=.5, application/json
|
|
233
|
-
* this.accepts(['html', 'json']);
|
|
234
|
-
* this.accepts('html', 'json');
|
|
235
|
-
* // => "json"
|
|
236
|
-
*/
|
|
237
|
-
accepts(args: string[]): string | string[] | false;
|
|
238
|
-
accepts(...args: string[]): string | string[] | false;
|
|
239
|
-
/**
|
|
240
|
-
* Return accepted encodings or best fit based on `encodings`.
|
|
241
|
-
*
|
|
242
|
-
* Given `Accept-Encoding: gzip, deflate`
|
|
243
|
-
* an array sorted by quality is returned:
|
|
244
|
-
*
|
|
245
|
-
* ['gzip', 'deflate']
|
|
246
|
-
*/
|
|
247
|
-
acceptsEncodings(): string[];
|
|
248
|
-
acceptsEncodings(encodings: string[]): string | false;
|
|
249
|
-
acceptsEncodings(...encodings: string[]): string | false;
|
|
250
|
-
/**
|
|
251
|
-
* Return accepted charsets or best fit based on `charsets`.
|
|
252
|
-
*
|
|
253
|
-
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
|
|
254
|
-
* an array sorted by quality is returned:
|
|
255
|
-
*
|
|
256
|
-
* ['utf-8', 'utf-7', 'iso-8859-1']
|
|
257
|
-
*/
|
|
258
|
-
acceptsCharsets(): string[];
|
|
259
|
-
acceptsCharsets(charsets: string[]): string | false;
|
|
260
|
-
acceptsCharsets(...charsets: string[]): string | false;
|
|
261
|
-
/**
|
|
262
|
-
* Return accepted languages or best fit based on `langs`.
|
|
263
|
-
*
|
|
264
|
-
* Given `Accept-Language: en;q=0.8, es, pt`
|
|
265
|
-
* an array sorted by quality is returned:
|
|
266
|
-
*
|
|
267
|
-
* ['es', 'pt', 'en']
|
|
268
|
-
*/
|
|
269
|
-
acceptsLanguages(): string[];
|
|
270
|
-
acceptsLanguages(languages: string[]): string | false;
|
|
271
|
-
acceptsLanguages(...languages: string[]): string | false;
|
|
272
|
-
/**
|
|
273
|
-
* Check if the incoming request contains the "Content-Type"
|
|
274
|
-
* header field and if it contains any of the given mime `type`s.
|
|
275
|
-
* If there is no request body, `null` is returned.
|
|
276
|
-
* If there is no content type, `false` is returned.
|
|
277
|
-
* Otherwise, it returns the first `type` that matches.
|
|
278
|
-
*
|
|
279
|
-
* Examples:
|
|
280
|
-
*
|
|
281
|
-
* // With Content-Type: text/html; charset=utf-8
|
|
282
|
-
* this.is('html'); // => 'html'
|
|
283
|
-
* this.is('text/html'); // => 'text/html'
|
|
284
|
-
* this.is('text/*', 'application/json'); // => 'text/html'
|
|
285
|
-
*
|
|
286
|
-
* // When Content-Type is application/json
|
|
287
|
-
* this.is('json', 'urlencoded'); // => 'json'
|
|
288
|
-
* this.is('application/json'); // => 'application/json'
|
|
289
|
-
* this.is('html', 'application/*'); // => 'application/json'
|
|
290
|
-
*
|
|
291
|
-
* this.is('html'); // => false
|
|
292
|
-
*/
|
|
293
|
-
is(type?: string | string[], ...types: string[]): string | false | null;
|
|
294
|
-
/**
|
|
295
|
-
* Return the request mime type void of
|
|
296
|
-
* parameters such as "charset".
|
|
297
|
-
*/
|
|
298
|
-
get type(): string;
|
|
299
|
-
/**
|
|
300
|
-
* Return request header.
|
|
301
|
-
*
|
|
302
|
-
* The `Referrer` header field is special-cased,
|
|
303
|
-
* both `Referrer` and `Referer` are interchangeable.
|
|
304
|
-
*
|
|
305
|
-
* Examples:
|
|
306
|
-
*
|
|
307
|
-
* this.get('Content-Type');
|
|
308
|
-
* // => "text/plain"
|
|
309
|
-
*
|
|
310
|
-
* this.get('content-type');
|
|
311
|
-
* // => "text/plain"
|
|
312
|
-
*
|
|
313
|
-
* this.get('Something');
|
|
314
|
-
* // => ''
|
|
315
|
-
*/
|
|
316
|
-
get<T = string | string[]>(field: string): T;
|
|
317
|
-
/**
|
|
318
|
-
* Inspect implementation.
|
|
319
|
-
*/
|
|
320
|
-
inspect(): {
|
|
321
|
-
method: string;
|
|
322
|
-
url: string;
|
|
323
|
-
header: http7.IncomingHttpHeaders;
|
|
324
|
-
} | undefined;
|
|
325
|
-
/**
|
|
326
|
-
* Custom inspection implementation for newer Node.js versions.
|
|
327
|
-
*/
|
|
328
|
-
[util.inspect.custom](): {
|
|
329
|
-
method: string;
|
|
330
|
-
url: string;
|
|
331
|
-
header: http7.IncomingHttpHeaders;
|
|
332
|
-
} | undefined;
|
|
333
|
-
/**
|
|
334
|
-
* Return JSON representation.
|
|
335
|
-
*/
|
|
336
|
-
toJSON(): {
|
|
337
|
-
method: string;
|
|
338
|
-
url: string;
|
|
339
|
-
header: http7.IncomingHttpHeaders;
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
//#endregion
|
|
343
|
-
export { Request, RequestSocket };
|