Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Last active July 7, 2024 20:20
Show Gist options
  • Save masakielastic/d1f589ba3aedcaa98dad4593004caf80 to your computer and use it in GitHub Desktop.
Save masakielastic/d1f589ba3aedcaa98dad4593004caf80 to your computer and use it in GitHub Desktop.
http/2 frames example
def h2frames(name)
frames = {
'pri' => "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n",
'settings' => "\x00\x00\x0C" +
"\x04" +
"\x00" +
"\x00\x00\x00\x00" +
"\x00\x02\x00\x00\x00\x00" +
"\x00\x03\x00\x00\x00\x64",
'ack' => "\x00\x00\x00" +
"\x04" +
"\x01" +
"\x00\x00\x00\x00",
'headers' => "\x00\x00\x3a" +
"\x01" +
"\x05" +
"\x00\x00\x00\x01" +
"\x00" +
"\x07:method" + # 7 :method
"\x03\x47\x45\x54" + # 3 GET
"\x00" +
"\x05\x3a\x70\x61\x74\x68" + # 5 :path
"\x01\x2f" + # 1 /
"\x00" +
"\x07\x3a\x73\x63\x68\x65\x6d\x65" + # 7 :scheme
"\x04http" + # 4 http
"\x00" +
"\x0a\x3a\x61\x75\x74\x68\x6f\x72\x69\x74\x79" + # 10 :authority
"\x09localhost" # 9 localhost
}
frames[name]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment