diff --git a/__tests__/response/body.test.js b/__tests__/response/body.test.js index c63cb4d75..239a77689 100644 --- a/__tests__/response/body.test.js +++ b/__tests__/response/body.test.js @@ -302,6 +302,19 @@ describe('res.body=', () => { res.body = new Blob([new Uint8Array([1, 2, 3])], { type: 'application/octet-stream' }) assert.strictEqual(3, res.header['content-length']) }) + + it('should keep the Blob content type', () => { + const res = response() + res.body = new Blob([new Uint8Array([1, 2, 3])], { type: 'image/png' }) + assert.strictEqual('image/png', res.header['content-type']) + }) + + it('should not override an explicit content type', () => { + const res = response() + res.type = 'application/json' + res.body = new Blob(['x'], { type: 'image/png' }) + assert.strictEqual('application/json; charset=utf-8', res.header['content-type']) + }) }) describe('when a response is given', () => { diff --git a/lib/response.js b/lib/response.js index 9b6741476..275706e46 100644 --- a/lib/response.js +++ b/lib/response.js @@ -207,7 +207,7 @@ module.exports = { // blob if (val instanceof Blob) { - if (setType) this.type = 'bin' + if (setType) this.type = val.type || 'bin' this.length = val.size cleanupPreviousStream() return