@eggjs/koa 3.1.0-beta.3 → 3.1.0-beta.31

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