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