gpt4 book ai didi

node.js - NodeJS 原生 http2 支持

转载 作者:IT老高 更新时间:2023-10-28 23:02:53 26 4
gpt4 key购买 nike

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

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

最佳答案

--expose-http2 标志启用实验性 HTTP2 支持。自 2017 年 8 月 5 日 (pull request) 起,此标志可用于夜间构建 (Node v8.4.0)。

node --expose-http2 client.js

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

--experimental-modules 标志也可以从 Node v8.5.0 开始添加。

node --expose-http2 --experimental-modules client.mjs

client.mjs

import http2 from 'http2';

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

我使用 NVS( Node 版本切换器)来测试夜间构建。

nvs add nightly
nvs use nightly

关于node.js - NodeJS 原生 http2 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35453991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com