Skip to content

Commit

Permalink
fix: calculate content-lenght header correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Feb 12, 2018
1 parent c203d8b commit 1a9d8a3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/additions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ function fixtureAdditions (state, {id, fixture}) {
})

fixture.headers['content-length'] = String(calculateBodyLength(fixture.response))

return fixture
}

function calculateBodyLength (body) {
if (typeof body === 'string') {
return body.length
if (typeof body !== 'string') {
body = JSON.stringify(body)
}

return JSON.stringify(body).length
return Buffer.byteLength(body, 'utf8')
}

0 comments on commit 1a9d8a3

Please sign in to comment.