@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.
@@ -1,231 +1,211 @@
1
- import { Request } from "./request.js";
2
- import { Context } from "./context.js";
3
- import { Application } from "./application.js";
4
- import util from "node:util";
5
- import Stream from "node:stream";
6
- import { IncomingMessage, ServerResponse } from "node:http";
7
- import { Options } from "content-disposition";
8
- import * as http0 from "http";
9
- import * as net0 from "net";
10
-
11
- //#region src/response.d.ts
12
- declare class Response {
13
- [key: symbol]: unknown;
14
- app: Application;
15
- req: IncomingMessage;
16
- res: ServerResponse;
17
- ctx: Context;
18
- request: Request;
19
- constructor(app: Application, ctx: Context, req: IncomingMessage, res: ServerResponse);
20
- /**
21
- * Return the request socket.
22
- */
23
- get socket(): net0.Socket | null;
24
- /**
25
- * Return response header.
26
- */
27
- get header(): http0.OutgoingHttpHeaders;
28
- /**
29
- * Return response header, alias as response.header
30
- */
31
- get headers(): http0.OutgoingHttpHeaders;
32
- _explicitStatus: boolean;
33
- /**
34
- * Get response status code.
35
- */
36
- get status(): number;
37
- /**
38
- * Set response status code.
39
- */
40
- set status(code: number);
41
- /**
42
- * Get response status message
43
- */
44
- get message(): string;
45
- /**
46
- * Set response status message
47
- */
48
- set message(msg: string);
49
- _body: any;
50
- _explicitNullBody: boolean;
51
- /**
52
- * Get response body.
53
- */
54
- get body(): string | Buffer | object | Stream | null | undefined | boolean;
55
- /**
56
- * Set response body.
57
- */
58
- set body(val: string | Buffer | object | Stream | null | undefined | boolean);
59
- /**
60
- * Set Content-Length field to `n`.
61
- */
62
- set length(n: number | string | undefined);
63
- /**
64
- * Return parsed response Content-Length when present.
65
- *
66
- * When Content-Length is not defined it will return `undefined`.
67
- */
68
- get length(): number | undefined;
69
- /**
70
- * Check if a header has been written to the socket.
71
- */
72
- get headerSent(): boolean;
73
- /**
74
- * Vary on `field`.
75
- */
76
- vary(field: string): void;
77
- _getBackReferrer(): string | undefined;
78
- /**
79
- * Perform a 302 redirect to `url`.
80
- *
81
- * The string "back" is special-cased
82
- * to provide Referrer support, when Referrer
83
- * is not present `alt` or "/" is used.
84
- *
85
- * Examples:
86
- *
87
- * this.redirect('back');
88
- * this.redirect('back', '/index.html');
89
- * this.redirect('/login');
90
- * this.redirect('http://google.com'); // will format to 'http://google.com/'
91
- */
92
- redirect(url: string, alt?: string): void;
93
- /**
94
- * Set Content-Disposition header to "attachment" with optional `filename`.
95
- */
96
- attachment(filename?: string, options?: Options): void;
97
- /**
98
- * Set Content-Type response header with `type` through `mime.lookup()`
99
- * when it does not contain a charset.
100
- *
101
- * Examples:
102
- *
103
- * this.type = '.html';
104
- * this.type = 'html';
105
- * this.type = 'json';
106
- * this.type = 'application/json';
107
- * this.type = 'png';
108
- */
109
- set type(type: string | null | undefined);
110
- /**
111
- * Return the response mime type void of
112
- * parameters such as "charset".
113
- */
114
- get type(): string;
115
- /**
116
- * Check whether the response is one of the listed types.
117
- * Pretty much the same as `this.request.is()`.
118
- *
119
- * this.response.is('html')
120
- * this.response.is('html', 'json')
121
- */
122
- is(type?: string | string[], ...types: string[]): string | false;
123
- /**
124
- * Set the Last-Modified date using a string or a Date.
125
- *
126
- * this.response.lastModified = new Date();
127
- * this.response.lastModified = '2013-09-13';
128
- */
129
- set lastModified(val: string | Date | undefined);
130
- /**
131
- * Get the Last-Modified date in Date form, if it exists.
132
- */
133
- get lastModified(): Date | undefined;
134
- /**
135
- * Set the ETag of a response.
136
- * This will normalize the quotes if necessary.
137
- *
138
- * this.response.etag = 'md5-hash-sum';
139
- * this.response.etag = '"md5-hash-sum"';
140
- * this.response.etag = 'W/"123456789"';
141
- */
142
- set etag(val: string);
143
- /**
144
- * Get the ETag of a response.
145
- */
146
- get etag(): string;
147
- /**
148
- * Return response header.
149
- *
150
- * Examples:
151
- *
152
- * this.get('Content-Type');
153
- * // => "text/plain"
154
- *
155
- * this.get('content-type');
156
- * // => "text/plain"
157
- */
158
- get<T = string | string[] | number>(field: string): T;
159
- /**
160
- * Returns true if the header identified by name is currently set in the outgoing headers.
161
- * The header name matching is case-insensitive.
162
- *
163
- * Examples:
164
- *
165
- * this.has('Content-Type');
166
- * // => true
167
- *
168
- * this.get('content-type');
169
- * // => true
170
- */
171
- has(field: string): boolean;
172
- /**
173
- * Set header `field` to `val` or pass
174
- * an object of header fields.
175
- *
176
- * Examples:
177
- *
178
- * this.set('Foo', ['bar', 'baz']);
179
- * this.set('Accept', 'application/json');
180
- * this.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
181
- */
182
- set(field: string | Record<string, string>, val?: string | number | unknown[]): void;
183
- /**
184
- * Append additional header `field` with value `val`.
185
- *
186
- * Examples:
187
- *
188
- * ```
189
- * this.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
190
- * this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
191
- * this.append('Warning', '199 Miscellaneous warning');
192
- */
193
- append(field: string, val: string | string[]): void;
194
- /**
195
- * Remove header `field`.
196
- */
197
- remove(field: string): void;
198
- /**
199
- * Checks if the request is writable.
200
- * Tests for the existence of the socket
201
- * as node sometimes does not set it.
202
- */
203
- get writable(): boolean;
204
- /**
205
- * Inspect implementation.
206
- */
207
- inspect(): {
208
- status: number;
209
- message: string;
210
- header: http0.OutgoingHttpHeaders;
211
- } | undefined;
212
- [util.inspect.custom](): {
213
- status: number;
214
- message: string;
215
- header: http0.OutgoingHttpHeaders;
216
- } | undefined;
217
- /**
218
- * Return JSON representation.
219
- */
220
- toJSON(): {
221
- status: number;
222
- message: string;
223
- header: http0.OutgoingHttpHeaders;
224
- };
225
- /**
226
- * Flush any set headers and begin the body
227
- */
228
- flushHeaders(): void;
1
+ import Stream from 'node:stream';
2
+ import type { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'node:http';
3
+ import { type Options as ContentDispositionOptions } from 'content-disposition';
4
+ import type { Application } from './application.ts';
5
+ import type { Context } from './context.ts';
6
+ import type { Request } from './request.ts';
7
+ export declare class Response {
8
+ [key: symbol]: unknown;
9
+ app: Application;
10
+ req: IncomingMessage;
11
+ res: ServerResponse;
12
+ ctx: Context;
13
+ request: Request;
14
+ constructor(app: Application, ctx: Context, req: IncomingMessage, res: ServerResponse);
15
+ /**
16
+ * Return the request socket.
17
+ */
18
+ get socket(): ServerResponse['socket'];
19
+ /**
20
+ * Return response header.
21
+ */
22
+ get header(): OutgoingHttpHeaders;
23
+ /**
24
+ * Return response header, alias as response.header
25
+ */
26
+ get headers(): OutgoingHttpHeaders;
27
+ _explicitStatus: boolean;
28
+ /**
29
+ * Get response status code.
30
+ */
31
+ get status(): number;
32
+ /**
33
+ * Set response status code.
34
+ */
35
+ set status(code: number);
36
+ /**
37
+ * Get response status message
38
+ */
39
+ get message(): string;
40
+ /**
41
+ * Set response status message
42
+ */
43
+ set message(msg: string);
44
+ _body: any;
45
+ _explicitNullBody: boolean;
46
+ /**
47
+ * Get response body.
48
+ */
49
+ get body(): string | Buffer | object | Stream | null | undefined | boolean;
50
+ /**
51
+ * Set response body.
52
+ */
53
+ set body(val: string | Buffer | object | Stream | null | undefined | boolean);
54
+ /**
55
+ * Set Content-Length field to `n`.
56
+ */
57
+ set length(n: number | string | undefined);
58
+ /**
59
+ * Return parsed response Content-Length when present.
60
+ *
61
+ * When Content-Length is not defined it will return `undefined`.
62
+ */
63
+ get length(): number | undefined;
64
+ /**
65
+ * Check if a header has been written to the socket.
66
+ */
67
+ get headerSent(): boolean;
68
+ /**
69
+ * Vary on `field`.
70
+ */
71
+ vary(field: string): void;
72
+ protected _getBackReferrer(): string | undefined;
73
+ /**
74
+ * Perform a 302 redirect to `url`.
75
+ *
76
+ * The string "back" is special-cased
77
+ * to provide Referrer support, when Referrer
78
+ * is not present `alt` or "/" is used.
79
+ *
80
+ * Examples:
81
+ *
82
+ * this.redirect('back');
83
+ * this.redirect('back', '/index.html');
84
+ * this.redirect('/login');
85
+ * this.redirect('http://google.com'); // will format to 'http://google.com/'
86
+ */
87
+ redirect(url: string, alt?: string): void;
88
+ /**
89
+ * Set Content-Disposition header to "attachment" with optional `filename`.
90
+ */
91
+ attachment(filename?: string, options?: ContentDispositionOptions): void;
92
+ /**
93
+ * Set Content-Type response header with `type` through `mime.lookup()`
94
+ * when it does not contain a charset.
95
+ *
96
+ * Examples:
97
+ *
98
+ * this.type = '.html';
99
+ * this.type = 'html';
100
+ * this.type = 'json';
101
+ * this.type = 'application/json';
102
+ * this.type = 'png';
103
+ */
104
+ set type(type: string | null | undefined);
105
+ /**
106
+ * Return the response mime type void of
107
+ * parameters such as "charset".
108
+ */
109
+ get type(): string;
110
+ /**
111
+ * Check whether the response is one of the listed types.
112
+ * Pretty much the same as `this.request.is()`.
113
+ *
114
+ * this.response.is('html')
115
+ * this.response.is('html', 'json')
116
+ */
117
+ is(type?: string | string[], ...types: string[]): string | false;
118
+ /**
119
+ * Set the Last-Modified date using a string or a Date.
120
+ *
121
+ * this.response.lastModified = new Date();
122
+ * this.response.lastModified = '2013-09-13';
123
+ */
124
+ set lastModified(val: string | Date | undefined);
125
+ /**
126
+ * Get the Last-Modified date in Date form, if it exists.
127
+ */
128
+ get lastModified(): Date | undefined;
129
+ /**
130
+ * Set the ETag of a response.
131
+ * This will normalize the quotes if necessary.
132
+ *
133
+ * this.response.etag = 'md5-hash-sum';
134
+ * this.response.etag = '"md5-hash-sum"';
135
+ * this.response.etag = 'W/"123456789"';
136
+ */
137
+ set etag(val: string);
138
+ /**
139
+ * Get the ETag of a response.
140
+ */
141
+ get etag(): string;
142
+ /**
143
+ * Return response header.
144
+ *
145
+ * Examples:
146
+ *
147
+ * this.get('Content-Type');
148
+ * // => "text/plain"
149
+ *
150
+ * this.get('content-type');
151
+ * // => "text/plain"
152
+ */
153
+ get<T = string | string[] | number>(field: string): T;
154
+ /**
155
+ * Returns true if the header identified by name is currently set in the outgoing headers.
156
+ * The header name matching is case-insensitive.
157
+ *
158
+ * Examples:
159
+ *
160
+ * this.has('Content-Type');
161
+ * // => true
162
+ *
163
+ * this.get('content-type');
164
+ * // => true
165
+ */
166
+ has(field: string): boolean;
167
+ /**
168
+ * Set header `field` to `val` or pass
169
+ * an object of header fields.
170
+ *
171
+ * Examples:
172
+ *
173
+ * this.set('Foo', ['bar', 'baz']);
174
+ * this.set('Accept', 'application/json');
175
+ * this.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
176
+ */
177
+ set(field: string | Record<string, string>, val?: string | number | unknown[]): void;
178
+ /**
179
+ * Append additional header `field` with value `val`.
180
+ *
181
+ * Examples:
182
+ *
183
+ * ```
184
+ * this.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
185
+ * this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
186
+ * this.append('Warning', '199 Miscellaneous warning');
187
+ */
188
+ append(field: string, val: string | string[]): void;
189
+ /**
190
+ * Remove header `field`.
191
+ */
192
+ remove(field: string): void;
193
+ /**
194
+ * Checks if the request is writable.
195
+ * Tests for the existence of the socket
196
+ * as node sometimes does not set it.
197
+ */
198
+ get writable(): boolean;
199
+ /**
200
+ * Inspect implementation.
201
+ */
202
+ inspect(): object | undefined;
203
+ /**
204
+ * Return JSON representation.
205
+ */
206
+ toJSON(): object;
207
+ /**
208
+ * Flush any set headers and begin the body
209
+ */
210
+ flushHeaders(): void;
229
211
  }
230
- //#endregion
231
- export { Response };