koa 3.1.2 → 3.2.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/Readme.md CHANGED
@@ -189,14 +189,6 @@ See [AUTHORS](AUTHORS).
189
189
  - [中文文档 v2.x](https://github.com/demopark/koa-docs-Zh-CN)
190
190
  - __[#koajs]__ on freenode
191
191
 
192
- ## Job Board
193
-
194
- Looking for a career upgrade?
195
-
196
- <a href="https://astro.netlify.com/automattic"><img src="https://astro.netlify.com/static/automattic.png"></a>
197
- <a href="https://astro.netlify.com/segment"><img src="https://astro.netlify.com/static/segment.png"></a>
198
- <a href="https://astro.netlify.com/auth0"><img src="https://astro.netlify.com/static/auth0.png"/></a>
199
-
200
192
  ## Backers
201
193
 
202
194
  Support us with a monthly donation and help us continue our activities.
@@ -4,6 +4,7 @@
4
4
  * Module dependencies.
5
5
  */
6
6
  const util = require('node:util')
7
+ const v8 = require('node:v8')
7
8
  const debug = util.debuglog('koa:application')
8
9
  const Emitter = require('node:events')
9
10
  const Stream = require('node:stream')
@@ -40,6 +41,13 @@ const only = require('./only.js')
40
41
  * Inherits from `Emitter.prototype`.
41
42
  */
42
43
 
44
+ function getAsyncLocalStorage (options) {
45
+ if (options.asyncLocalStorage instanceof AsyncLocalStorage) {
46
+ return options.asyncLocalStorage
47
+ }
48
+ return new AsyncLocalStorage()
49
+ }
50
+
43
51
  module.exports = class Application extends Emitter {
44
52
  /**
45
53
  * Initialize a new `Application`.
@@ -81,10 +89,13 @@ module.exports = class Application extends Emitter {
81
89
  this[util.inspect.custom] = this.inspect
82
90
  }
83
91
  if (options.asyncLocalStorage) {
84
- if (options.asyncLocalStorage instanceof AsyncLocalStorage) {
85
- this.ctxStorage = options.asyncLocalStorage
92
+ if (v8.startupSnapshot?.isBuildingSnapshot?.()) {
93
+ this.ctxStorage = null
94
+ v8.startupSnapshot.addDeserializeCallback(({ app, options }) => {
95
+ app.ctxStorage = getAsyncLocalStorage(options)
96
+ }, { app: this, options })
86
97
  } else {
87
- this.ctxStorage = new AsyncLocalStorage()
98
+ this.ctxStorage = getAsyncLocalStorage(options)
88
99
  }
89
100
  }
90
101
  }
package/lib/request.js CHANGED
@@ -392,7 +392,8 @@ module.exports = {
392
392
  get length () {
393
393
  const len = this.get('Content-Length')
394
394
  if (len === '') return
395
- return ~~len
395
+ const parsed = Number.parseInt(len, 10)
396
+ return Number.isNaN(parsed) ? undefined : parsed
396
397
  },
397
398
 
398
399
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koa",
3
- "version": "3.1.2",
3
+ "version": "3.2.1",
4
4
  "description": "Koa web app framework",
5
5
  "main": "lib/application.js",
6
6
  "exports": {