This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn h2frames() []const u8 { | |
return | |
// 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" ++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size_t h2frames_size(void) { | |
return 24 + 0xC + 9 + 0x00 + 9 + 0x3A + 9; | |
} | |
uint8_t *h2frames(void) { | |
return | |
// PRI | |
"PRI * HTTP/2.0\x0D\x0A\x0D\x0ASM\x0D\x0A\x0D\x0A" | |
// settings | |
"\x00\x00\x0C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function binToInt16(string $bytes): int | |
{ | |
return (ord($bytes[0]) << 8) | ord($bytes[1]); | |
} | |
function binToInt24(string $bytes): int | |
{ | |
return (ord($bytes[0]) << 16) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FrameHeader { | |
private $bytes; | |
public function __construct(string $bytes) | |
{ | |
$this->bytes = $bytes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function H2FrameIter(string $chunk): Generator { | |
$chunk_size = strlen($chunk); | |
$index = 0; | |
$next = 0; | |
while (true) { | |
if ($next > $chunk_size || $next + 3 > $chunk_size) { | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http.server import HTTPServer, CGIHTTPRequestHandler | |
import ssl | |
def run(host, port, ctx, handler): | |
server = HTTPServer((host, port), handler) | |
server.socket = ctx.wrap_socket(server.socket) | |
print('Server Starts - %s:%s' % (host, port)) | |
try: | |
server.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function dump($chunk, $name) { | |
var_dump( | |
$name, | |
[ | |
'size' => strlen($chunk), | |
'hex' => bin2hex($chunk) | |
] | |
); |
NewerOlder