| 250 | // Convert protocols array into valid OpenSSL protocols list |
| 251 | // ("\x06spdy/2\x08http/1.1\x08http/1.0") |
| 252 | function convertProtocols(protocols) { |
| 253 | const lens = new Array(protocols.length); |
| 254 | const buff = Buffer.allocUnsafe(protocols.reduce((p, c, i) => { |
| 255 | const len = Buffer.byteLength(c); |
| 256 | if (len > 255) { |
| 257 | throw new ERR_OUT_OF_RANGE('The byte length of the protocol at index ' + |
| 258 | `${i} exceeds the maximum length.`, '<= 255', len, true); |
| 259 | } |
| 260 | lens[i] = len; |
| 261 | return p + 1 + len; |
| 262 | }, 0)); |
| 263 | |
| 264 | let offset = 0; |
| 265 | for (let i = 0, c = protocols.length; i < c; i++) { |
| 266 | buff[offset++] = lens[i]; |
| 267 | buff.write(protocols[i], offset); |
| 268 | offset += lens[i]; |
| 269 | } |
| 270 | |
| 271 | return buff; |
| 272 | } |
| 273 | |
| 274 | exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) { |
| 275 | // If protocols is Array - translate it into buffer |