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