Skip to content

Commit f665ddf

Browse files
author
Kiril Angov
committed
Make curl_opt local variable so it does not leak between requests
1 parent cefdcb1 commit f665ddf

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

resty

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ HELP
130130
if [[ "POST PUT TRACE PATCH DELETE" =~ $method ]]; then local hasbody; hasbody="yes" ;fi
131131

132132
if [ -d "$cookies" ] ; then # retrieve cookie
133-
(mkdir -p "$cookies"; echo "http://localhost*" > "$host")
133+
(mkdir -p "$cookies"; echo "http://localhost*" >| "$host")
134134
fi
135135

136136
if [[ "$1" =~ ^/ ]] ; then # retrieve path
@@ -143,7 +143,7 @@ HELP
143143
[[ $# -gt 0 ]] && shift
144144
fi
145145

146-
local -a all_opts curlopt_cmd
146+
local -a all_opts curl_opt curlopt_cmd
147147
local raw query vimedit quote maybe_query verbose dry_run
148148

149149
local -a resty_default_arg host_arg;
@@ -199,7 +199,7 @@ HELP
199199

200200
if [ "$hasbody" = "yes" ] && [ "$vimedit" = "yes" ]; then
201201
local tmpf; tmpf=$(mktemp)
202-
[ -t 0 ] || cat > "$tmpf"
202+
[ -t 0 ] || cat >| "$tmpf"
203203
(exec < /dev/tty; "$editor" "$tmpf")
204204
body=$(cat "$tmpf")
205205
rm -f "$tmpf"
@@ -213,8 +213,7 @@ HELP
213213
fi
214214

215215
# 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\" "$(\
218217
[ -n "$curlopt_cmd" ] && printf '%s ' ${curlopt_cmd[@]})"\"$_path$query\")
219218
if [ "$dry_run" = "yes" ] ; then
220219
echo "${cmd[@]}"
@@ -224,9 +223,9 @@ HELP
224223
# Launch command and retrieved streams
225224
local res out err ret _status outf errf
226225
outf=$(mktemp) errf=$(mktemp)
227-
eval "${cmd[@]}" > "$outf" 2> "$errf"
226+
eval "${cmd[@]}" >| "$outf" 2>| "$errf"
228227
_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)
230229

231230
if [ "$_status" -ne "0" ]; then echo "$err" >&2 ; return $_status ; fi
232231

0 commit comments

Comments
 (0)