Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions __tests__/response/body.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down