|
130 | 130 | if [[ "POST PUT TRACE PATCH DELETE" =~ $method ]]; then local hasbody; hasbody="yes" ;fi
|
131 | 131 |
|
132 | 132 | if [ -d "$cookies" ] ; then # retrieve cookie
|
133 |
| - (mkdir -p "$cookies"; echo "http://localhost*" > "$host") |
| 133 | + (mkdir -p "$cookies"; echo "http://localhost*" >| "$host") |
134 | 134 | fi
|
135 | 135 |
|
136 | 136 | if [[ "$1" =~ ^/ ]] ; then # retrieve path
|
|
143 | 143 | [[ $# -gt 0 ]] && shift
|
144 | 144 | fi
|
145 | 145 |
|
146 |
| - local -a all_opts curlopt_cmd |
| 146 | + local -a all_opts curl_opt curlopt_cmd |
147 | 147 | local raw query vimedit quote maybe_query verbose dry_run
|
148 | 148 |
|
149 | 149 | local -a resty_default_arg host_arg;
|
|
199 | 199 |
|
200 | 200 | if [ "$hasbody" = "yes" ] && [ "$vimedit" = "yes" ]; then
|
201 | 201 | local tmpf; tmpf=$(mktemp)
|
202 |
| - [ -t 0 ] || cat > "$tmpf" |
| 202 | + [ -t 0 ] || cat >| "$tmpf" |
203 | 203 | (exec < /dev/tty; "$editor" "$tmpf")
|
204 | 204 | body=$(cat "$tmpf")
|
205 | 205 | rm -f "$tmpf"
|
|
213 | 213 | fi
|
214 | 214 |
|
215 | 215 | # Forge command and display it if dry-run
|
216 |
| - local cmd |
217 |
| - cmd=(curl -sLv $curl_opt $(printf "%q" "$body") -X $method -b \"$cookies/$domain\" -c \"$cookies/$domain\" "$(\ |
| 216 | + local cmd=(curl -sLv $curl_opt $(printf "%q" "$body") -X $method -b \"$cookies/$domain\" -c \"$cookies/$domain\" "$(\ |
218 | 217 | [ -n "$curlopt_cmd" ] && printf '%s ' ${curlopt_cmd[@]})"\"$_path$query\")
|
219 | 218 | if [ "$dry_run" = "yes" ] ; then
|
220 | 219 | echo "${cmd[@]}"
|
|
224 | 223 | # Launch command and retrieved streams
|
225 | 224 | local res out err ret _status outf errf
|
226 | 225 | outf=$(mktemp) errf=$(mktemp)
|
227 |
| - eval "${cmd[@]}" > "$outf" 2> "$errf" |
| 226 | + eval "${cmd[@]}" >| "$outf" 2>| "$errf" |
228 | 227 | _status=$?; out="$(cat "$outf")"; err="$(cat "$errf")"; rm -f "$outf" "$errf"
|
229 |
| - ret=$(sed '/^.*HTTP\/1\.[01] [0-9][0-9][0-9]/s/.*\([0-9]\)[0-9][0-9].*/\1/p; d' <<< "$err" | tail -n1) |
| 228 | + ret=$(sed '/^.*HTTP\/[12]\(\.[01]\)\? [0-9][0-9][0-9]/s/.*\([0-9]\)[0-9][0-9].*/\1/p; d' <<< "$err" | tail -n1) |
230 | 229 |
|
231 | 230 | if [ "$_status" -ne "0" ]; then echo "$err" >&2 ; return $_status ; fi
|
232 | 231 |
|
|
0 commit comments