]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEV: h2: support hex-encoded data sequences in mkhdr
authorWilly Tarreau <w@1wt.eu>
Fri, 12 Jan 2024 16:53:50 +0000 (17:53 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Jan 2024 17:59:59 +0000 (18:59 +0100)
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

dev/h2/mkhdr.sh

index c77eb3dd4051aaaac2b0e29fb44b382e9a169c4c..4ed1a07827c864ea08f6578ad63839701b9db1ad 100755 (executable)
@@ -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 ;;