From: Willy Tarreau Date: Fri, 12 Jan 2024 16:53:50 +0000 (+0100) Subject: DEV: h2: support hex-encoded data sequences in mkhdr X-Git-Tag: v3.0-dev2~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3a19e70e8e1aeb25d3efe9392ce620569de4e8f;p=thirdparty%2Fhaproxy.git 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 --- diff --git a/dev/h2/mkhdr.sh b/dev/h2/mkhdr.sh index c77eb3dd40..4ed1a07827 100755 --- a/dev/h2/mkhdr.sh +++ b/dev/h2/mkhdr.sh @@ -5,11 +5,12 @@ USAGE=\ "Usage: %s [-l ] [-t ] [-f [,...]] [-i ] [ -d ] - [ -e ]* [ -r raw ] [ -h | --help ] > hdr.bin + [ -e ]* [ -r|-R raw ] [ -h | --help ] > hdr.bin Numbers are decimal or 0xhex. Not set=0. If is passed, it points to a file that is read and chunked into frames of 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 ;;