NodeJS 4.xまたは5.xはネイティブにHTTP/2プロトコルをサポートしていますか?私はhttp2パッケージがあることを知っていますが、それは外的なものです。NodeJSネイティブhttp2サポート
http2サポートをノードのコアにマージする計画はありますか?
NodeJS 4.xまたは5.xはネイティブにHTTP/2プロトコルをサポートしていますか?私はhttp2パッケージがあることを知っていますが、それは外的なものです。NodeJSネイティブhttp2サポート
http2サポートをノードのコアにマージする計画はありますか?
--expose-http2
フラグは、実験HTTP2サポートを可能にします。このフラグは、夜間のビルド(ノードv8.4.0)で、Aug 5、2017(pull request)以降に使用できます。
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
フラグは、ノードのV8.5.0以降に追加することができます。私はテストのためにNVS(ノードバージョンスイッチャー)を使用
node --expose-http2 --experimental-modules client.mjs
client.mjs
import http2 from 'http2';
const client = http2.connect('https://stackoverflow.com');
はナイトリービルド。
nvs add nightly
nvs use nightly
いいえ、まだありません。ここ
コアNodeJSにHTTP/2サポートを追加することについての議論である。https://github.com/nodejs/NG/issues/8
リポジトリはhttps://github.com/nodejs/http2 – pungggi
ノード8.4.0には実験的なHttp2 APIがあります。ここにあるドキュメントnodejs http2
nodejでのhttp2サポートがもう実験的ではないことを知っていますか? – funkenstrahlen
ノードv8.8.1から、コードを実行しているときに--expose-http2
フラグは必要ありません。
HTTP/2を使い始める最も簡単な方法は、Node.jsが公開する互換性APIを利用することです。
const http2 = require('http2');
const fs = require('fs');
const options = {
key: fs.readFileSync('./selfsigned.key'),
cert: fs.readFileSync('./selfsigned.crt'),
allowHTTP1: true
}
const server = http2.createSecureServer(options, (req, res) => {
res.setHeader('Content-Type', 'text/html');
res.end('ok');
});
server.listen(443);
私はnative HTTP/2 Node.js exposes to create a server hereの使用についてさらに詳しく書いています。
Node.jsのドキュメント(https://nodejs.org/api/http2.html#http2_server_side_example)の最新のサーバー側の例も参照してください。 –
です。自己署名証明書がSSL接続できるようにするには、 'process.env.NODE_TLS_REJECT_UNAUTHORIZED =" 0 ";'を追加することを忘れないでください。 –
Node.jsのドキュメント(https://nodejs.org/api/http2.html#http2_client_side_example)の最新のクライアント側の例も参照してください。 –