@eggjs/koa 3.0.1 → 3.1.0-beta.10

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,338 +1,343 @@
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;
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 http0 from "http";
10
+
11
+ //#region src/request.d.ts
12
+ interface RequestSocket extends Socket {
13
+ encrypted: boolean;
11
14
  }
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
- };
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(): http0.IncomingHttpHeaders;
28
+ /**
29
+ * Set request header.
30
+ */
31
+ set header(val: http0.IncomingHttpHeaders);
32
+ /**
33
+ * Return request header, alias as request.header
34
+ */
35
+ get headers(): http0.IncomingHttpHeaders;
36
+ /**
37
+ * Set request header, alias as request.header
38
+ */
39
+ set headers(val: http0.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: 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
+ };
338
341
  }
342
+ //#endregion
343
+ export { Request, RequestSocket };