+12
-4
@@ -307,7 +307,15 @@ 'use strict' | ||
| if (typeof body === 'string') return res.end(body) | ||
| if (body instanceof Blob) { return Stream.Readable.from(body.stream()).pipe(res) } | ||
| if (body instanceof ReadableStream) { return Stream.Readable.from(body).pipe(res) } | ||
| if (body instanceof Response) { return Stream.Readable.from(body?.body || '').pipe(res) } | ||
| if (isStream(body)) return body.pipe(res) | ||
| let stream = null | ||
| if (body instanceof Blob) stream = Stream.Readable.from(body.stream()) | ||
| else if (body instanceof ReadableStream) stream = Stream.Readable.from(body) | ||
| else if (body instanceof Response) stream = Stream.Readable.from(body?.body || '') | ||
| else if (isStream(body)) stream = body | ||
| if (stream) { | ||
| return Stream.pipeline(stream, res, err => { | ||
| if (err && ctx.app.listenerCount('error')) ctx.onerror(err) | ||
| }) | ||
| } | ||
| // body: json | ||
@@ -314,0 +322,0 @@ body = JSON.stringify(body) |
+16
-3
@@ -138,2 +138,10 @@ 'use strict' | ||
| this._body = val | ||
| const cleanupPreviousStream = () => { | ||
| if (original && isStream(original)) { | ||
| original.once('error', () => {}) | ||
| destroy(original) | ||
| } | ||
| } | ||
| // no content | ||
@@ -153,2 +161,3 @@ | ||
| this.remove('Transfer-Encoding') | ||
| cleanupPreviousStream() | ||
| return | ||
@@ -167,2 +176,3 @@ } | ||
| this.length = Buffer.byteLength(val) | ||
| cleanupPreviousStream() | ||
| return | ||
@@ -175,2 +185,3 @@ } | ||
| this.length = val.length | ||
| cleanupPreviousStream() | ||
| return | ||
@@ -183,5 +194,4 @@ } | ||
| if (original !== val) { | ||
| val.once('error', err => this.ctx.onerror(err)) | ||
| // overwriting | ||
| if (original != null) this.remove('Content-Length') | ||
| cleanupPreviousStream() | ||
| } | ||
@@ -196,2 +206,3 @@ | ||
| if (setType) this.type = 'bin' | ||
| cleanupPreviousStream() | ||
| return | ||
@@ -204,2 +215,3 @@ } | ||
| this.length = val.size | ||
| cleanupPreviousStream() | ||
| return | ||
@@ -216,3 +228,3 @@ } | ||
| } | ||
| cleanupPreviousStream() | ||
| return | ||
@@ -224,2 +236,3 @@ } | ||
| if (!this.type || !/\bjson\b/i.test(this.type)) this.type = 'json' | ||
| cleanupPreviousStream() | ||
| }, | ||
@@ -226,0 +239,0 @@ |
+1
-1
| { | ||
| "name": "koa", | ||
| "version": "3.0.3", | ||
| "version": "3.1.0", | ||
| "description": "Koa web app framework", | ||
@@ -5,0 +5,0 @@ "main": "lib/application.js", |
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
64557
0.72%1752
1.04%