Daniela Matos de Carvalho
Software Engineer @Dashlane, mother, photographer amateur, former @requirelx organiser, prev @YLDio, @zpx_interactive
@sericaia
(image source: High Performance Browser Networking - Ilya Gregorik)
(image source: High Performance Browser Networking - Ilya Gregorik)
there is
when only
saxophones play
saxophonists might play the whole song,
or just a part of it
[Binary]
[Binary]
[Binary]
[Binary]
and they also announce that
they are going to play
sound
enthusiasm
applause
mood
attendees
orchestra
conductor
room
node --expose-http2 index.js
const http2 = require('http2'),
fs = require('fs');
const options = {
key: fs.readFileSync('keys/server.key'),
cert: fs.readFileSync('keys/server.crt')
};
const server = http2.createSecureServer(options);
server.on('stream', (stream, requestHeaders) => {
// ...
});
server.listen(3000);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const { HTTP2_HEADER_PATH } = http2.constants;
const pushAsset = (stream, file) => {
const filePath = path.join(__dirname, file.filePath);
stream.pushStream({ [HTTP2_HEADER_PATH]: file.path }, (pushStream) => {
pushStream.respondWithFile(filePath, file.headers);
});
}
const onRequestHandler = (req, res) => {
const currentUrl = url.parse(req.url);
// ...
if (currentUrl.pathname === '/') {
const cssFile = {
path: '/style.css',
filePath: './style.css',
headers: {
'content-type': 'text/css'
}
};
pushAsset(res.stream, cssFile);
// ...
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@sericaia
By Daniela Matos de Carvalho
Software Engineer @Dashlane, mother, photographer amateur, former @requirelx organiser, prev @YLDio, @zpx_interactive