Search code examples
http2

HTTP2_Plain in node-http2 module is not working?


I want to create a http2 server using node-http2 module without TLS. My code is as follows:

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

var log = bunyan.createLogger({name: "HTTP2 server without TLS!"});

var options = {
    log: log
}

var server = http2.raw.createServer(options, function(request, response) {
    console.log("Receiving HTTP2 request!");
    // response.writeHead(200);
    response.end('Hello world from HTTP2!');
});

server.listen(8000);

However, it does not work. When connecting to this server from chrome, it shows downloading something. When I closed the server, the downloading is finished with blank file (26 bytes).

Does anyone know what is wrong here? Do I need to configure the browser? Thanks in advance!


Solution

  • Chrome and all other browsers only support HTTP/2 over TLS (h2) and not plain HTTP/2 (h2c). So your browser does not understand what is returned from the server and apparently node-http2 does not send a proper error response when it receives a non-http2 request.