3 [ "$include_multipart" ] && return 0
6 if [ "${CONTENT_TYPE}" -a ! "${CONTENT_TYPE##multipart/form-data;*}" ]; then
7 multipart_boundary="${CONTENT_TYPE#*; boundary=}"
8 multipart_boundary="${multipart_boundary%%;*}"
9 multipart_boundary="${multipart_boundary%${CR}}"
11 multipart_cachefile="/tmp/multipart.$$"
14 # read n bytes, like `head -c` but do not consume input
17 for block in 65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1; do
18 if [ $size -ge $block ]; then
19 dd status=none bs="$block" count="$((size / block))"
20 size="$((size % block))"
26 multipart_cachefile="${1:-${multipart_cachefile}}" # global
28 if [ "${multipart_boundary}" ]; then
29 # readbytes "$(( CONTENT_LENGTH ))" >"${multipart_cachefile}"
30 head -c "$(( CONTENT_LENGTH ))" >"${multipart_cachefile}"
37 local name="$1" count="${2:-1}"
38 local formdata state=begin
40 while IFS='' read -r formdata; do case "$formdata" in
41 "--${multipart_boundary}--${CR}")
42 [ $state = data ] && return 0 \
45 "--${multipart_boundary}${CR}")
46 [ $state = data ] && return 0 \
49 "Content-Disposition: form-data; name=\"${name}\""*"${CR}")
50 [ $state = header -a $count -eq 1 ] && state=dheader
51 [ $state = header -a $count -gt 1 ] && count=$((count - 1))
52 [ $state = data ] && printf "%s\n" "$formdata"
55 if [ $state = dheader ]; then
56 # Do not use `sed -n` (or busybox sed will "convert" NULL to LF)
57 sed "/--${multipart_boundary}\(--\)\?${CR}/{x;q;}" \
61 [ $state = header ] && state=junk
63 esac; done <"${multipart_cachefile}"
67 local name="$1" count="${2:-1}"
68 local formdata state=begin
70 while read -r formdata; do case "$formdata" in
71 "--${multipart_boundary}--${CR}")
74 "--${multipart_boundary}${CR}")
77 "Content-Disposition: form-data; name=\"${name}\"; filename=\""*"\""*"${CR}")
78 [ $state = header -a $count -eq 1 ] && break
79 [ $state = header -a $count -gt 1 ] && count=$((count - 1))
82 [ $state = header ] && state=junk
84 esac; done <"${multipart_cachefile}"
86 filename="${formdata#*; filename=\"}"
87 filename="${filename%%\"${CR}}"
88 filename="${filename%%\";*}"
90 HEX_DECODE % "$filename"