Skip to content

Instantly share code, notes, and snippets.

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