@eggjs/koa 3.1.0-beta.9 → 3.1.2-beta.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.
- package/dist/application.d.ts +51 -65
- package/dist/application.js +25 -14
- package/dist/context.d.ts +56 -122
- package/dist/context.js +4 -12
- package/dist/request.d.ts +211 -229
- package/dist/request.js +3 -8
- package/dist/response.d.ts +140 -156
- package/dist/response.js +6 -9
- package/package.json +33 -39
package/dist/response.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { Request } from "./request.js";
|
|
2
2
|
import { Context } from "./context.js";
|
|
3
3
|
import { Application } from "./application.js";
|
|
4
|
-
import
|
|
4
|
+
import { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from "node:http";
|
|
5
5
|
import Stream from "node:stream";
|
|
6
|
-
import { IncomingMessage, ServerResponse } from "node:http";
|
|
7
6
|
import { Options } from "content-disposition";
|
|
8
|
-
import * as http6 from "http";
|
|
9
|
-
import * as net0 from "net";
|
|
10
7
|
|
|
11
8
|
//#region src/response.d.ts
|
|
12
9
|
declare class Response {
|
|
@@ -18,213 +15,200 @@ declare class Response {
|
|
|
18
15
|
request: Request;
|
|
19
16
|
constructor(app: Application, ctx: Context, req: IncomingMessage, res: ServerResponse);
|
|
20
17
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
get socket():
|
|
18
|
+
* Return the request socket.
|
|
19
|
+
*/
|
|
20
|
+
get socket(): ServerResponse["socket"];
|
|
24
21
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
get header():
|
|
22
|
+
* Return response header.
|
|
23
|
+
*/
|
|
24
|
+
get header(): OutgoingHttpHeaders;
|
|
28
25
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
get headers():
|
|
26
|
+
* Return response header, alias as response.header
|
|
27
|
+
*/
|
|
28
|
+
get headers(): OutgoingHttpHeaders;
|
|
32
29
|
_explicitStatus: boolean;
|
|
33
30
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
* Get response status code.
|
|
32
|
+
*/
|
|
36
33
|
get status(): number;
|
|
37
34
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
* Set response status code.
|
|
36
|
+
*/
|
|
40
37
|
set status(code: number);
|
|
41
38
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
* Get response status message
|
|
40
|
+
*/
|
|
44
41
|
get message(): string;
|
|
45
42
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
* Set response status message
|
|
44
|
+
*/
|
|
48
45
|
set message(msg: string);
|
|
49
46
|
_body: any;
|
|
50
47
|
_explicitNullBody: boolean;
|
|
51
48
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
* Get response body.
|
|
50
|
+
*/
|
|
54
51
|
get body(): string | Buffer | object | Stream | null | undefined | boolean;
|
|
55
52
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
* Set response body.
|
|
54
|
+
*/
|
|
58
55
|
set body(val: string | Buffer | object | Stream | null | undefined | boolean);
|
|
59
56
|
/**
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
* Set Content-Length field to `n`.
|
|
58
|
+
*/
|
|
62
59
|
set length(n: number | string | undefined);
|
|
63
60
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
* Return parsed response Content-Length when present.
|
|
62
|
+
*
|
|
63
|
+
* When Content-Length is not defined it will return `undefined`.
|
|
64
|
+
*/
|
|
68
65
|
get length(): number | undefined;
|
|
69
66
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
* Check if a header has been written to the socket.
|
|
68
|
+
*/
|
|
72
69
|
get headerSent(): boolean;
|
|
73
70
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
* Vary on `field`.
|
|
72
|
+
*/
|
|
76
73
|
vary(field: string): void;
|
|
77
|
-
_getBackReferrer(): string | undefined;
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
74
|
+
protected _getBackReferrer(): string | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Perform a 302 redirect to `url`.
|
|
77
|
+
*
|
|
78
|
+
* The string "back" is special-cased
|
|
79
|
+
* to provide Referrer support, when Referrer
|
|
80
|
+
* is not present `alt` or "/" is used.
|
|
81
|
+
*
|
|
82
|
+
* Examples:
|
|
83
|
+
*
|
|
84
|
+
* this.redirect('back');
|
|
85
|
+
* this.redirect('back', '/index.html');
|
|
86
|
+
* this.redirect('/login');
|
|
87
|
+
* this.redirect('http://google.com'); // will format to 'http://google.com/'
|
|
88
|
+
*/
|
|
92
89
|
redirect(url: string, alt?: string): void;
|
|
93
90
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
* Set Content-Disposition header to "attachment" with optional `filename`.
|
|
92
|
+
*/
|
|
96
93
|
attachment(filename?: string, options?: Options): void;
|
|
97
94
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
* Set Content-Type response header with `type` through `mime.lookup()`
|
|
96
|
+
* when it does not contain a charset.
|
|
97
|
+
*
|
|
98
|
+
* Examples:
|
|
99
|
+
*
|
|
100
|
+
* this.type = '.html';
|
|
101
|
+
* this.type = 'html';
|
|
102
|
+
* this.type = 'json';
|
|
103
|
+
* this.type = 'application/json';
|
|
104
|
+
* this.type = 'png';
|
|
105
|
+
*/
|
|
109
106
|
set type(type: string | null | undefined);
|
|
110
107
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
* Return the response mime type void of
|
|
109
|
+
* parameters such as "charset".
|
|
110
|
+
*/
|
|
114
111
|
get type(): string;
|
|
115
112
|
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
* Check whether the response is one of the listed types.
|
|
114
|
+
* Pretty much the same as `this.request.is()`.
|
|
115
|
+
*
|
|
116
|
+
* this.response.is('html')
|
|
117
|
+
* this.response.is('html', 'json')
|
|
118
|
+
*/
|
|
122
119
|
is(type?: string | string[], ...types: string[]): string | false;
|
|
123
120
|
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
121
|
+
* Set the Last-Modified date using a string or a Date.
|
|
122
|
+
*
|
|
123
|
+
* this.response.lastModified = new Date();
|
|
124
|
+
* this.response.lastModified = '2013-09-13';
|
|
125
|
+
*/
|
|
129
126
|
set lastModified(val: string | Date | undefined);
|
|
130
127
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
* Get the Last-Modified date in Date form, if it exists.
|
|
129
|
+
*/
|
|
133
130
|
get lastModified(): Date | undefined;
|
|
134
131
|
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
* Set the ETag of a response.
|
|
133
|
+
* This will normalize the quotes if necessary.
|
|
134
|
+
*
|
|
135
|
+
* this.response.etag = 'md5-hash-sum';
|
|
136
|
+
* this.response.etag = '"md5-hash-sum"';
|
|
137
|
+
* this.response.etag = 'W/"123456789"';
|
|
138
|
+
*/
|
|
142
139
|
set etag(val: string);
|
|
143
140
|
/**
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
* Get the ETag of a response.
|
|
142
|
+
*/
|
|
146
143
|
get etag(): string;
|
|
147
144
|
/**
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
145
|
+
* Return response header.
|
|
146
|
+
*
|
|
147
|
+
* Examples:
|
|
148
|
+
*
|
|
149
|
+
* this.get('Content-Type');
|
|
150
|
+
* // => "text/plain"
|
|
151
|
+
*
|
|
152
|
+
* this.get('content-type');
|
|
153
|
+
* // => "text/plain"
|
|
154
|
+
*/
|
|
158
155
|
get<T = string | string[] | number>(field: string): T;
|
|
159
156
|
/**
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
157
|
+
* Returns true if the header identified by name is currently set in the outgoing headers.
|
|
158
|
+
* The header name matching is case-insensitive.
|
|
159
|
+
*
|
|
160
|
+
* Examples:
|
|
161
|
+
*
|
|
162
|
+
* this.has('Content-Type');
|
|
163
|
+
* // => true
|
|
164
|
+
*
|
|
165
|
+
* this.get('content-type');
|
|
166
|
+
* // => true
|
|
167
|
+
*/
|
|
171
168
|
has(field: string): boolean;
|
|
172
169
|
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
170
|
+
* Set header `field` to `val` or pass
|
|
171
|
+
* an object of header fields.
|
|
172
|
+
*
|
|
173
|
+
* Examples:
|
|
174
|
+
*
|
|
175
|
+
* this.set('Foo', ['bar', 'baz']);
|
|
176
|
+
* this.set('Accept', 'application/json');
|
|
177
|
+
* this.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
178
|
+
*/
|
|
182
179
|
set(field: string | Record<string, string>, val?: string | number | unknown[]): void;
|
|
183
180
|
/**
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
181
|
+
* Append additional header `field` with value `val`.
|
|
182
|
+
*
|
|
183
|
+
* Examples:
|
|
184
|
+
*
|
|
185
|
+
* ```
|
|
186
|
+
* this.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
|
|
187
|
+
* this.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
|
|
188
|
+
* this.append('Warning', '199 Miscellaneous warning');
|
|
189
|
+
*/
|
|
193
190
|
append(field: string, val: string | string[]): void;
|
|
194
191
|
/**
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
* Remove header `field`.
|
|
193
|
+
*/
|
|
197
194
|
remove(field: string): void;
|
|
198
195
|
/**
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
196
|
+
* Checks if the request is writable.
|
|
197
|
+
* Tests for the existence of the socket
|
|
198
|
+
* as node sometimes does not set it.
|
|
199
|
+
*/
|
|
203
200
|
get writable(): boolean;
|
|
204
201
|
/**
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
inspect():
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
header: http6.OutgoingHttpHeaders;
|
|
216
|
-
} | undefined;
|
|
217
|
-
/**
|
|
218
|
-
* Return JSON representation.
|
|
219
|
-
*/
|
|
220
|
-
toJSON(): {
|
|
221
|
-
status: number;
|
|
222
|
-
message: string;
|
|
223
|
-
header: http6.OutgoingHttpHeaders;
|
|
224
|
-
};
|
|
225
|
-
/**
|
|
226
|
-
* Flush any set headers and begin the body
|
|
227
|
-
*/
|
|
202
|
+
* Inspect implementation.
|
|
203
|
+
*/
|
|
204
|
+
inspect(): object | undefined;
|
|
205
|
+
/**
|
|
206
|
+
* Return JSON representation.
|
|
207
|
+
*/
|
|
208
|
+
toJSON(): object;
|
|
209
|
+
/**
|
|
210
|
+
* Flush any set headers and begin the body
|
|
211
|
+
*/
|
|
228
212
|
flushHeaders(): void;
|
|
229
213
|
}
|
|
230
214
|
//#endregion
|
package/dist/response.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import util from "node:util";
|
|
2
1
|
import Stream from "node:stream";
|
|
2
|
+
import util from "node:util";
|
|
3
3
|
import onFinished from "on-finished";
|
|
4
4
|
import statuses from "statuses";
|
|
5
5
|
import { is } from "type-is";
|
|
6
6
|
import assert from "node:assert";
|
|
7
7
|
import { extname } from "node:path";
|
|
8
|
-
import contentDisposition from "content-disposition";
|
|
9
8
|
import { getType } from "cache-content-type";
|
|
10
|
-
import
|
|
9
|
+
import contentDisposition from "content-disposition";
|
|
11
10
|
import destroy from "destroy";
|
|
12
|
-
import vary from "vary";
|
|
13
11
|
import encodeUrl from "encodeurl";
|
|
12
|
+
import escape from "escape-html";
|
|
13
|
+
import vary from "vary";
|
|
14
14
|
|
|
15
15
|
//#region src/response.ts
|
|
16
16
|
var Response = class {
|
|
@@ -24,6 +24,7 @@ var Response = class {
|
|
|
24
24
|
this.req = req;
|
|
25
25
|
this.res = res;
|
|
26
26
|
this.ctx = ctx;
|
|
27
|
+
this[util.inspect.custom] = this.inspect.bind(this);
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Return the request socket.
|
|
@@ -35,7 +36,7 @@ var Response = class {
|
|
|
35
36
|
* Return response header.
|
|
36
37
|
*/
|
|
37
38
|
get header() {
|
|
38
|
-
return this.res.getHeaders()
|
|
39
|
+
return this.res.getHeaders() ?? {};
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* Return response header, alias as response.header
|
|
@@ -156,7 +157,6 @@ var Response = class {
|
|
|
156
157
|
_getBackReferrer() {
|
|
157
158
|
const referrer = this.ctx.get("Referrer");
|
|
158
159
|
if (referrer) {
|
|
159
|
-
if (referrer.startsWith("/")) return referrer;
|
|
160
160
|
if (new URL(referrer, this.ctx.href).host === this.ctx.host) return referrer;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -362,9 +362,6 @@ var Response = class {
|
|
|
362
362
|
Reflect.set(o, "body", this.body);
|
|
363
363
|
return o;
|
|
364
364
|
}
|
|
365
|
-
[util.inspect.custom]() {
|
|
366
|
-
return this.inspect();
|
|
367
|
-
}
|
|
368
365
|
/**
|
|
369
366
|
* Return JSON representation.
|
|
370
367
|
*/
|
package/package.json
CHANGED
|
@@ -1,47 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/koa",
|
|
3
|
-
"version": "3.1.
|
|
4
|
-
"engines": {
|
|
5
|
-
"node": ">= 20.19.0"
|
|
6
|
-
},
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"type": "module",
|
|
11
|
-
"exports": {
|
|
12
|
-
".": "./dist/index.js",
|
|
13
|
-
"./package.json": "./package.json"
|
|
14
|
-
},
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"files": [
|
|
17
|
-
"dist"
|
|
18
|
-
],
|
|
19
|
-
"main": "./dist/index.js",
|
|
20
|
-
"module": "./dist/index.js",
|
|
3
|
+
"version": "3.1.2-beta.0",
|
|
21
4
|
"description": "Koa web app framework for https://eggjs.org",
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "git://github.com/eggjs/egg.git",
|
|
25
|
-
"directory": "packages/koa"
|
|
26
|
-
},
|
|
27
|
-
"homepage": "https://github.com/eggjs/egg/tree/next/packages/koa",
|
|
28
5
|
"keywords": [
|
|
29
|
-
"web",
|
|
30
6
|
"app",
|
|
31
|
-
"http",
|
|
32
7
|
"application",
|
|
33
8
|
"framework",
|
|
9
|
+
"http",
|
|
34
10
|
"middleware",
|
|
35
|
-
"rack"
|
|
11
|
+
"rack",
|
|
12
|
+
"web"
|
|
36
13
|
],
|
|
14
|
+
"homepage": "https://github.com/eggjs/egg/tree/next/packages/koa",
|
|
37
15
|
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/eggjs/egg.git",
|
|
19
|
+
"directory": "packages/koa"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/index.js",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
38
35
|
"dependencies": {
|
|
39
36
|
"@types/content-disposition": "^0.5.8",
|
|
40
37
|
"accepts": "^1.3.8",
|
|
41
38
|
"cache-content-type": "^2.0.0",
|
|
42
|
-
"content-disposition": "~0.
|
|
39
|
+
"content-disposition": "~1.0.0",
|
|
43
40
|
"content-type": "^1.0.5",
|
|
44
|
-
"cookies": "^0.9.1",
|
|
45
41
|
"destroy": "^1.0.4",
|
|
46
42
|
"encodeurl": "^2.0.0",
|
|
47
43
|
"escape-html": "^1.0.3",
|
|
@@ -54,33 +50,31 @@
|
|
|
54
50
|
"parseurl": "^1.3.3",
|
|
55
51
|
"statuses": "^2.0.1",
|
|
56
52
|
"type-is": "^2.0.0",
|
|
57
|
-
"vary": "^1.1.2"
|
|
53
|
+
"vary": "^1.1.2",
|
|
54
|
+
"@eggjs/cookies": "4.0.2-beta.0"
|
|
58
55
|
},
|
|
59
56
|
"devDependencies": {
|
|
60
57
|
"@types/accepts": "^1.3.7",
|
|
61
58
|
"@types/content-type": "^1.1.8",
|
|
62
|
-
"@types/cookies": "^0.9.0",
|
|
63
59
|
"@types/destroy": "^1.0.3",
|
|
64
60
|
"@types/encodeurl": "^1.0.2",
|
|
65
61
|
"@types/escape-html": "^1.0.4",
|
|
66
62
|
"@types/fresh": "^0.5.2",
|
|
67
63
|
"@types/http-errors": "^2.0.4",
|
|
68
64
|
"@types/koa-compose": "^3.2.8",
|
|
69
|
-
"@types/node": "24.5.2",
|
|
70
65
|
"@types/on-finished": "^2.3.4",
|
|
71
66
|
"@types/parseurl": "^1.3.3",
|
|
72
67
|
"@types/statuses": "^2.0.5",
|
|
73
68
|
"@types/type-is": "^1.6.6",
|
|
74
69
|
"@types/vary": "^1.1.3",
|
|
75
70
|
"mm": "^4.0.2",
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
|
|
71
|
+
"typescript": "^5.9.3",
|
|
72
|
+
"@eggjs/supertest": "9.0.2-beta.0"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=22.18.0"
|
|
79
76
|
},
|
|
80
77
|
"scripts": {
|
|
81
|
-
"
|
|
82
|
-
"typecheck": "tsc --noEmit",
|
|
83
|
-
"lint": "oxlint --type-aware",
|
|
84
|
-
"test": "vitest run"
|
|
78
|
+
"typecheck": "tsgo --noEmit"
|
|
85
79
|
}
|
|
86
80
|
}
|