@eggjs/koa 3.1.0-beta.20 → 3.1.0-beta.22

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