Skip to content

Commit 59590e8

Browse files
gyx1000ryanblock
authored andcommitted
perf(http) Improve IsBinary checking performance
1 parent 57dc238 commit 59590e8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/http/_res-fmt.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ let httpError = require('./errors')
22
let binaryTypes = require('./helpers/binary-types')
33
let { brotliCompressSync } = require('zlib')
44

5+
let binaryTypesSet = new Set(binaryTypes)
6+
57
module.exports = function responseFormatter (req, params) {
68
let isError = params instanceof Error
79

@@ -167,7 +169,8 @@ module.exports = function responseFormatter (req, params) {
167169
}
168170

169171
// Handle body encoding (if necessary)
170-
let isBinary = binaryTypes.some(t => res.headers['content-type'].includes(t))
172+
let [ cTest ] = (res.headers['content-type'] || '').split(';')
173+
let isBinary = binaryTypesSet.has(cTest)
171174
let bodyIsString = typeof res.body === 'string'
172175
let b64enc = i => new Buffer.from(i).toString('base64')
173176
function compress (body) {

0 commit comments

Comments
 (0)