koa 2.6.1 → 2.8.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 +70 -0
- package/LICENSE +1 -1
- package/Readme.md +23 -8
- package/lib/application.js +22 -7
- package/lib/context.js +7 -6
- package/lib/request.js +7 -13
- package/lib/response.js +5 -5
- package/package.json +7 -17
package/History.md
CHANGED
|
@@ -1,4 +1,74 @@
|
|
|
1
1
|
|
|
2
|
+
2.8.1 / 2019-08-19
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
**fixes**
|
|
6
|
+
* [[`287e589`](http://github.com/koajs/koa/commit/287e589ac773d3738b2aa7d40e0b6d43dde5261b)] - fix: make options more compatibility (dead-horse <<dead_horse@qq.com>>)
|
|
7
|
+
|
|
8
|
+
2.8.0 / 2019-08-19
|
|
9
|
+
==================
|
|
10
|
+
|
|
11
|
+
**features**
|
|
12
|
+
* [[`5afff89`](http://github.com/koajs/koa/commit/5afff89eca0efe7081309dc2d123309e825df221)] - feat: accept options in the Application constructor (#1372) (Jake <<djakelambert@gmail.com>>)
|
|
13
|
+
|
|
14
|
+
**fixes**
|
|
15
|
+
* [[`ff70bdc`](http://github.com/koajs/koa/commit/ff70bdc75a30a37f63fc1f7d8cbae3204df3d982)] - fix: typo on document (#1355) (Jeff <<jeff.tian@outlook.com>>)
|
|
16
|
+
|
|
17
|
+
**others**
|
|
18
|
+
* [[`3b23865`](http://github.com/koajs/koa/commit/3b23865340cfba075f61f7dba0ea31fcc27260ec)] - docs: parameter of request.get is case-insensitive (#1373) (Gunnlaugur Thor Briem <<gunnlaugur@gmail.com>>)
|
|
19
|
+
* [[`a245d18`](http://github.com/koajs/koa/commit/a245d18a131341feec4f87659746954e78cae780)] - docs: Update response.socket (#1357) (Jeff <<jeff.tian@outlook.com>>)
|
|
20
|
+
* [[`d1d65dd`](http://github.com/koajs/koa/commit/d1d65dd29d7bbaf9ea42eaa5fcb0da3fb4df98e9)] - chore(deps): install egg-bin, mm as devDeps not deps (#1366) (Edvard Chen <<pigeon73101@gmail.com>>)
|
|
21
|
+
* [[`2c86b10`](http://github.com/koajs/koa/commit/2c86b10feafd868ebd071dda3a222e6f51972b5d)] - test: remove jest and use egg-bin(mocha) (#1363) (Yiyu He <<dead_horse@qq.com>>)
|
|
22
|
+
* [[`219bf22`](http://github.com/koajs/koa/commit/219bf22237b11bc375e2e110b93db512f1acfdd4)] - docs(context): update link (#1354) (Peng Jie <<bivinity.pengzjie@gmail.com>>)
|
|
23
|
+
* [[`52a6737`](http://github.com/koajs/koa/commit/52a673703a87a93c0f6a8552e6bd73caba66d2eb)] - chore: ignore Intellij IDEA project files (#1361) (Imon-Haque <<38266345+Imon-Haque@users.noreply.github.com>>)
|
|
24
|
+
* [[`b9e3546`](http://github.com/koajs/koa/commit/b9e35469d3bbd0a1ee92e0a815ce2512904d4a18)] - docs(api): fix keygrip link (#1350) (Peng Jie <<bivinity.pengzjie@gmail.com>>)
|
|
25
|
+
* [[`d4bdb5e`](http://github.com/koajs/koa/commit/d4bdb5ed9e2fe06ec44698b66c029f624135a0ab)] - chore: update eslint and fix lint errors (dead-horse <<dead_horse@qq.com>>)
|
|
26
|
+
* [[`12960c4`](http://github.com/koajs/koa/commit/12960c437cc25c53e682cfe5bff06d74a5bb1eb9)] - build: test on 8/10/12 (dead-horse <<dead_horse@qq.com>>)
|
|
27
|
+
* [[`00e8f7a`](http://github.com/koajs/koa/commit/00e8f7a1b7603aabdb7fb3567f485cb1c2076702)] - docs: ctx.type aliases ctx.response, not ctx.request (#1343) (Alex Berk <<berkalexanderc@gmail.com>>)
|
|
28
|
+
* [[`62f29eb`](http://github.com/koajs/koa/commit/62f29eb0c4dee01170a5511615e5bcc9faca26ca)] - docs(context): update cookies link (#1348) (Peng Jie <<dean.leehom@gmail.com>>)
|
|
29
|
+
* [[`b7fc526`](http://github.com/koajs/koa/commit/b7fc526ea49894f366153bd32997e02568c0b8a6)] - docs: fix typo in cookie path default value docs (#1340) (Igor Adamenko <<igoradamenko@users.noreply.github.com>>)
|
|
30
|
+
* [[`23f7f54`](http://github.com/koajs/koa/commit/23f7f545abfe1fb6499cd61cc8ff41fd86cef4a0)] - chore: simplify variable (#1332) (kzhang <<godky@users.noreply.github.com>>)
|
|
31
|
+
* [[`132c9ee`](http://github.com/koajs/koa/commit/132c9ee63f92a586a120ed3bd6b7ef023badb8bb)] - docs: Clarify the format of request.headers (#1325) (Dobes Vandermeer <<dobesv@gmail.com>>)
|
|
32
|
+
* [[`5810f27`](http://github.com/koajs/koa/commit/5810f279a4caeda115f39e429c9671795613abf8)] - docs: Removed Document in Progress note in Koa vs Express (#1336) (Andrew Peterson <<andrew@andpeterson.com>>)
|
|
33
|
+
* [[`75233d9`](http://github.com/koajs/koa/commit/75233d974a30af6e3b8ab38a73e5ede67172fc1c)] - chore: Consider removing this return statement; it will be ignored. (#1322) (Vern Brandl <<tkvern@users.noreply.github.com>>)
|
|
34
|
+
* [[`04e07fd`](http://github.com/koajs/koa/commit/04e07fdc620841068f12b8edf36f27e6592a0a18)] - test: Buffer() is deprecated due to security and usability issues. so use the Buffer.alloc() instead (#1321) (Vern Brandl <<tkvern@users.noreply.github.com>>)
|
|
35
|
+
* [[`130e363`](http://github.com/koajs/koa/commit/130e363856747b487652f04b5550056d7778e43a)] - docs: use 'fs-extra' instead of 'fs-promise' (#1309) (rosald <<35028438+rosald@users.noreply.github.com>>)
|
|
36
|
+
* [[`2f2078b`](http://github.com/koajs/koa/commit/2f2078bf998bd3f44289ebd17eeccf5e12e4c134)] - chore: Update PR-welcome badge url (#1299) (James George <<jamesgeorge998001@gmail.com>>)
|
|
37
|
+
|
|
38
|
+
2.7.0 / 2019-01-28
|
|
39
|
+
==================
|
|
40
|
+
|
|
41
|
+
**features**
|
|
42
|
+
* [[`b7bfa71`](http://github.com/koajs/koa/commit/b7bfa7113b8d1af49a57ab767f24a599ed92044f)] - feat: change set status assert, allowing valid custom statuses (#1308) (Martin Iwanowski <<martin@iwanowski.se>>)
|
|
43
|
+
|
|
44
|
+
**others**
|
|
45
|
+
* [[`72f325b`](http://github.com/koajs/koa/commit/72f325b78edd0dc2aac940a76ce5f644005ce4c3)] - chore: add pr welcoming badge (#1291) (James George <<jamesgeorge998001@gmail.com>>)
|
|
46
|
+
* [[`b15115b`](http://github.com/koajs/koa/commit/b15115b2cbfffe15827cd5e4368267d417b72f08)] - chore: Reduce unnecessary variable declarations (#1298) (call me saisai <<1457358080@qq.com>>)
|
|
47
|
+
* [[`ad91ce2`](http://github.com/koajs/koa/commit/ad91ce2346cb34e5d5a49d07dd952d15f6c832a3)] - chore: license 2019 (dead-horse <<dead_horse@qq.com>>)
|
|
48
|
+
* [[`b25e79d`](http://github.com/koajs/koa/commit/b25e79dfb599777a38157bd419395bd28369ee86)] - Mark two examples as live for the corresponding documentation change in https://github.com/koajs/koajs.com/pull/38. (#1031) (Francisco Ryan Tolmasky I <<tolmasky@gmail.com>>)
|
|
49
|
+
* [[`d9ef603`](http://github.com/koajs/koa/commit/d9ef60398e88f2c2f958ab2b159d38052ffe7f8a)] - chore: Optimize array split (#1295) (Mikhail Bodrov <<connormiha1@gmail.com>>)
|
|
50
|
+
* [[`9be8583`](http://github.com/koajs/koa/commit/9be858312553002841725b617050aaff3c48951d)] - chore: replace ~~ with Math.trunc in res.length (option) (#1288) (jeremiG <<gendronjeremi@gmail.com>>)
|
|
51
|
+
* [[`7e46c20`](http://github.com/koajs/koa/commit/7e46c2058cb5994809eab5f4dbb12f21e937c72b)] - docs: add link to the license file (#1290) (James George <<jamesgeorge998001@gmail.com>>)
|
|
52
|
+
* [[`48993ad`](http://github.com/koajs/koa/commit/48993ade9b0831fbce28d94b3b0963a4b0dccbdd)] - docs: Document other body types (#1285) (Douglas Wade <<douglas.b.wade@gmail.com>>)
|
|
53
|
+
* [[`acb388b`](http://github.com/koajs/koa/commit/acb388bc0546b48fca11dce8aa7a595af2cda5e2)] - docs: Add security vulnerability disclosure instructions to the Readme (#1283) (Douglas Wade <<douglas.b.wade@gmail.com>>)
|
|
54
|
+
* [[`a007198`](http://github.com/koajs/koa/commit/a007198fa23c19902b1f3ffb81498629e0e9c875)] - docs: Document ctx.app.emit (#1284) (Douglas Wade <<douglas.b.wade@gmail.com>>)
|
|
55
|
+
* [[`f90e825`](http://github.com/koajs/koa/commit/f90e825da9d505c11b4262c50cd54553f979c300)] - docs: response.set(fields) won't overwrites previous header fields(#1282) (Douglas Wade <<douglas.b.wade@gmail.com>>)
|
|
56
|
+
* [[`fc93c05`](http://github.com/koajs/koa/commit/fc93c05f68398f30abc46fd16ae6c673a1eee099)] - docs: update readme to add babel 7 instructions (#1274) (Vikram Rangaraj <<vik120@icloud.com>>)
|
|
57
|
+
* [[`5560f72`](http://github.com/koajs/koa/commit/5560f729124f022ffed00085aafea43dded7fb03)] - chore: use the ability of `content-type` lib directly (#1276) (Jordan <<mingmingwon@gmail.com>>)
|
|
58
|
+
|
|
59
|
+
2.6.2 / 2018-11-10
|
|
60
|
+
==================
|
|
61
|
+
|
|
62
|
+
**fixes**
|
|
63
|
+
* [[`9905199`](http://github.com/koajs/koa/commit/99051992a9f45eb0dd79e062681d6f5d366deb41)] - fix: Status message is not supported on HTTP/2 (#1264) (André Cruz <<andre@cabine.org>>)
|
|
64
|
+
|
|
65
|
+
**others**
|
|
66
|
+
* [[`325792a`](http://github.com/koajs/koa/commit/325792aee92de0ba6fea306657933fc63dc00474)] - docs: add table of contents for guide.md (#1267) (ZYSzys <<zyszys98@gmail.com>>)
|
|
67
|
+
* [[`71aaa29`](http://github.com/koajs/koa/commit/71aaa29591d6681f8579486f18d32ba1ee651a5b)] - docs: fix spelling in throw docs (#1269) (Martin Iwanowski <<martin@iwanowski.se>>)
|
|
68
|
+
* [[`bc81ca9`](http://github.com/koajs/koa/commit/bc81ca9414296234c764b7306a19ba72b2e59b52)] - chore: use res instead of this.res (#1271) (Jordan <<mingmingwon@gmail.com>>)
|
|
69
|
+
* [[`0251b38`](http://github.com/koajs/koa/commit/0251b38a8405471892c5eeaba7c8d54bd7028214)] - test: node v11 on travis (#1265) (Martin Iwanowski <<martin@iwanowski.se>>)
|
|
70
|
+
* [[`88b92b4`](http://github.com/koajs/koa/commit/88b92b43153f21609aee71d47abcd4dc27a6586d)] - doc: updated docs for throw() to pass status as first param. (#1268) (Waleed Ashraf <<waleedashraf@outlook.com>>)
|
|
71
|
+
|
|
2
72
|
2.6.1 / 2018-10-23
|
|
3
73
|
==================
|
|
4
74
|
|
package/LICENSE
CHANGED
package/Readme.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
[![Test coverage][coveralls-image]][coveralls-url]
|
|
7
7
|
[![OpenCollective Backers][backers-image]](#backers)
|
|
8
8
|
[![OpenCollective Sponsors][sponsors-image]](#sponsors)
|
|
9
|
+
[![PR's Welcome][pr-welcoming-image]][pr-welcoming-url]
|
|
9
10
|
|
|
10
11
|
Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream.
|
|
11
12
|
|
|
@@ -135,7 +136,7 @@ app.use(async (ctx, next) => {
|
|
|
135
136
|
```
|
|
136
137
|
|
|
137
138
|
The `Context` object also provides shortcuts for methods on its `request` and `response`. In the prior
|
|
138
|
-
examples, `ctx.type` can be used instead of `ctx.
|
|
139
|
+
examples, `ctx.type` can be used instead of `ctx.response.type` and `ctx.accepts` can be used
|
|
139
140
|
instead of `ctx.request.accepts`.
|
|
140
141
|
|
|
141
142
|
For more information on `Request`, `Response` and `Context`, see the [Request API Reference](docs/api/request.md),
|
|
@@ -161,16 +162,22 @@ Learn more about the application object in the [Application API Reference](docs/
|
|
|
161
162
|
|
|
162
163
|
## Babel setup
|
|
163
164
|
|
|
164
|
-
If you're not using `node v7.6+`, we recommend setting up `babel` with [
|
|
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):
|
|
165
166
|
|
|
166
167
|
```bash
|
|
167
|
-
$ npm install babel
|
|
168
|
+
$ npm install @babel/register @babel/preset-env @babel/cli --save-dev
|
|
168
169
|
```
|
|
169
170
|
|
|
170
|
-
|
|
171
|
+
In development, you'll want to use [`@babel/register`](https://babeljs.io/docs/en/next/babel-register):
|
|
171
172
|
|
|
172
|
-
```
|
|
173
|
-
require
|
|
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
|
|
174
181
|
```
|
|
175
182
|
|
|
176
183
|
And have your `.babelrc` setup:
|
|
@@ -178,7 +185,7 @@ And have your `.babelrc` setup:
|
|
|
178
185
|
```json
|
|
179
186
|
{
|
|
180
187
|
"presets": [
|
|
181
|
-
["env", {
|
|
188
|
+
["@babel/preset-env", {
|
|
182
189
|
"targets": {
|
|
183
190
|
"node": true
|
|
184
191
|
}
|
|
@@ -198,6 +205,12 @@ the general Koa guide.
|
|
|
198
205
|
$ npm test
|
|
199
206
|
```
|
|
200
207
|
|
|
208
|
+
## Reporting vulnerabilities
|
|
209
|
+
|
|
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.
|
|
213
|
+
|
|
201
214
|
## Authors
|
|
202
215
|
|
|
203
216
|
See [AUTHORS](AUTHORS).
|
|
@@ -296,7 +309,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
|
|
296
309
|
|
|
297
310
|
# License
|
|
298
311
|
|
|
299
|
-
MIT
|
|
312
|
+
[MIT](https://github.com/koajs/koa/blob/master/LICENSE)
|
|
300
313
|
|
|
301
314
|
[npm-image]: https://img.shields.io/npm/v/koa.svg?style=flat-square
|
|
302
315
|
[npm-url]: https://www.npmjs.com/package/koa
|
|
@@ -309,3 +322,5 @@ Become a sponsor and get your logo on our README on Github with a link to your s
|
|
|
309
322
|
[gitter-image]: https://img.shields.io/gitter/room/koajs/koa.svg?style=flat-square
|
|
310
323
|
[gitter-url]: https://gitter.im/koajs/koa?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
311
324
|
[#koajs]: https://webchat.freenode.net/?channels=#koajs
|
|
325
|
+
[pr-welcoming-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
|
|
326
|
+
[pr-welcoming-url]: https://github.com/koajs/koa/pull/new
|
package/lib/application.js
CHANGED
|
@@ -34,13 +34,24 @@ module.exports = class Application extends Emitter {
|
|
|
34
34
|
* @api public
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param {object} [options] Application options
|
|
40
|
+
* @param {string} [options.env='development'] Environment
|
|
41
|
+
* @param {string[]} [options.keys] Signed cookie keys
|
|
42
|
+
* @param {boolean} [options.proxy] Trust proxy headers
|
|
43
|
+
* @param {number} [options.subdomainOffset] Subdomain offset
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
constructor(options) {
|
|
38
48
|
super();
|
|
39
|
-
|
|
40
|
-
this.proxy = false;
|
|
49
|
+
options = options || {};
|
|
50
|
+
this.proxy = options.proxy || false;
|
|
51
|
+
this.subdomainOffset = options.subdomainOffset || 2;
|
|
52
|
+
this.env = options.env || process.env.NODE_ENV || 'development';
|
|
53
|
+
if (options.keys) this.keys = options.keys;
|
|
41
54
|
this.middleware = [];
|
|
42
|
-
this.subdomainOffset = 2;
|
|
43
|
-
this.env = process.env.NODE_ENV || 'development';
|
|
44
55
|
this.context = Object.create(context);
|
|
45
56
|
this.request = Object.create(request);
|
|
46
57
|
this.response = Object.create(response);
|
|
@@ -200,9 +211,9 @@ function respond(ctx) {
|
|
|
200
211
|
// allow bypassing koa
|
|
201
212
|
if (false === ctx.respond) return;
|
|
202
213
|
|
|
203
|
-
const res = ctx.res;
|
|
204
214
|
if (!ctx.writable) return;
|
|
205
215
|
|
|
216
|
+
const res = ctx.res;
|
|
206
217
|
let body = ctx.body;
|
|
207
218
|
const code = ctx.status;
|
|
208
219
|
|
|
@@ -222,7 +233,11 @@ function respond(ctx) {
|
|
|
222
233
|
|
|
223
234
|
// status body
|
|
224
235
|
if (null == body) {
|
|
225
|
-
|
|
236
|
+
if (ctx.req.httpVersionMajor >= 2) {
|
|
237
|
+
body = String(code);
|
|
238
|
+
} else {
|
|
239
|
+
body = ctx.message || String(code);
|
|
240
|
+
}
|
|
226
241
|
if (!res.headersSent) {
|
|
227
242
|
ctx.type = 'text';
|
|
228
243
|
ctx.length = Buffer.byteLength(body);
|
package/lib/context.js
CHANGED
|
@@ -73,19 +73,20 @@ const proto = module.exports = {
|
|
|
73
73
|
assert: httpAssert,
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* Throw an error with `
|
|
77
|
-
*
|
|
76
|
+
* Throw an error with `status` (default 500) and
|
|
77
|
+
* `msg`. Note that these are user-level
|
|
78
78
|
* errors, and the message may be exposed to the client.
|
|
79
79
|
*
|
|
80
80
|
* this.throw(403)
|
|
81
|
-
* this.throw('name required', 400)
|
|
82
81
|
* this.throw(400, 'name required')
|
|
83
82
|
* this.throw('something exploded')
|
|
84
|
-
* this.throw(new Error('invalid')
|
|
85
|
-
* this.throw(400, new Error('invalid'))
|
|
83
|
+
* this.throw(new Error('invalid'))
|
|
84
|
+
* this.throw(400, new Error('invalid'))
|
|
86
85
|
*
|
|
87
86
|
* See: https://github.com/jshttp/http-errors
|
|
88
87
|
*
|
|
88
|
+
* Note: `status` should only be passed as the first parameter.
|
|
89
|
+
*
|
|
89
90
|
* @param {String|Number|Error} err, msg or status
|
|
90
91
|
* @param {String|Number|Error} [err, msg or status]
|
|
91
92
|
* @param {Object} [props]
|
|
@@ -153,7 +154,7 @@ const proto = module.exports = {
|
|
|
153
154
|
const msg = err.expose ? err.message : code;
|
|
154
155
|
this.status = err.status;
|
|
155
156
|
this.length = Buffer.byteLength(msg);
|
|
156
|
-
|
|
157
|
+
res.end(msg);
|
|
157
158
|
},
|
|
158
159
|
|
|
159
160
|
get cookies() {
|
package/lib/request.js
CHANGED
|
@@ -257,7 +257,7 @@ module.exports = {
|
|
|
257
257
|
if (!host) host = this.get('Host');
|
|
258
258
|
}
|
|
259
259
|
if (!host) return '';
|
|
260
|
-
return host.split(/\s*,\s
|
|
260
|
+
return host.split(/\s*,\s*/, 1)[0];
|
|
261
261
|
},
|
|
262
262
|
|
|
263
263
|
/**
|
|
@@ -273,7 +273,7 @@ module.exports = {
|
|
|
273
273
|
const host = this.host;
|
|
274
274
|
if (!host) return '';
|
|
275
275
|
if ('[' == host[0]) return this.URL.hostname || ''; // IPv6
|
|
276
|
-
return host.split(':')[0];
|
|
276
|
+
return host.split(':', 1)[0];
|
|
277
277
|
},
|
|
278
278
|
|
|
279
279
|
/**
|
|
@@ -287,11 +287,9 @@ module.exports = {
|
|
|
287
287
|
get URL() {
|
|
288
288
|
/* istanbul ignore else */
|
|
289
289
|
if (!this.memoizedURL) {
|
|
290
|
-
const protocol = this.protocol;
|
|
291
|
-
const host = this.host;
|
|
292
290
|
const originalUrl = this.originalUrl || ''; // avoid undefined in template string
|
|
293
291
|
try {
|
|
294
|
-
this.memoizedURL = new URL(`${
|
|
292
|
+
this.memoizedURL = new URL(`${this.origin}${originalUrl}`);
|
|
295
293
|
} catch (err) {
|
|
296
294
|
this.memoizedURL = Object.create(null);
|
|
297
295
|
}
|
|
@@ -367,16 +365,12 @@ module.exports = {
|
|
|
367
365
|
*/
|
|
368
366
|
|
|
369
367
|
get charset() {
|
|
370
|
-
let type = this.get('Content-Type');
|
|
371
|
-
if (!type) return '';
|
|
372
|
-
|
|
373
368
|
try {
|
|
374
|
-
|
|
369
|
+
const { parameters } = contentType.parse(this.req);
|
|
370
|
+
return parameters.charset || '';
|
|
375
371
|
} catch (e) {
|
|
376
372
|
return '';
|
|
377
373
|
}
|
|
378
|
-
|
|
379
|
-
return type.parameters.charset || '';
|
|
380
374
|
},
|
|
381
375
|
|
|
382
376
|
/**
|
|
@@ -408,7 +402,7 @@ module.exports = {
|
|
|
408
402
|
if (this.socket.encrypted) return 'https';
|
|
409
403
|
if (!this.app.proxy) return 'http';
|
|
410
404
|
const proto = this.get('X-Forwarded-Proto');
|
|
411
|
-
return proto ? proto.split(/\s*,\s
|
|
405
|
+
return proto ? proto.split(/\s*,\s*/, 1)[0] : 'http';
|
|
412
406
|
},
|
|
413
407
|
|
|
414
408
|
/**
|
|
@@ -508,7 +502,7 @@ module.exports = {
|
|
|
508
502
|
* @api private
|
|
509
503
|
*/
|
|
510
504
|
set accept(obj) {
|
|
511
|
-
|
|
505
|
+
this._accept = obj;
|
|
512
506
|
},
|
|
513
507
|
|
|
514
508
|
/**
|
package/lib/response.js
CHANGED
|
@@ -48,7 +48,7 @@ module.exports = {
|
|
|
48
48
|
const { res } = this;
|
|
49
49
|
return typeof res.getHeaders === 'function'
|
|
50
50
|
? res.getHeaders()
|
|
51
|
-
: res._headers || {};
|
|
51
|
+
: res._headers || {}; // Node < 7.7
|
|
52
52
|
},
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -83,8 +83,8 @@ module.exports = {
|
|
|
83
83
|
set status(code) {
|
|
84
84
|
if (this.headerSent) return;
|
|
85
85
|
|
|
86
|
-
assert(
|
|
87
|
-
assert(
|
|
86
|
+
assert(Number.isInteger(code), 'status code must be a number');
|
|
87
|
+
assert(code >= 100 && code <= 999, `invalid status code: ${code}`);
|
|
88
88
|
this._explicitStatus = true;
|
|
89
89
|
this.res.statusCode = code;
|
|
90
90
|
if (this.req.httpVersionMajor < 2) this.res.statusMessage = statuses[code];
|
|
@@ -211,7 +211,7 @@ module.exports = {
|
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
return
|
|
214
|
+
return Math.trunc(len) || 0;
|
|
215
215
|
},
|
|
216
216
|
|
|
217
217
|
/**
|
|
@@ -381,7 +381,7 @@ module.exports = {
|
|
|
381
381
|
get type() {
|
|
382
382
|
const type = this.get('Content-Type');
|
|
383
383
|
if (!type) return '';
|
|
384
|
-
return type.split(';')[0];
|
|
384
|
+
return type.split(';', 1)[0];
|
|
385
385
|
},
|
|
386
386
|
|
|
387
387
|
/**
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koa",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "Koa web app framework",
|
|
5
5
|
"main": "lib/application.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
8
|
-
"test-cov": "
|
|
7
|
+
"test": "egg-bin test test",
|
|
8
|
+
"test-cov": "egg-bin cov test",
|
|
9
9
|
"lint": "eslint benchmarks lib test",
|
|
10
10
|
"bench": "make -C benchmarks",
|
|
11
11
|
"authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS"
|
|
@@ -48,12 +48,13 @@
|
|
|
48
48
|
"vary": "^1.1.2"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"
|
|
51
|
+
"egg-bin": "^4.13.0",
|
|
52
|
+
"eslint": "^6.0.1",
|
|
52
53
|
"eslint-config-koa": "^2.0.0",
|
|
53
54
|
"eslint-config-standard": "^7.0.1",
|
|
54
55
|
"eslint-plugin-promise": "^3.5.0",
|
|
55
56
|
"eslint-plugin-standard": "^2.1.1",
|
|
56
|
-
"
|
|
57
|
+
"mm": "^2.5.0",
|
|
57
58
|
"supertest": "^3.1.0"
|
|
58
59
|
},
|
|
59
60
|
"engines": {
|
|
@@ -61,16 +62,5 @@
|
|
|
61
62
|
},
|
|
62
63
|
"files": [
|
|
63
64
|
"lib"
|
|
64
|
-
]
|
|
65
|
-
"jest": {
|
|
66
|
-
"testMatch": [
|
|
67
|
-
"**/test/!(helpers)/*.js"
|
|
68
|
-
],
|
|
69
|
-
"coverageReporters": [
|
|
70
|
-
"text-summary",
|
|
71
|
-
"lcov"
|
|
72
|
-
],
|
|
73
|
-
"bail": true,
|
|
74
|
-
"testEnvironment": "node"
|
|
75
|
-
}
|
|
65
|
+
]
|
|
76
66
|
}
|