NodeJS 4.x veya 5.x HTTP/2 protokolünü doğal olarak destekliyor mu? Http2 paketinin olduğunu biliyorum ama bu harici bir şey.NodeJS yerel http2 desteği
Düğümün çekirdeğine http2 desteğini birleştirmek için bazı planlar var mı?
NodeJS 4.x veya 5.x HTTP/2 protokolünü doğal olarak destekliyor mu? Http2 paketinin olduğunu biliyorum ama bu harici bir şey.NodeJS yerel http2 desteği
Düğümün çekirdeğine http2 desteğini birleştirmek için bazı planlar var mı?
--expose-http2
bayrak deney HTTP2 destek sağlar: Burada
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
bayrağı da Düğüm v8.5.0 yana eklenebilir.
node --expose-http2 --experimental-modules client.mjs
client.mjs
import http2 from 'http2';
const client = http2.connect('https://stackoverflow.com');
test etmek için NVS (düğüm şekli Değiştirici) gece oluşturur kullanın.
nvs add nightly
nvs use nightly
Hayır, henüz değil. https://github.com/nodejs/NG/issues/8
Havuz https://github.com/nodejs/http2 – pungggi
Düğüm 8.4.0 Deneysel Http2 API vardır. Docs here nodejs http2
nodejs'deki http2 desteği artık deneysel olmayacak mı? – funkenstrahlen
Kodunuzu çalıştırırken v8.8.1 düğümünden --expose-http2
bayrağına ihtiyacınız yoktur.
HTTP/2 ile çalışmaya başlamanın en basit yolu, Node.js'nin ortaya koyduğu uyumluluk API'sini kullanmaktır.
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'u kullanma hakkında daha fazla yazı yazdım.
Ayrıca, Node.js belgelerinde güncel sunucu tarafı örneğine bakın: https://nodejs.org/api/http2.html#http2_server_side_example. –
SSL bağlantısı yapabilmek için kendinden imzalı sertifikalar için 'process.env.NODE_TLS_REJECT_UNAUTHORIZED =" 0 "; –
Ayrıca, Node.js belgelerinde güncel istemci tarafı örneğine bakın: https://nodejs.org/api/http2.html#http2_client_side_example. –