Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERR_INVALID_HTTP_RESPONSE on nodejs http2

Tags:

node.js

http2

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);
like image 483
PiniH Avatar asked Jul 20 '26 18:07

PiniH


1 Answers

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.

like image 142
PiniH Avatar answered Jul 23 '26 09:07

PiniH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!