@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/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
- * Return request header.
26
- */
27
- get header(): http0.IncomingHttpHeaders;
23
+ * Return request header.
24
+ */
25
+ get header(): IncomingMessage["headers"];
28
26
  /**
29
- * Set request header.
30
- */
31
- set header(val: http0.IncomingHttpHeaders);
27
+ * Set request header.
28
+ */
29
+ set header(val: IncomingMessage["headers"]);
32
30
  /**
33
- * Return request header, alias as request.header
34
- */
35
- get headers(): http0.IncomingHttpHeaders;
31
+ * Return request header, alias as request.header
32
+ */
33
+ get headers(): IncomingMessage["headers"];
36
34
  /**
37
- * Set request header, alias as request.header
38
- */
39
- set headers(val: http0.IncomingHttpHeaders);
35
+ * Set request header, alias as request.header
36
+ */
37
+ set headers(val: IncomingMessage["headers"]);
40
38
  /**
41
- * Get request URL.
42
- */
39
+ * Get request URL.
40
+ */
43
41
  get url(): string;
44
42
  /**
45
- * Set request URL.
46
- */
43
+ * Set request URL.
44
+ */
47
45
  set url(val: string);
48
46
  /**
49
- * Get origin of URL.
50
- */
47
+ * Get origin of URL.
48
+ */
51
49
  get origin(): string;
52
50
  /**
53
- * Get full request URL.
54
- */
51
+ * Get full request URL.
52
+ */
55
53
  get href(): string;
56
54
  /**
57
- * Get request method.
58
- */
55
+ * Get request method.
56
+ */
59
57
  get method(): string;
60
58
  /**
61
- * Set request method.
62
- */
59
+ * Set request method.
60
+ */
63
61
  set method(val: string);
64
62
  /**
65
- * Get request pathname.
66
- */
63
+ * Get request pathname.
64
+ */
67
65
  get path(): string;
68
66
  /**
69
- * Set pathname, retaining the query string when present.
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
- * Get parsed query string.
75
- */
72
+ * Get parsed query string.
73
+ */
76
74
  get query(): ParsedUrlQuery;
77
75
  /**
78
- * Set query string as an object.
79
- */
76
+ * Set query string as an object.
77
+ */
80
78
  set query(obj: ParsedUrlQuery);
81
79
  /**
82
- * Get query string.
83
- */
80
+ * Get query string.
81
+ */
84
82
  get querystring(): string;
85
83
  /**
86
- * Set query string.
87
- */
84
+ * Set query string.
85
+ */
88
86
  set querystring(str: string);
89
87
  /**
90
- * Get the search string. Same as the query string
91
- * except it includes the leading ?.
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
- * Set the search string. Same as
96
- * request.querystring= but included for ubiquity.
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
- * Parse the "Host" header field host
101
- * and support X-Forwarded-Host when a
102
- * proxy is enabled.
103
- * return `hostname:port` format
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
- * Parse the "Host" header field hostname
108
- * and support X-Forwarded-Host when a
109
- * proxy is enabled.
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
- * Get WHATWG parsed URL.
115
- * Lazily memoized.
116
- */
112
+ * Get WHATWG parsed URL.
113
+ * Lazily memoized.
114
+ */
117
115
  get URL(): URL;
118
116
  /**
119
- * Check if the request is fresh, aka
120
- * Last-Modified and/or the ETag
121
- * still match.
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
- * Check if the request is stale, aka
126
- * "Last-Modified" and / or the "ETag" for the
127
- * resource has changed.
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
- * Check if the request is idempotent.
132
- */
129
+ * Check if the request is idempotent.
130
+ */
133
131
  get idempotent(): boolean;
134
132
  /**
135
- * Return the request socket.
136
- */
133
+ * Return the request socket.
134
+ */
137
135
  get socket(): RequestSocket;
138
136
  /**
139
- * Get the charset when present or undefined.
140
- */
141
- get charset(): string;
137
+ * Get the charset when present or undefined.
138
+ */
139
+ get charset(): string | undefined;
142
140
  /**
143
- * Return parsed Content-Length when present.
144
- */
141
+ * Return parsed Content-Length when present.
142
+ */
145
143
  get length(): number | undefined;
146
144
  /**
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
- */
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
- * Shorthand for:
157
- *
158
- * this.protocol == 'https'
159
- */
154
+ * Shorthand for:
155
+ *
156
+ * this.protocol == 'https'
157
+ */
160
158
  get secure(): boolean;
161
159
  /**
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
- */
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
- * 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
- */
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
- * 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
- */
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
- * Get accept object.
194
- * Lazily memoized.
195
- */
191
+ * Get accept object.
192
+ * Lazily memoized.
193
+ */
196
194
  get accept(): Accepts;
197
195
  /**
198
- * Set accept object.
199
- */
196
+ * Set accept object.
197
+ */
200
198
  set accept(obj: Accepts);
201
199
  /**
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
- */
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
- * 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
- */
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
- * 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
- */
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
- * 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
- */
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
- * 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
- */
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
- * Return the request mime type void of
296
- * parameters such as "charset".
297
- */
293
+ * Return the request mime type void of
294
+ * parameters such as "charset".
295
+ */
298
296
  get type(): string;
299
297
  /**
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
- */
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
- * Inspect implementation.
319
- */
320
- inspect(): {
321
- method: string;
322
- url: string;
323
- header: http0.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: 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() {