]> git.kaiwu.me - haproxy.git/commit
DEV: h2: add mkhdr.c, a C port of mkhdr.sh
authorWilly Tarreau <w@1wt.eu>
Mon, 16 Nov 2026 14:53:44 +0000 (14:53 +0000)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 Nov 2026 10:08:46 +0000 (11:08 +0100)
commitc53aa3f9ddf1d0406baf9ab36b5c1926752eb544
treea6305479a47c8bc279be5f5b989e24f1cdd043fc
parent4773afcce7abf9b317d833b9585c4952fca68816
DEV: h2: add mkhdr.c, a C port of mkhdr.sh

mkhdr.sh forks several processes per frame, which makes it slow when
producing many frames (around 4ms per invocation here, vs 0.2ms for
the C version). This is a port of the script to C, accepting the same
options and producing byte-identical output for valid inputs, with a
few differences:
  - the data file passed with -d is read in binary mode, so NUL bytes
    are preserved (bash's "read" silently drops them);
  - header names and values passed with -e may be longer than 127
    bytes, as their lengths are now properly encoded as HPACK integers,
    and backslash escapes are interpreted there as with -r, the length
    being computed after unescaping;
  - -r, -R and -e may be repeated and combined, their contents being
    concatenated in their order of appearance to form the payload
    (e.g. "-R 4 -r abcd" gives 04 61 62 63 64). An odd number of hex
    digits in -R implies a leading zero;
  - -e no longer forces the frame type to HEADERS, it only changes the
    default type, so that -t always wins regardless of the option order
    (the script would turn "-t c -e foo bar" into a HEADERS frame);
  - -l always sets the frame's length field, which only defaults to the
    payload's length (the script ignored -l when a payload was given).
    This permits to emit a frame header alone and append its payload
    separately, or to advertise a wrong length;
  - options that would otherwise be silently ignored are rejected: any
    option other than -e, -r or -R repeated, -t p with other options,
    -d with -r/-R/-e;
  - the "ACK" flag (0x01) is supported for SETTINGS and PING;
  - unknown flags or invalid hex digits are reported as errors instead
    of being silently ignored;
  - the usage message describes each option on its own line, and is
    sent to stderr on errors.

The output is emitted through a 64kB buffer so that frames are sent in
large blocks (stdio defaults to 4kB on pipes).

It's built with "make dev/h2/mkhdr".
.gitignore
Makefile
dev/h2/mkhdr.c [new file with mode: 0644]