ERR_INVALID_HTTP_RESPONSE on nodejs http2
Asked Answered
A

1

7

When using node new http2 server, I encountered this error when attempting to call it from the browser: ERR_INVALID_HTTP_RESPONSE.

The code:

const http2 = require('http2');

// Create a plain-text HTTP/2 server
const server = http2.createServer();

server.on('stream', (stream, headers) => {
  console.log('headers: ', headers);
  stream.respond({
    'content-type': 'text/html',
    ':status': 200
  });
  stream.end('<h1>Hello World</h1>');
});

server.listen(80);
Acetylcholine answered 7/8, 2017 at 16:48 Comment(0)
A
13

Turns out, chrome won't allow you to access insecure http2 servers, I had to change the code to:

const server = http2.createSecureServer({
  key,
  cert
});

and then it worked.

Acetylcholine answered 7/8, 2017 at 16:48 Comment(1)
got the link or article about chrome vs insecure http2 server?Damarisdamarra

© 2022 - 2024 — McMap. All rights reserved.