Skip to content

http2.connect doesn't connect to an http2 secure server #14671

@chiptus

Description

@chiptus
  • Version: v9.0.0-pre
  • Platform: Windows 10 64 bit
  • Subsystem: http2

Using the code examples from james's post

Chrome is connecting to the server successfully, but the client doesn't. Before changing the server to secure server it was the opposite way.

server.js

const http2 = require('http2');
const fs = require('fs');

// Create a plain-text HTTP/2 server
const options = {
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.crt'),
};
const server = http2.createSecureServer(options);
server.on('stream', (stream, headers) => {
  console.log('stream');
  stream.respond({
    'content-type': 'text/html',
    ':status': 200,
  });
  stream.end('<h1>Hello World</h1>');
});

server.listen(1234);

client.js

const http2 = require('http2');

const client = http2.connect('https://localhost:1234');

const req = client.request({ ':path': '/' });

req.on('response', (headers) => {
  console.log(headers[':status']);
  console.log(headers['date']);
});

let data = '';
req.setEncoding('utf8');
req.on('data', (d) => data += d);
req.on('end', () => {
  console.log(data);
  client.destroy();
});
req.end();

#goodnessSquad

Metadata

Metadata

Assignees

No one assigned

    Labels

    http2Issues or PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions