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);
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.