Skip to content

Commit

Permalink
Add chunked encoding request body support
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Jun 3, 2018
1 parent 0f75928 commit 8ab65dc
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion bashttpd
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,37 @@ get_request_body() {
if [ ! -z "${length}" ]; then
recv "Reading ${length} byte request body"
head -c "${length}"
else
local encoding="$(get_request_header "transfer-encoding")"
recv "encoding: ${encoding}"
if [ "${encoding}" = "chunked" ]; then
while IFS='' read -r line; do
line=${line%%$'\r'}
recv "$line"

length="$(printf "%d" "0x${line%%$'\n'}")"
recv "Reading ${length} byte chunk"
#head -c "${length}"
dd bs=1 count="${length}" 2>/dev/null

# The next two bytes are supposed to be '\r\n'
recv "Reading 2 byte end"
# TODO: add verification
#head -c "2" > /dev/null
dd bs=1 count=2 of=/dev/null 2>/dev/null

[ "${length}" -eq 0 ] && break
recv "Done with chunk"
done

recv "Done reading chunked body"
#else
# recv "Reading entire request body"
# cat
fi
fi
}


on_uri_match() {
local regex=$1
shift
Expand Down

0 comments on commit 8ab65dc

Please sign in to comment.