diff --git a/.node-version b/.node-version deleted file mode 100644 index 53d1c14db..000000000 --- a/.node-version +++ /dev/null @@ -1 +0,0 @@ -v22 diff --git a/__tests__/application/index.test.js b/__tests__/application/index.test.js index d5d6ccc54..5df7be3c4 100644 --- a/__tests__/application/index.test.js +++ b/__tests__/application/index.test.js @@ -59,7 +59,7 @@ describe('app', () => { it('should set compose from the constructor', () => { const compose = () => (ctx) => {} - const app = new Koa({ compose }) + const app = new Koa.default({ compose }) assert.strictEqual(app.compose, compose) }) diff --git a/__tests__/application/respond.test.js b/__tests__/application/respond.test.js index 80703e7ac..0d3d9592c 100644 --- a/__tests__/application/respond.test.js +++ b/__tests__/application/respond.test.js @@ -556,6 +556,20 @@ describe('app.respond', () => { .expect(200) .expect('content-type', 'application/octet-stream') }) + + it('should respond hello', async () => { + const app = new Koa() + + app.use(async ctx => { + ctx.body = new Blob(['hello']).stream() + }) + + return request(app.callback()) + .get('/') + .expect(200) + .expect('content-type', 'application/octet-stream') + .expect(Buffer.from('hello')) + }) }) describe('when .body is a Response', () => { @@ -578,13 +592,14 @@ describe('app.respond', () => { app.use(ctx => { ctx.body = new Response(null, { status: 200, statusText: 'OK' }) + console.log(ctx) }) return request(app.callback()) - .head('/') + .get('/') .expect(200) .expect('content-type', 'application/octet-stream') - .expect('content-length', '2') + .expect(Buffer.from([])) }) }) diff --git a/lib/application.js b/lib/application.js index 0ba1c8907..4d170b049 100644 --- a/lib/application.js +++ b/lib/application.js @@ -306,7 +306,7 @@ function respond (ctx) { if (body instanceof Stream) return body.pipe(res) 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 (body instanceof Response) return Stream.Readable.from(body?.body || '').pipe(res) // body: json body = JSON.stringify(body) diff --git a/lib/only.js b/lib/only.js index 0551a3354..0fc27bbed 100644 --- a/lib/only.js +++ b/lib/only.js @@ -1,6 +1,4 @@ module.exports = (obj, keys) => { - obj = obj || {} - if (typeof keys === 'string') keys = keys.split(/ +/) const ret = {} for (let i = 0; i < keys.length; i++) { const key = keys[i] diff --git a/lib/response.js b/lib/response.js index 8893fcba5..ce709c6dd 100644 --- a/lib/response.js +++ b/lib/response.js @@ -205,9 +205,6 @@ module.exports = { this.set(key, headers.get(key)) } - if (val.redirected) { - this.redirect(val.url) - } return }