@eggjs/koa 2.17.0 → 2.18.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.
@@ -0,0 +1,329 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ /// <reference types="node" resolution-mode="require"/>
4
+ /// <reference types="node" resolution-mode="require"/>
5
+ import net from 'node:net';
6
+ import qs from 'node:querystring';
7
+ import util from 'node:util';
8
+ import type { IncomingMessage, ServerResponse } from 'node:http';
9
+ import type Application from './application.js';
10
+ import type Context from './context.js';
11
+ import type Response from './response.js';
12
+ export default class Request {
13
+ #private;
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(path: string);
69
+ /**
70
+ * Get parsed query string.
71
+ */
72
+ get query(): qs.ParsedUrlQuery;
73
+ /**
74
+ * Set query string as an object.
75
+ */
76
+ set query(obj: qs.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
+ /**
109
+ * Get WHATWG parsed URL.
110
+ * Lazily memoized.
111
+ */
112
+ get URL(): URL;
113
+ /**
114
+ * Check if the request is fresh, aka
115
+ * Last-Modified and/or the ETag
116
+ * still match.
117
+ */
118
+ get fresh(): boolean;
119
+ /**
120
+ * Check if the request is stale, aka
121
+ * "Last-Modified" and / or the "ETag" for the
122
+ * resource has changed.
123
+ */
124
+ get stale(): boolean;
125
+ /**
126
+ * Check if the request is idempotent.
127
+ */
128
+ get idempotent(): boolean;
129
+ /**
130
+ * Return the request socket.
131
+ */
132
+ get socket(): net.Socket & {
133
+ encrypted: boolean;
134
+ };
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
+ /**
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
+ /**
188
+ * Get accept object.
189
+ * Lazily memoized.
190
+ */
191
+ get accept(): any;
192
+ /**
193
+ * Set accept object.
194
+ */
195
+ set accept(obj: any);
196
+ /**
197
+ * Check if the given `type(s)` is acceptable, returning
198
+ * the best match when true, otherwise `false`, in which
199
+ * case you should respond with 406 "Not Acceptable".
200
+ *
201
+ * The `type` value may be a single mime type string
202
+ * such as "application/json", the extension name
203
+ * such as "json" or an array `["json", "html", "text/plain"]`. When a list
204
+ * or array is given the _best_ match, if any is returned.
205
+ *
206
+ * Examples:
207
+ *
208
+ * // Accept: text/html
209
+ * this.accepts('html');
210
+ * // => "html"
211
+ *
212
+ * // Accept: text/*, application/json
213
+ * this.accepts('html');
214
+ * // => "html"
215
+ * this.accepts('text/html');
216
+ * // => "text/html"
217
+ * this.accepts('json', 'text');
218
+ * // => "json"
219
+ * this.accepts('application/json');
220
+ * // => "application/json"
221
+ *
222
+ * // Accept: text/*, application/json
223
+ * this.accepts('image/png');
224
+ * this.accepts('png');
225
+ * // => false
226
+ *
227
+ * // Accept: text/*;q=.5, application/json
228
+ * this.accepts(['html', 'json']);
229
+ * this.accepts('html', 'json');
230
+ * // => "json"
231
+ */
232
+ accepts(...args: any[]): string | string[] | false;
233
+ /**
234
+ * Return accepted encodings or best fit based on `encodings`.
235
+ *
236
+ * Given `Accept-Encoding: gzip, deflate`
237
+ * an array sorted by quality is returned:
238
+ *
239
+ * ['gzip', 'deflate']
240
+ */
241
+ acceptsEncodings(...args: any[]): string | string[];
242
+ /**
243
+ * Return accepted charsets or best fit based on `charsets`.
244
+ *
245
+ * Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
246
+ * an array sorted by quality is returned:
247
+ *
248
+ * ['utf-8', 'utf-7', 'iso-8859-1']
249
+ */
250
+ acceptsCharsets(...args: any[]): string | string[];
251
+ /**
252
+ * Return accepted languages or best fit based on `langs`.
253
+ *
254
+ * Given `Accept-Language: en;q=0.8, es, pt`
255
+ * an array sorted by quality is returned:
256
+ *
257
+ * ['es', 'pt', 'en']
258
+ */
259
+ acceptsLanguages(...args: any[]): string | string[];
260
+ /**
261
+ * Check if the incoming request contains the "Content-Type"
262
+ * header field and if it contains any of the given mime `type`s.
263
+ * If there is no request body, `null` is returned.
264
+ * If there is no content type, `false` is returned.
265
+ * Otherwise, it returns the first `type` that matches.
266
+ *
267
+ * Examples:
268
+ *
269
+ * // With Content-Type: text/html; charset=utf-8
270
+ * this.is('html'); // => 'html'
271
+ * this.is('text/html'); // => 'text/html'
272
+ * this.is('text/*', 'application/json'); // => 'text/html'
273
+ *
274
+ * // When Content-Type is application/json
275
+ * this.is('json', 'urlencoded'); // => 'json'
276
+ * this.is('application/json'); // => 'application/json'
277
+ * this.is('html', 'application/*'); // => 'application/json'
278
+ *
279
+ * this.is('html'); // => false
280
+ */
281
+ is(type?: string | string[], ...types: string[]): string | false | null;
282
+ /**
283
+ * Return the request mime type void of
284
+ * parameters such as "charset".
285
+ */
286
+ get type(): string;
287
+ /**
288
+ * Return request header.
289
+ *
290
+ * The `Referrer` header field is special-cased,
291
+ * both `Referrer` and `Referer` are interchangeable.
292
+ *
293
+ * Examples:
294
+ *
295
+ * this.get('Content-Type');
296
+ * // => "text/plain"
297
+ *
298
+ * this.get('content-type');
299
+ * // => "text/plain"
300
+ *
301
+ * this.get('Something');
302
+ * // => ''
303
+ */
304
+ get<T = string | string[]>(field: string): T;
305
+ /**
306
+ * Inspect implementation.
307
+ */
308
+ inspect(): {
309
+ method: string;
310
+ url: string;
311
+ header: import("http").IncomingHttpHeaders;
312
+ } | undefined;
313
+ /**
314
+ * Custom inspection implementation for newer Node.js versions.
315
+ */
316
+ [util.inspect.custom](): {
317
+ method: string;
318
+ url: string;
319
+ header: import("http").IncomingHttpHeaders;
320
+ } | undefined;
321
+ /**
322
+ * Return JSON representation.
323
+ */
324
+ toJSON(): {
325
+ method: string;
326
+ url: string;
327
+ header: import("http").IncomingHttpHeaders;
328
+ };
329
+ }