web:javascript:nodejs:http2
HTTP2 avec Node
const http2 = require('http2'); const server = http2.createSecureServer({cert, key}, onRequest); function push (stream, filePath) { const {file, headers} = getFile(filePath); const pushHeaders = {[HTTP2_HEADER_PATH]: filePath }; stream.pushStream(pushHeaders, (pushStream) => { pushStream.respondWithFD(file, headers); }); } function onRequest (req, res) { // Push files with index.html if (reqPath === '/index.html') { push(res.stream, 'bundle1.js'); push(res.stream, 'bundle2.js'); } // Serve file res.stream.respondWithFD(file.fileDescriptor, file.headers); }
Source : HTTP/2 Server Push with Node.js
Avec Express
Pour HTTP/2 avec Express, on peut utiliser spdy.
web/javascript/nodejs/http2.txt · Dernière modification : 2022/02/02 00:42 de 127.0.0.1