NodeJS本机http2支持

Osk*_*ura 16 node.js http2

NodeJS 4.x或5.x本机是否支持HTTP/2协议?我知道有http2包,但它是一个外部的东西.

是否有计划将http2支持合并到Node的核心?

mas*_*tic 9

--expose-http2flag支持实验性HTTP2支持.自2017年8月5日起,此标志可用于夜间构建(Node v8.4.0)(拉取请求).

node --expose-http2 client.js
Run Code Online (Sandbox Code Playgroud)

client.js

const http2 = require('http2');
const client = http2.connect('https://stackoverflow.com');

const req = client.request();
req.setEncoding('utf8');

req.on('response', (headers, flags) => {
  console.log(headers);
});

let data = '';
req.on('data', (d) => data += d);
req.on('end', () => client.destroy());
req.end();
Run Code Online (Sandbox Code Playgroud)

--experimental-modules 也可以从Node v8.5.0添加flag.

node --expose-http2 --experimental-modules client.mjs
Run Code Online (Sandbox Code Playgroud)

client.mjs

import http2 from 'http2';

const client = http2.connect('https://stackoverflow.com');
Run Code Online (Sandbox Code Playgroud)

我使用NVS(节点版本切换器)来测试夜间构建.

nvs add nightly
nvs use nightly
Run Code Online (Sandbox Code Playgroud)


FF_*_*Dev 8

还没有.

以下是关于向核心NodeJS添加HTTP/2支持的讨论:https://github.com/nodejs/NG/issues/8