Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Created September 18, 2024 19:15
Show Gist options
  • Save masakielastic/d1ddb08ef82ab6d919bd13f121c663d3 to your computer and use it in GitHub Desktop.
Save masakielastic/d1ddb08ef82ab6d919bd13f121c663d3 to your computer and use it in GitHub Desktop.
h2frames.js
console.log(Buffer.from(h2frames()).toString('hex').toUpperCase());
function h2frames() {
const pri = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
const settings = [
'\x00\x00\x0C',
'\x04',
'\x00',
'\x00\x00\x00\x00',
'\x00\x02\x00\x00\x00\x00',
'\x00\x03\x00\x00\x00\x64'
].join('');
const ack = [
'\x00\x00\x00',
'\x04',
'\x01',
'\x00\x00\x00\x00'
].join('');
const headers = [
'\x00\x00\x3a',
'\x01',
'\x05',
'\x00\x00\x00\x01',
'\x00',
// 7:method
'\x07\x3a\x6d\x65\x74\x68\x6f\x64',
// 3GET
'\x03\x47\x45\x54',
'\x00',
// 5:path
'\x05\x3a\x70\x61\x74\x68',
// 1/
'\x01\x2f',
'\x00',
// 7:scheme
'\x07\x3a\x73\x63\x68\x65\x6d\x65',
// 4http
'\x04\x68\x74\x74\x70',
'\x00',
// 10:authority
'\x0a\x3a\x61\x75\x74\x68\x6f\x72\x69\x74\x79',
// 9localhost
'\x09\x6c\x6f\x63\x61\x6c\x68\x6f\x73\x74'
].join('');
return pri + settings + ack + headers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment