Socket
Socket
Sign inDemoInstall

koa

Package Overview
Dependencies
Maintainers
11
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa - npm Package Compare versions

Comparing version 2.13.0 to 2.14.2

43

lib/application.js

@@ -11,2 +11,3 @@

const onFinished = require('on-finished');
const assert = require('assert');
const response = require('./response');

@@ -45,4 +46,4 @@ const compose = require('koa-compose');

* @param {number} [options.subdomainOffset] Subdomain offset
* @param {boolean} [options.proxyIpHeader] proxy ip header, default to X-Forwarded-For
* @param {boolean} [options.maxIpsCount] max ips read from proxy ip header, default to 0 (means infinity)
* @param {string} [options.proxyIpHeader] Proxy IP header, defaults to X-Forwarded-For
* @param {number} [options.maxIpsCount] Max IPs read from proxy IP header, default to 0 (means infinity)
*

@@ -69,2 +70,7 @@ */

}
if (options.asyncLocalStorage) {
const { AsyncLocalStorage } = require('async_hooks');
assert(AsyncLocalStorage, 'Requires node 12.17.0 or higher to enable asyncLocalStorage');
this.ctxStorage = new AsyncLocalStorage();
}
}

@@ -153,3 +159,8 @@

const ctx = this.createContext(req, res);
return this.handleRequest(ctx, fn);
if (!this.ctxStorage) {
return this.handleRequest(ctx, fn);
}
return this.ctxStorage.run(ctx, async() => {
return await this.handleRequest(ctx, fn);
});
};

@@ -161,2 +172,9 @@

/**
* return currnect contenxt from async local storage
*/
get currentContext() {
if (this.ctxStorage) return this.ctxStorage.getStore();
}
/**
* Handle request in callback.

@@ -219,2 +237,20 @@ *

}
/**
* Help TS users comply to CommonJS, ESM, bundler mismatch.
* @see https://github.com/koajs/koa/issues/1513
*/
static get default() {
return Application;
}
createAsyncCtxStorageMiddleware() {
const app = this;
return async function asyncCtxStorage(ctx, next) {
await app.ctxStorage.run(ctx, async() => {
return await next();
});
};
}
};

@@ -287,2 +323,3 @@

*/
module.exports.HttpError = HttpError;

18

lib/request.js

@@ -149,3 +149,3 @@

/**
* Set pathname, retaining the query-string when present.
* Set pathname, retaining the query string when present.
*

@@ -167,3 +167,3 @@ * @param {String} path

/**
* Get parsed query-string.
* Get parsed query string.
*

@@ -181,3 +181,3 @@ * @return {Object}

/**
* Set query-string as an object.
* Set query string as an object.
*

@@ -205,3 +205,3 @@ * @param {Object} obj

/**
* Set querystring.
* Set query string.
*

@@ -223,3 +223,3 @@ * @param {String} str

/**
* Get the search string. Same as the querystring
* Get the search string. Same as the query string
* except it includes the leading ?.

@@ -414,3 +414,3 @@ *

/**
* Short-hand for:
* Shorthand for:
*

@@ -431,3 +431,3 @@ * this.protocol == 'https'

*
* For example if the value were "client, proxy1, proxy2"
* For example if the value was "client, proxy1, proxy2"
* you would receive the array `["client", "proxy1", "proxy2"]`

@@ -505,2 +505,3 @@ * where "proxy2" is the furthest down-stream.

*/
get accept() {

@@ -516,2 +517,3 @@ return this._accept || (this._accept = accepts(this.req));

*/
set accept(obj) {

@@ -619,3 +621,3 @@ this._accept = obj;

* Check if the incoming request contains the "Content-Type"
* header field, and it contains any of the give mime `type`s.
* header field and if it contains any of the given mime `type`s.
* If there is no request body, `null` is returned.

@@ -622,0 +624,0 @@ * If there is no content type, `false` is returned.

@@ -194,3 +194,5 @@

set length(n) {
this.set('Content-Length', n);
if (!this.has('Transfer-Encoding')) {
this.set('Content-Length', n);
}
},

@@ -437,2 +439,3 @@

*/
has(field) {

@@ -446,3 +449,3 @@ return typeof this.res.hasHeader === 'function'

/**
* Set header `field` to `val`, or pass
* Set header `field` to `val` or pass
* an object of header fields.

@@ -570,4 +573,5 @@ *

/**
* Flush any set headers, and begin the body
* Flush any set headers and begin the body
*/
flushHeaders() {

@@ -584,2 +588,3 @@ this.res.flushHeaders();

*/
/* istanbul ignore else */

@@ -586,0 +591,0 @@ if (util.inspect.custom) {

{
"name": "koa",
"version": "2.13.0",
"version": "2.14.2",
"description": "Koa web app framework",

@@ -11,9 +11,18 @@ "main": "lib/application.js",

},
"./": "./"
"./lib/request": "./lib/request.js",
"./lib/request.js": "./lib/request.js",
"./lib/response": "./lib/response.js",
"./lib/response.js": "./lib/response.js",
"./lib/application": "./lib/application.js",
"./lib/application.js": "./lib/application.js",
"./lib/context": "./lib/context.js",
"./lib/context.js": "./lib/context.js",
"./*": "./*.js",
"./*.js": "./*.js",
"./package": "./package.json",
"./package.json": "./package.json"
},
"scripts": {
"test": "egg-bin test test",
"test-cov": "egg-bin cov test",
"lint": "eslint benchmarks lib test",
"bench": "make -C benchmarks",
"test": "jest --forceExit",
"lint": "eslint --ignore-path .gitignore .",
"authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS",

@@ -40,5 +49,5 @@ "build": "gen-esm-wrapper . ./dist/koa.mjs",

"cookies": "~0.8.0",
"debug": "~3.1.0",
"debug": "^4.3.2",
"delegates": "^1.0.0",
"depd": "^1.1.2",
"depd": "^2.0.0",
"destroy": "^1.0.4",

@@ -52,3 +61,3 @@ "encodeurl": "^1.0.2",

"koa-compose": "^4.1.0",
"koa-convert": "^1.2.0",
"koa-convert": "^2.0.0",
"on-finished": "^2.3.0",

@@ -62,12 +71,11 @@ "only": "~0.0.2",

"devDependencies": {
"egg-bin": "^4.13.0",
"eslint": "^6.5.1",
"eslint": "^7.32.0",
"eslint-config-koa": "^2.0.0",
"eslint-config-standard": "^14.1.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"gen-esm-wrapper": "^1.0.6",
"mm": "^2.5.0",
"jest": "^27.0.6",
"supertest": "^3.1.0"

@@ -81,3 +89,6 @@ },

"lib"
]
],
"jest": {
"testEnvironment": "node"
}
}

@@ -163,36 +163,2 @@ <img src="/docs/logo.png" alt="Koa middleware framework for nodejs"/>

## Babel setup
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):
```bash
$ npm install @babel/register @babel/preset-env @babel/cli --save-dev
```
In development, you'll want to use [`@babel/register`](https://babeljs.io/docs/en/next/babel-register):
```bash
node --require @babel/register <your-entry-file>
```
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:
```bash
babel src --out-dir dist --copy-files
```
And have your `.babelrc` setup:
```json
{
"presets": [
["@babel/preset-env", {
"targets": {
"node": true
}
}]
]
}
```
## Troubleshooting

@@ -211,5 +177,3 @@

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) and [jonathanong](mailto:me@jongleberry.com) to
disclose.
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.

@@ -216,0 +180,0 @@ ## Authors

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc