Skip to content

ALPNProtocols option of TLSSocket constructor is broken. #16643

Description

@qubyte
  • Version: v8.8.1
  • Platform: Darwin sprite.local 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64
  • Subsystem: _tls_wrap.js

Documentation for the ALPNProtocols option (found here) indicates that an array of strings should be acceptable:

\\ Broken
var socket = new tls.TLSSocket(null, { ALPNProtocols: ['http/1.1'] });

However, the example above produces this error:

TypeError: Must give a Buffer as first argument
    at TLSSocket._init (_tls_wrap.js:516:9)
    at new TLSSocket (_tls_wrap.js:304:8)
    at repl:1:14
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:441:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)

From which I inferred that I had to use a buffer:

\\ Working
var buffer = Buffer.from([8, ...Buffer.from('http/1.1')]);
var socket = new tls.TLSSocket(null, { ALPNProtocols: buffer });

If this is indeed a documentation bug, I'd be happy to open a pull request. I'll take a shot at a code bug if the issue is determined to be there instead.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

tlsIssues and PRs related to the tls subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions