DEV: h2: support hex-encoded data sequences in mkhdr

For HPACK-encoded headers (particularly with huffman encoding), it's
really necessary to support hex sequences as they appear in RFC7541
examples, so let's support hex digit pairs with -R.

Now it's possible to do this to send GET https://www.example.com/ :

    (dev/h2/mkhdr.sh -t p; dev/h2/mkhdr.sh -t s;
     dev/h2/mkhdr.sh -t h -i 1 -f es,eh \
     -R '8286 8441 0f77 7777 2e65 7861 6d70 6c65 2e63 6f6d ') | nc 0 8080
This commit is contained in:
Willy Tarreau 2024-01-12 17:53:50 +01:00
parent 5bf19f8b57
commit f3a19e70e8
1 changed files with 4 additions and 2 deletions

View File

@ -5,11 +5,12 @@
USAGE=\
"Usage: %s [-l <len> ] [-t <type>] [-f <flags>[,...]] [-i <sid>] [ -d <data> ]
[ -e <name> <value> ]* [ -r raw ] [ -h | --help ] > hdr.bin
[ -e <name> <value> ]* [ -r|-R raw ] [ -h | --help ] > hdr.bin
Numbers are decimal or 0xhex. Not set=0. If <data> is passed, it points
to a file that is read and chunked into frames of <len> bytes. -e
encodes a headers frame (by default) with all headers at once encoded
in literal. Use type 'p' for the preface. Use -r to pass raw hex data.
in literal. Use type 'p' for the preface. Use -r to pass raw data or
-R to pass raw hex codes (hex digit pairs, blanks ignored).
Supported symbolic types (case insensitive prefix match):
DATA (0x00) PUSH_PROMISE (0x05)
@ -136,6 +137,7 @@ while [ -n "$1" -a -z "${1##-*}" ]; do
-i) ID="$2" ; shift 2 ;;
-d) DATA="$2" ; shift 2 ;;
-r) RAW="$2" ; shift 2 ;;
-R) RAW="$(printf $(echo -n "${2// /}" | sed -e 's/\([^ ][^ ]\)/\\\\x\1/g'))" ; shift 2 ;;
-e) TYPE=1; HDR[${#HDR[@]}]="$2=$3"; shift 3 ;;
-h|--help) usage "${0##*}"; quit;;
*) usage "${0##*}"; die ;;