Skip to content

Instantly share code, notes, and snippets.

@Swiip
Last active March 22, 2018 08:01
Show Gist options
  • Save Swiip/e56a521eae57f1d370780d0f718980a7 to your computer and use it in GitHub Desktop.
Save Swiip/e56a521eae57f1d370780d0f718980a7 to your computer and use it in GitHub Desktop.
Basic Node HTTP/2 Push Server
628408: HTTP2_SESSION
localhost:8443 (DIRECT)
Start Time: 2018-03-22 09:00:43.870
t=1298705 [st=0] +HTTP2_SESSION [dt=?]
--> host = "localhost:8443"
--> proxy = "DIRECT"
t=1298705 [st=0] HTTP2_SESSION_INITIALIZED
--> protocol = "h2"
--> source_dependency = 628407 (SOCKET)
t=1298705 [st=0] HTTP2_SESSION_SEND_SETTINGS
--> settings = ["[id:1 (SETTINGS_HEADER_TABLE_SIZE) value:65536]","[id:3 (SETTINGS_MAX_CONCURRENT_STREAMS) value:1000]","[id:4 (SETTINGS_INITIAL_WINDOW_SIZE) value:6291456]"]
t=1298705 [st=0] HTTP2_SESSION_UPDATE_RECV_WINDOW
--> delta = 15663105
--> window_size = 15728640
t=1298705 [st=0] HTTP2_SESSION_SEND_WINDOW_UPDATE
--> delta = 15663105
--> stream_id = 0
t=1298705 [st=0] HTTP2_SESSION_SEND_HEADERS
--> exclusive = true
--> fin = true
--> has_priority = true
--> :method: GET
:authority: localhost:8443
:scheme: https
:path: /robots.txt
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
accept: */*
accept-encoding: gzip, deflate, br
accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
--> parent_stream_id = 0
--> source_dependency = 628404 (HTTP_STREAM_JOB)
--> stream_id = 1
--> weight = 220
t=1298705 [st=0] HTTP2_SESSION_RECV_SETTINGS
t=1298705 [st=0] HTTP2_SESSION_SEND_SETTINGS_ACK
t=1298705 [st=0] HTTP2_SESSION_RECV_SETTINGS_ACK
t=1298706 [st=1] HTTP2_SESSION_RECV_HEADERS
--> fin = false
--> :status: 200
content-type: text/html
date: Thu, 22 Mar 2018 08:00:43 GMT
--> stream_id = 1
t=1298706 [st=1] HTTP2_SESSION_RECV_PUSH_PROMISE
--> :scheme: https
:authority: localhost:8443
:method: GET
:path: /index.css
--> id = 1
--> promised_stream_id = 2
t=1298706 [st=1] HTTP2_STREAM_SEND_PRIORITY
--> exclusive = true
--> parent_stream_id = 1
--> stream_id = 2
--> weight = 110
t=1298706 [st=1] HTTP2_SESSION_RECV_HEADERS
--> fin = false
--> :status: 200
content-type: text/css
date: Thu, 22 Mar 2018 08:00:43 GMT
--> stream_id = 2
t=1298706 [st=1] HTTP2_SESSION_RECV_DATA
--> fin = false
--> size = 61
--> stream_id = 1
t=1298706 [st=1] HTTP2_SESSION_UPDATE_RECV_WINDOW
--> delta = -61
--> window_size = 15728579
t=1298706 [st=1] HTTP2_SESSION_RECV_DATA
--> fin = false
--> size = 16
--> stream_id = 2
t=1298706 [st=1] HTTP2_SESSION_UPDATE_RECV_WINDOW
--> delta = -16
--> window_size = 15728563
t=1298706 [st=1] HTTP2_SESSION_RECV_DATA
--> fin = true
--> size = 0
--> stream_id = 1
t=1298706 [st=1] HTTP2_SESSION_UPDATE_RECV_WINDOW
--> delta = 61
--> window_size = 15728624
t=1298707 [st=2] HTTP2_SESSION_RECV_DATA
--> fin = true
--> size = 0
--> stream_id = 2
const http2 = require("http2");
const fs = require("fs");
const server = http2.createSecureServer({
key: fs.readFileSync("certs/localhost-privkey.pem"),
cert: fs.readFileSync("certs/localhost-cert.pem")
});
server.on("error", err => console.error(err));
server.on("stream", (stream, headers) => {
stream.respond({
"content-type": "text/html",
":status": 200
});
stream.pushStream({ ":path": "/index.css" }, (err, pushStream, headers) => {
if (err) throw err;
pushStream.respond({
"content-type": "text/css",
":status": 200
});
pushStream.end("h1 {color: red;}");
});
stream.end(
`<h1>Hello World</h1><link rel="stylesheet" href="/index.css" crossorigin>`
);
});
server.listen(8443);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment