diff options
Diffstat (limited to 'lib/tls.js')
-rw-r--r-- | lib/tls.js | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/tls.js b/lib/tls.js index 695edd8c5a..849daeb07f 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -29,17 +29,19 @@ exports.getCiphers = internalUtil.cachedResult(() => { // Convert protocols array into valid OpenSSL protocols list // ("\x06spdy/2\x08http/1.1\x08http/1.0") function convertProtocols(protocols) { - var buff = Buffer.allocUnsafe(protocols.reduce(function(p, c) { - return p + 1 + Buffer.byteLength(c); + const lens = Array(protocols.length); + const buff = Buffer.allocUnsafe(protocols.reduce((p, c, i) => { + var len = Buffer.byteLength(c); + lens[i] = len; + return p + 1 + len; }, 0)); - protocols.reduce(function(offset, c) { - var clen = Buffer.byteLength(c); - buff[offset] = clen; - buff.write(c, offset + 1); - - return offset + 1 + clen; - }, 0); + var offset = 0; + for (var i = 0, c = protocols.length; i < c; i++) { + buff[offset++] = lens[i]; + buff.write(protocols[i], offset); + offset += lens[i]; + } return buff; } |