DEV: h2: support reading frame payload from a file

Now we can build a series of data frames by reading from a file and
chunking it into frames of requested length. It's mostly useful for
data frames (e.g. post). One way to announce these upfront is to
capture the output of curl use without content-length:

  $ nc -lp4446 > post-h2-nocl.bin
  $ curl -v --http2-prior-knowledge http://127.0.0.1:4446/url -H "content-length:" -d @/dev/null

Then just change the 5th byte from the end from 1 to 0 to remove the
end-of-stream bit, it will allow to chain a file, then to send an
empty DATA frame with ES set :

  $ (dev/h2/mkhdr.sh -i 1 -t data -d CHANGELOG;
     dev/h2/mkhdr.sh -i 1 -t data -l 0 -f es) > h2-data-changelog.bin

Then post that to the server:
  $ cat post-h2-nocl.bin h2-data-changelog.bin | nc 0 4446
This commit is contained in:
Willy Tarreau 2023-04-26 11:25:46 +02:00
parent 78bb934607
commit e8ae99b111
1 changed files with 16 additions and 3 deletions

View File

@ -4,8 +4,9 @@
# All fields are optional. 0 assumed when absent.
USAGE=\
"Usage: %s [-l <len>] [-t <type>] [-f <flags>] [-i <sid>] > hdr.bin
Numbers are decimal or 0xhex. Not set=0.
"Usage: %s [-l <len> ] [-t <type>] [-f <flags>] [-i <sid>] [ -d <data> ] > 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.
Supported symbolic types (case insensitive prefix match):
DATA (0x00) PUSH_PROMISE (0x05)
@ -108,6 +109,7 @@ while [ -n "$1" -a -z "${1##-*}" ]; do
-t) TYPE="$2" ; shift 2 ;;
-f) FLAGS="$2" ; shift 2 ;;
-i) ID="$2" ; shift 2 ;;
-d) DATA="$2" ; shift 2 ;;
-h|--help) usage "${0##*}"; quit;;
*) usage "${0##*}"; die ;;
esac
@ -133,6 +135,17 @@ if [ -n "${ID##[0-9]*}" ]; then
die
fi
mkframe "$LEN" "$TYPE" "$FLAGS" "$ID"
if [ -z "$DATA" ]; then
mkframe "$LEN" "$TYPE" "$FLAGS" "$ID"
else
# read file $DATA in <LEN> chunks and send it in multiple frames
# advertising their respective lengths.
[ $LEN -gt 0 ] || LEN=16384
while read -rN "$LEN" payload || [ ${#payload} -gt 0 ]; do
mkframe "${#payload}" "$TYPE" "$FLAGS" "$ID"
echo -n "$payload"
done < "$DATA"
fi
exit 0