koa 2.11.0 → 2.13.1
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/History.md +55 -0
- package/Readme.md +1 -38
- package/dist/koa.mjs +4 -0
- package/lib/application.js +28 -7
- package/lib/context.js +13 -5
- package/lib/request.js +15 -13
- package/lib/response.js +18 -13
- package/package.json +14 -4
package/History.md
CHANGED
|
@@ -1,4 +1,59 @@
|
|
|
1
1
|
|
|
2
|
+
2.13.1 / 2021-01-04
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
**fixes**
|
|
6
|
+
* [[`b5472f4`](http://github.com/koajs/koa/commit/b5472f4cbb87349becae36b4a9ad5f76a825abb8)] - fix: make ESM transpiled CommonJS play nice for TS folks, fix #1513 (#1518) (miwnwski <<m@iwnw.ski>>)
|
|
7
|
+
* [[`68d97d6`](http://github.com/koajs/koa/commit/68d97d69e4536065504bf9ef1e348a66b3f35709)] - fix: fixed order of vulnerability disclosure addresses (niftylettuce <<niftylettuce@gmail.com>>)
|
|
8
|
+
|
|
9
|
+
**others**
|
|
10
|
+
* [[`b4398f5`](http://github.com/koajs/koa/commit/b4398f5d68f9546167419f394a686afdcb5e10e2)] - correct verb tense in doc (#1512) (Matan Shavit <<71092861+matanshavit@users.noreply.github.com>>)
|
|
11
|
+
* [[`39e1a5a`](http://github.com/koajs/koa/commit/39e1a5a380aa2bbc4e2d164e8e4bf37cfd512516)] - fixed multiple grammatical errors in docs. (#1497) (Hridayesh Sharma <<vyasriday7@gmail.com>>)
|
|
12
|
+
* [[`aeb5d19`](http://github.com/koajs/koa/commit/aeb5d1984dcc5f8e3386f8f9724807ae6f3aa1c4)] - docs: added niftylettuce@gmail.com to vulnerability disclosure (niftylettuce <<niftylettuce@gmail.com>>)
|
|
13
|
+
* [[`6e1093b`](http://github.com/koajs/koa/commit/6e1093be27b41135c8e67fce108743d54e9cab67)] - docs: remove babel from readme (#1494) (miwnwski <<m@iwnw.ski>>)
|
|
14
|
+
* [[`38cb591`](http://github.com/koajs/koa/commit/38cb591254ff5f65a04e8fb57be293afe697c46e)] - docs: update specific for auto response status (AlbertAZ1992 <<ziyuximing@163.com>>)
|
|
15
|
+
* [[`2224cd9`](http://github.com/koajs/koa/commit/2224cd9b6a648e7ac2eb27eac332e7d6de7db26c)] - docs: remove babel ref. (#1488) (Imed Jaberi <<imed_jebari@hotmail.fr>>)
|
|
16
|
+
* [[`d51f983`](http://github.com/koajs/koa/commit/d51f98328c3b84493cc6bda0732aabb69e20e3a1)] - docs: fix assert example for response (#1489) (Imed Jaberi <<imed_jebari@hotmail.fr>>)
|
|
17
|
+
* [[`f8b49b8`](http://github.com/koajs/koa/commit/f8b49b859363ad6c3d9ea5c11ee62341407ceafd)] - chore: fix grammatical and spelling errors in comments and tests (#1490) (Matt Kubej <<mkubej@gmail.com>>)
|
|
18
|
+
* [[`d1c9263`](http://github.com/koajs/koa/commit/d1c92638c95d799df2fdff5576b96fc43a62813f)] - deps: update depd >> v2.0.0 (#1482) (imed jaberi <<imed_jebari@hotmail.fr>>)
|
|
19
|
+
|
|
20
|
+
2.13.0 / 2020-06-21
|
|
21
|
+
==================
|
|
22
|
+
|
|
23
|
+
**features**
|
|
24
|
+
* [[`bbcde76`](http://github.com/koajs/koa/commit/bbcde76f5cb5b67bbcd3201791cf0ef648fd3a8b)] - feat: support esm (#1474) (ZYSzys <<zhangyongsheng@youzan.com>>)
|
|
25
|
+
|
|
26
|
+
**others**
|
|
27
|
+
* [[`20e58cf`](http://github.com/koajs/koa/commit/20e58cf3e4f20fc5d5886df1d0ac6dd8c33bd202)] - test: imporve coverage to 100% (dead-horse <<dead_horse@qq.com>>)
|
|
28
|
+
* [[`4a40d63`](http://github.com/koajs/koa/commit/4a40d633c4b4a203c6656078f9952ccef65c5875)] - build: use prepare instead of prepublish (dead-horse <<dead_horse@qq.com>>)
|
|
29
|
+
* [[`226ba8c`](http://github.com/koajs/koa/commit/226ba8c8e81e83da48e7bf137be3f146d03f40b8)] - build: use prepublish instead of prepack (dead-horse <<dead_horse@qq.com>>)
|
|
30
|
+
|
|
31
|
+
2.12.1 / 2020-06-13
|
|
32
|
+
==================
|
|
33
|
+
|
|
34
|
+
**fixes**
|
|
35
|
+
* [[`e2030c7`](http://github.com/koajs/koa/commit/e2030c7249c7ae24e28158d8eae405a02fefc9f8)] - fix: Improve checks for Error in onerror handlers (#1468) (Julien Wajsberg <<felash@gmail.com>>)
|
|
36
|
+
|
|
37
|
+
**others**
|
|
38
|
+
* [[`5208c5e`](http://github.com/koajs/koa/commit/5208c5e15d35b3653fce6b8ed68d09865abea843)] - chore: Use single console.error() statement in error handler (#1471) (Mike Vosseller <<michael.vosseller@gmail.com>>)
|
|
39
|
+
|
|
40
|
+
2.12.0 / 2020-05-18
|
|
41
|
+
==================
|
|
42
|
+
|
|
43
|
+
**features**
|
|
44
|
+
* [[`0d2f421`](http://github.com/koajs/koa/commit/0d2f421c265350d3d84e1bc261572954479f27d3)] - feat: error handler treat err.statusCode as the same as err.status (#1460) (Vijay Krishnavanshi <<vijaykrishnavanshi@gmail.com>>)
|
|
45
|
+
* [[`8d52105`](http://github.com/koajs/koa/commit/8d52105a34234be9e771ff3b76b43e4e30328943)] - feat: allow bodyless responses for non empty status codes (#1447) (ejose19 <<8742215+ejose19@users.noreply.github.com>>)
|
|
46
|
+
|
|
47
|
+
**others**
|
|
48
|
+
* [[`faeaff5`](http://github.com/koajs/koa/commit/faeaff5c149a81a188ab8e5af0b994029e45acbb)] - fox: remove `error-inject` and fix error handling (#1409) (Konstantin Vyatkin <<tino@vtkn.io>>)
|
|
49
|
+
* [[`f7c732f`](http://github.com/koajs/koa/commit/f7c732fd06f724505e9090add4d977e667da55a8)] - docs: fixed incorrect onerror example (#1459) (Paul Annekov <<paul.annekov@gmail.com>>)
|
|
50
|
+
* [[`143d8f7`](http://github.com/koajs/koa/commit/143d8f72f2a232b4c97eac00e7811015911e4f7c)] - Always use strict equality. (#1225) (Yazan Medanat <<medanat@gmail.com>>)
|
|
51
|
+
* [[`6b6b0dd`](http://github.com/koajs/koa/commit/6b6b0ddf7aff073e65493c6efaffab8331c0331c)] - docs(api): add app.use chainability note (#1449) (Zac Anger <<zac@zacanger.com>>)
|
|
52
|
+
* [[`8ddab48`](http://github.com/koajs/koa/commit/8ddab48cbdbca1e6d1cc8c3ddae45491db524d51)] - docs: Document response status with empty body (#1445) (Marc-Aurèle DARCHE <<152407+madarche@users.noreply.github.com>>)
|
|
53
|
+
* [[`7deedb2`](http://github.com/koajs/koa/commit/7deedb235274223f1b9da46dee296545b23598de)] - docs: Updating context.md with the latest cookies opts (#1433) (Brad Ito <<phlogisticfugu@users.noreply.github.com>>)
|
|
54
|
+
* [[`3e97a10`](http://github.com/koajs/koa/commit/3e97a106bb846d9337737011bb85149ddd797229)] - docs(links): remove Google+ link (#1439) (laffachan <<45162759+laffachan@users.noreply.github.com>>)
|
|
55
|
+
* [[`eda2760`](http://github.com/koajs/koa/commit/eda27608f7d39ede86d7b402aae64b1867ce31c6)] - build: Drop unused Travis sudo: false directive (#1416) (Olle Jonsson <<olle.jonsson@gmail.com>>)
|
|
56
|
+
|
|
2
57
|
2.11.0 / 2019-10-28
|
|
3
58
|
==================
|
|
4
59
|
|
package/Readme.md
CHANGED
|
@@ -160,40 +160,6 @@ Learn more about the application object in the [Application API Reference](docs/
|
|
|
160
160
|
- [FAQ](docs/faq.md)
|
|
161
161
|
- [API documentation](docs/api/index.md)
|
|
162
162
|
|
|
163
|
-
## Babel setup
|
|
164
|
-
|
|
165
|
-
If you're not using `node v7.6+`, we recommend setting up `babel` with [`@babel/preset-env`](https://babeljs.io/docs/en/next/babel-preset-env):
|
|
166
|
-
|
|
167
|
-
```bash
|
|
168
|
-
$ npm install @babel/register @babel/preset-env @babel/cli --save-dev
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
In development, you'll want to use [`@babel/register`](https://babeljs.io/docs/en/next/babel-register):
|
|
172
|
-
|
|
173
|
-
```bash
|
|
174
|
-
node --require @babel/register <your-entry-file>
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
In production, you'll want to build your files with [`@babel/cli`](https://babeljs.io/docs/en/babel-cli). Suppose you are compiling a folder `src` and you wanted the output to go to a new folder `dist` with non-javascript files copied:
|
|
178
|
-
|
|
179
|
-
```bash
|
|
180
|
-
babel src --out-dir dist --copy-files
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
And have your `.babelrc` setup:
|
|
184
|
-
|
|
185
|
-
```json
|
|
186
|
-
{
|
|
187
|
-
"presets": [
|
|
188
|
-
["@babel/preset-env", {
|
|
189
|
-
"targets": {
|
|
190
|
-
"node": true
|
|
191
|
-
}
|
|
192
|
-
}]
|
|
193
|
-
]
|
|
194
|
-
}
|
|
195
|
-
```
|
|
196
|
-
|
|
197
163
|
## Troubleshooting
|
|
198
164
|
|
|
199
165
|
Check the [Troubleshooting Guide](docs/troubleshooting.md) or [Debugging Koa](docs/guide.md#debugging-koa) in
|
|
@@ -207,9 +173,7 @@ $ npm test
|
|
|
207
173
|
|
|
208
174
|
## Reporting vulnerabilities
|
|
209
175
|
|
|
210
|
-
To report a security vulnerability, please do not open an issue, as this notifies attackers
|
|
211
|
-
of the vulnerability. Instead, please email [dead_horse](mailto:heyiyu.deadhorse@gmail.com) and [jonathanong](mailto:me@jongleberry.com) to
|
|
212
|
-
disclose.
|
|
176
|
+
To report a security vulnerability, please do not open an issue, as this notifies attackers of the vulnerability. Instead, please email [dead_horse](mailto:heyiyu.deadhorse@gmail.com), [jonathanong](mailto:me@jongleberry.com), and [niftylettuce](mailto:niftylettuce@gmail.com) to disclose.
|
|
213
177
|
|
|
214
178
|
## Authors
|
|
215
179
|
|
|
@@ -221,7 +185,6 @@ See [AUTHORS](AUTHORS).
|
|
|
221
185
|
- [Examples](https://github.com/koajs/examples)
|
|
222
186
|
- [Middleware](https://github.com/koajs/koa/wiki) list
|
|
223
187
|
- [Wiki](https://github.com/koajs/koa/wiki)
|
|
224
|
-
- [G+ Community](https://plus.google.com/communities/101845768320796750641)
|
|
225
188
|
- [Reddit Community](https://www.reddit.com/r/koajs)
|
|
226
189
|
- [Mailing list](https://groups.google.com/forum/#!forum/koajs)
|
|
227
190
|
- [中文文档 v1.x](https://github.com/guo-yu/koa-guide)
|
package/dist/koa.mjs
ADDED
package/lib/application.js
CHANGED
|
@@ -59,6 +59,8 @@ module.exports = class Application extends Emitter {
|
|
|
59
59
|
this.context = Object.create(context);
|
|
60
60
|
this.request = Object.create(request);
|
|
61
61
|
this.response = Object.create(response);
|
|
62
|
+
// util.inspect.custom support for node 6+
|
|
63
|
+
/* istanbul ignore else */
|
|
62
64
|
if (util.inspect.custom) {
|
|
63
65
|
this[util.inspect.custom] = this.inspect;
|
|
64
66
|
}
|
|
@@ -195,15 +197,28 @@ module.exports = class Application extends Emitter {
|
|
|
195
197
|
*/
|
|
196
198
|
|
|
197
199
|
onerror(err) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
// When dealing with cross-globals a normal `instanceof` check doesn't work properly.
|
|
201
|
+
// See https://github.com/koajs/koa/issues/1466
|
|
202
|
+
// We can probably remove it once jest fixes https://github.com/facebook/jest/issues/2549.
|
|
203
|
+
const isNativeError =
|
|
204
|
+
Object.prototype.toString.call(err) === '[object Error]' ||
|
|
205
|
+
err instanceof Error;
|
|
206
|
+
if (!isNativeError) throw new TypeError(util.format('non-error thrown: %j', err));
|
|
207
|
+
|
|
208
|
+
if (404 === err.status || err.expose) return;
|
|
201
209
|
if (this.silent) return;
|
|
202
210
|
|
|
203
211
|
const msg = err.stack || err.toString();
|
|
204
|
-
console.error();
|
|
205
|
-
|
|
206
|
-
|
|
212
|
+
console.error(`\n${msg.replace(/^/gm, ' ')}\n`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Help TS users comply to CommonJS, ESM, bundler mismatch.
|
|
217
|
+
* @see https://github.com/koajs/koa/issues/1513
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
static get default() {
|
|
221
|
+
return Application;
|
|
207
222
|
}
|
|
208
223
|
};
|
|
209
224
|
|
|
@@ -238,6 +253,11 @@ function respond(ctx) {
|
|
|
238
253
|
|
|
239
254
|
// status body
|
|
240
255
|
if (null == body) {
|
|
256
|
+
if (ctx.response._explicitNullBody) {
|
|
257
|
+
ctx.response.remove('Content-Type');
|
|
258
|
+
ctx.response.remove('Transfer-Encoding');
|
|
259
|
+
return res.end();
|
|
260
|
+
}
|
|
241
261
|
if (ctx.req.httpVersionMajor >= 2) {
|
|
242
262
|
body = String(code);
|
|
243
263
|
} else {
|
|
@@ -252,7 +272,7 @@ function respond(ctx) {
|
|
|
252
272
|
|
|
253
273
|
// responses
|
|
254
274
|
if (Buffer.isBuffer(body)) return res.end(body);
|
|
255
|
-
if ('string'
|
|
275
|
+
if ('string' === typeof body) return res.end(body);
|
|
256
276
|
if (body instanceof Stream) return body.pipe(res);
|
|
257
277
|
|
|
258
278
|
// body: json
|
|
@@ -267,4 +287,5 @@ function respond(ctx) {
|
|
|
267
287
|
* Make HttpError available to consumers of the library so that consumers don't
|
|
268
288
|
* have a direct dependency upon `http-errors`
|
|
269
289
|
*/
|
|
290
|
+
|
|
270
291
|
module.exports.HttpError = HttpError;
|
package/lib/context.js
CHANGED
|
@@ -110,7 +110,13 @@ const proto = module.exports = {
|
|
|
110
110
|
// to node-style callbacks.
|
|
111
111
|
if (null == err) return;
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
// When dealing with cross-globals a normal `instanceof` check doesn't work properly.
|
|
114
|
+
// See https://github.com/koajs/koa/issues/1466
|
|
115
|
+
// We can probably remove it once jest fixes https://github.com/facebook/jest/issues/2549.
|
|
116
|
+
const isNativeError =
|
|
117
|
+
Object.prototype.toString.call(err) === '[object Error]' ||
|
|
118
|
+
err instanceof Error;
|
|
119
|
+
if (!isNativeError) err = new Error(util.format('non-error thrown: %j', err));
|
|
114
120
|
|
|
115
121
|
let headerSent = false;
|
|
116
122
|
if (this.headerSent || !this.writable) {
|
|
@@ -143,16 +149,18 @@ const proto = module.exports = {
|
|
|
143
149
|
// force text/plain
|
|
144
150
|
this.type = 'text';
|
|
145
151
|
|
|
152
|
+
let statusCode = err.status || err.statusCode;
|
|
153
|
+
|
|
146
154
|
// ENOENT support
|
|
147
|
-
if ('ENOENT'
|
|
155
|
+
if ('ENOENT' === err.code) statusCode = 404;
|
|
148
156
|
|
|
149
157
|
// default to 500
|
|
150
|
-
if ('number'
|
|
158
|
+
if ('number' !== typeof statusCode || !statuses[statusCode]) statusCode = 500;
|
|
151
159
|
|
|
152
160
|
// respond
|
|
153
|
-
const code = statuses[
|
|
161
|
+
const code = statuses[statusCode];
|
|
154
162
|
const msg = err.expose ? err.message : code;
|
|
155
|
-
this.status = err.status;
|
|
163
|
+
this.status = err.status = statusCode;
|
|
156
164
|
this.length = Buffer.byteLength(msg);
|
|
157
165
|
res.end(msg);
|
|
158
166
|
},
|
package/lib/request.js
CHANGED
|
@@ -146,7 +146,7 @@ module.exports = {
|
|
|
146
146
|
},
|
|
147
147
|
|
|
148
148
|
/**
|
|
149
|
-
* Set pathname, retaining the query
|
|
149
|
+
* Set pathname, retaining the query string when present.
|
|
150
150
|
*
|
|
151
151
|
* @param {String} path
|
|
152
152
|
* @api public
|
|
@@ -163,7 +163,7 @@ module.exports = {
|
|
|
163
163
|
},
|
|
164
164
|
|
|
165
165
|
/**
|
|
166
|
-
* Get parsed query
|
|
166
|
+
* Get parsed query string.
|
|
167
167
|
*
|
|
168
168
|
* @return {Object}
|
|
169
169
|
* @api public
|
|
@@ -176,7 +176,7 @@ module.exports = {
|
|
|
176
176
|
},
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
|
-
* Set query
|
|
179
|
+
* Set query string as an object.
|
|
180
180
|
*
|
|
181
181
|
* @param {Object} obj
|
|
182
182
|
* @api public
|
|
@@ -199,7 +199,7 @@ module.exports = {
|
|
|
199
199
|
},
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
|
-
* Set
|
|
202
|
+
* Set query string.
|
|
203
203
|
*
|
|
204
204
|
* @param {String} str
|
|
205
205
|
* @api public
|
|
@@ -216,7 +216,7 @@ module.exports = {
|
|
|
216
216
|
},
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
|
-
* Get the search string. Same as the
|
|
219
|
+
* Get the search string. Same as the query string
|
|
220
220
|
* except it includes the leading ?.
|
|
221
221
|
*
|
|
222
222
|
* @return {String}
|
|
@@ -272,7 +272,7 @@ module.exports = {
|
|
|
272
272
|
get hostname() {
|
|
273
273
|
const host = this.host;
|
|
274
274
|
if (!host) return '';
|
|
275
|
-
if ('['
|
|
275
|
+
if ('[' === host[0]) return this.URL.hostname || ''; // IPv6
|
|
276
276
|
return host.split(':', 1)[0];
|
|
277
277
|
},
|
|
278
278
|
|
|
@@ -311,10 +311,10 @@ module.exports = {
|
|
|
311
311
|
const s = this.ctx.status;
|
|
312
312
|
|
|
313
313
|
// GET or HEAD for weak freshness validation only
|
|
314
|
-
if ('GET'
|
|
314
|
+
if ('GET' !== method && 'HEAD' !== method) return false;
|
|
315
315
|
|
|
316
316
|
// 2xx or 304 as per rfc2616 14.26
|
|
317
|
-
if ((s >= 200 && s < 300) || 304
|
|
317
|
+
if ((s >= 200 && s < 300) || 304 === s) {
|
|
318
318
|
return fresh(this.header, this.response.header);
|
|
319
319
|
}
|
|
320
320
|
|
|
@@ -382,7 +382,7 @@ module.exports = {
|
|
|
382
382
|
|
|
383
383
|
get length() {
|
|
384
384
|
const len = this.get('Content-Length');
|
|
385
|
-
if (len
|
|
385
|
+
if (len === '') return;
|
|
386
386
|
return ~~len;
|
|
387
387
|
},
|
|
388
388
|
|
|
@@ -406,7 +406,7 @@ module.exports = {
|
|
|
406
406
|
},
|
|
407
407
|
|
|
408
408
|
/**
|
|
409
|
-
*
|
|
409
|
+
* Shorthand for:
|
|
410
410
|
*
|
|
411
411
|
* this.protocol == 'https'
|
|
412
412
|
*
|
|
@@ -415,14 +415,14 @@ module.exports = {
|
|
|
415
415
|
*/
|
|
416
416
|
|
|
417
417
|
get secure() {
|
|
418
|
-
return 'https'
|
|
418
|
+
return 'https' === this.protocol;
|
|
419
419
|
},
|
|
420
420
|
|
|
421
421
|
/**
|
|
422
422
|
* When `app.proxy` is `true`, parse
|
|
423
423
|
* the "X-Forwarded-For" ip address list.
|
|
424
424
|
*
|
|
425
|
-
* For example if the value
|
|
425
|
+
* For example if the value was "client, proxy1, proxy2"
|
|
426
426
|
* you would receive the array `["client", "proxy1", "proxy2"]`
|
|
427
427
|
* where "proxy2" is the furthest down-stream.
|
|
428
428
|
*
|
|
@@ -495,6 +495,7 @@ module.exports = {
|
|
|
495
495
|
* @return {Object}
|
|
496
496
|
* @api private
|
|
497
497
|
*/
|
|
498
|
+
|
|
498
499
|
get accept() {
|
|
499
500
|
return this._accept || (this._accept = accepts(this.req));
|
|
500
501
|
},
|
|
@@ -505,6 +506,7 @@ module.exports = {
|
|
|
505
506
|
* @param {Object}
|
|
506
507
|
* @api private
|
|
507
508
|
*/
|
|
509
|
+
|
|
508
510
|
set accept(obj) {
|
|
509
511
|
this._accept = obj;
|
|
510
512
|
},
|
|
@@ -607,7 +609,7 @@ module.exports = {
|
|
|
607
609
|
|
|
608
610
|
/**
|
|
609
611
|
* Check if the incoming request contains the "Content-Type"
|
|
610
|
-
* header field
|
|
612
|
+
* header field and if it contains any of the given mime `type`s.
|
|
611
613
|
* If there is no request body, `null` is returned.
|
|
612
614
|
* If there is no content type, `false` is returned.
|
|
613
615
|
* Otherwise, it returns the first `type` that matches.
|
package/lib/response.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const contentDisposition = require('content-disposition');
|
|
9
|
-
const ensureErrorHandler = require('error-inject');
|
|
10
9
|
const getType = require('cache-content-type');
|
|
11
10
|
const onFinish = require('on-finished');
|
|
12
11
|
const escape = require('escape-html');
|
|
@@ -139,6 +138,7 @@ module.exports = {
|
|
|
139
138
|
// no content
|
|
140
139
|
if (null == val) {
|
|
141
140
|
if (!statuses.empty[this.status]) this.status = 204;
|
|
141
|
+
if (val === null) this._explicitNullBody = true;
|
|
142
142
|
this.remove('Content-Type');
|
|
143
143
|
this.remove('Content-Length');
|
|
144
144
|
this.remove('Transfer-Encoding');
|
|
@@ -152,7 +152,7 @@ module.exports = {
|
|
|
152
152
|
const setType = !this.has('Content-Type');
|
|
153
153
|
|
|
154
154
|
// string
|
|
155
|
-
if ('string'
|
|
155
|
+
if ('string' === typeof val) {
|
|
156
156
|
if (setType) this.type = /^\s*</.test(val) ? 'html' : 'text';
|
|
157
157
|
this.length = Buffer.byteLength(val);
|
|
158
158
|
return;
|
|
@@ -166,12 +166,13 @@ module.exports = {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// stream
|
|
169
|
-
if (
|
|
169
|
+
if (val instanceof Stream) {
|
|
170
170
|
onFinish(this.res, destroy.bind(null, val));
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
if (original != val) {
|
|
172
|
+
val.once('error', err => this.ctx.onerror(err));
|
|
173
|
+
// overwriting
|
|
174
|
+
if (null != original) this.remove('Content-Length');
|
|
175
|
+
}
|
|
175
176
|
|
|
176
177
|
if (setType) this.type = 'bin';
|
|
177
178
|
return;
|
|
@@ -257,7 +258,7 @@ module.exports = {
|
|
|
257
258
|
|
|
258
259
|
redirect(url, alt) {
|
|
259
260
|
// location
|
|
260
|
-
if ('back'
|
|
261
|
+
if ('back' === url) url = this.ctx.get('Referrer') || alt || '/';
|
|
261
262
|
this.set('Location', encodeUrl(url));
|
|
262
263
|
|
|
263
264
|
// status
|
|
@@ -324,7 +325,7 @@ module.exports = {
|
|
|
324
325
|
*/
|
|
325
326
|
|
|
326
327
|
set lastModified(val) {
|
|
327
|
-
if ('string'
|
|
328
|
+
if ('string' === typeof val) val = new Date(val);
|
|
328
329
|
this.set('Last-Modified', val.toUTCString());
|
|
329
330
|
},
|
|
330
331
|
|
|
@@ -432,6 +433,7 @@ module.exports = {
|
|
|
432
433
|
* @return {boolean}
|
|
433
434
|
* @api public
|
|
434
435
|
*/
|
|
436
|
+
|
|
435
437
|
has(field) {
|
|
436
438
|
return typeof this.res.hasHeader === 'function'
|
|
437
439
|
? this.res.hasHeader(field)
|
|
@@ -440,7 +442,7 @@ module.exports = {
|
|
|
440
442
|
},
|
|
441
443
|
|
|
442
444
|
/**
|
|
443
|
-
* Set header `field` to `val
|
|
445
|
+
* Set header `field` to `val` or pass
|
|
444
446
|
* an object of header fields.
|
|
445
447
|
*
|
|
446
448
|
* Examples:
|
|
@@ -457,7 +459,7 @@ module.exports = {
|
|
|
457
459
|
set(field, val) {
|
|
458
460
|
if (this.headerSent) return;
|
|
459
461
|
|
|
460
|
-
if (2
|
|
462
|
+
if (2 === arguments.length) {
|
|
461
463
|
if (Array.isArray(val)) val = val.map(v => typeof v === 'string' ? v : String(v));
|
|
462
464
|
else if (typeof val !== 'string') val = String(val);
|
|
463
465
|
this.res.setHeader(field, val);
|
|
@@ -563,19 +565,22 @@ module.exports = {
|
|
|
563
565
|
},
|
|
564
566
|
|
|
565
567
|
/**
|
|
566
|
-
* Flush any set headers
|
|
568
|
+
* Flush any set headers and begin the body
|
|
567
569
|
*/
|
|
570
|
+
|
|
568
571
|
flushHeaders() {
|
|
569
572
|
this.res.flushHeaders();
|
|
570
573
|
}
|
|
571
574
|
};
|
|
572
575
|
|
|
573
576
|
/**
|
|
574
|
-
* Custom inspection implementation for
|
|
577
|
+
* Custom inspection implementation for node 6+.
|
|
575
578
|
*
|
|
576
579
|
* @return {Object}
|
|
577
580
|
* @api public
|
|
578
581
|
*/
|
|
582
|
+
|
|
583
|
+
/* istanbul ignore else */
|
|
579
584
|
if (util.inspect.custom) {
|
|
580
585
|
module.exports[util.inspect.custom] = module.exports.inspect;
|
|
581
586
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koa",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.1",
|
|
4
4
|
"description": "Koa web app framework",
|
|
5
5
|
"main": "lib/application.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"require": "./lib/application.js",
|
|
9
|
+
"import": "./dist/koa.mjs"
|
|
10
|
+
},
|
|
11
|
+
"./": "./"
|
|
12
|
+
},
|
|
6
13
|
"scripts": {
|
|
7
14
|
"test": "egg-bin test test",
|
|
8
15
|
"test-cov": "egg-bin cov test",
|
|
9
16
|
"lint": "eslint benchmarks lib test",
|
|
10
17
|
"bench": "make -C benchmarks",
|
|
11
|
-
"authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS"
|
|
18
|
+
"authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS",
|
|
19
|
+
"build": "gen-esm-wrapper . ./dist/koa.mjs",
|
|
20
|
+
"prepare": "npm run build"
|
|
12
21
|
},
|
|
13
22
|
"repository": "koajs/koa",
|
|
14
23
|
"keywords": [
|
|
@@ -29,10 +38,9 @@
|
|
|
29
38
|
"cookies": "~0.8.0",
|
|
30
39
|
"debug": "~3.1.0",
|
|
31
40
|
"delegates": "^1.0.0",
|
|
32
|
-
"depd": "^
|
|
41
|
+
"depd": "^2.0.0",
|
|
33
42
|
"destroy": "^1.0.4",
|
|
34
43
|
"encodeurl": "^1.0.2",
|
|
35
|
-
"error-inject": "^1.0.0",
|
|
36
44
|
"escape-html": "^1.0.3",
|
|
37
45
|
"fresh": "~0.5.2",
|
|
38
46
|
"http-assert": "^1.3.0",
|
|
@@ -56,6 +64,7 @@
|
|
|
56
64
|
"eslint-plugin-node": "^10.0.0",
|
|
57
65
|
"eslint-plugin-promise": "^4.2.1",
|
|
58
66
|
"eslint-plugin-standard": "^4.0.1",
|
|
67
|
+
"gen-esm-wrapper": "^1.0.6",
|
|
59
68
|
"mm": "^2.5.0",
|
|
60
69
|
"supertest": "^3.1.0"
|
|
61
70
|
},
|
|
@@ -63,6 +72,7 @@
|
|
|
63
72
|
"node": "^4.8.4 || ^6.10.1 || ^7.10.1 || >= 8.1.4"
|
|
64
73
|
},
|
|
65
74
|
"files": [
|
|
75
|
+
"dist",
|
|
66
76
|
"lib"
|
|
67
77
|
]
|
|
68
78
|
}
|