Skip to content

Commit

Permalink
Make curl_opt local variable so it does not leak between requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiril Angov committed Mar 21, 2018
1 parent cefdcb1 commit f665ddf
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions resty
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ HELP
if [[ "POST PUT TRACE PATCH DELETE" =~ $method ]]; then local hasbody; hasbody="yes" ;fi

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

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

local -a all_opts curlopt_cmd
local -a all_opts curl_opt curlopt_cmd
local raw query vimedit quote maybe_query verbose dry_run

local -a resty_default_arg host_arg;
Expand Down Expand Up @@ -199,7 +199,7 @@ HELP

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

# Forge command and display it if dry-run
local cmd
cmd=(curl -sLv $curl_opt $(printf "%q" "$body") -X $method -b \"$cookies/$domain\" -c \"$cookies/$domain\" "$(\
local cmd=(curl -sLv $curl_opt $(printf "%q" "$body") -X $method -b \"$cookies/$domain\" -c \"$cookies/$domain\" "$(\
[ -n "$curlopt_cmd" ] && printf '%s ' ${curlopt_cmd[@]})"\"$_path$query\")
if [ "$dry_run" = "yes" ] ; then
echo "${cmd[@]}"
Expand All @@ -224,9 +223,9 @@ HELP
# Launch command and retrieved streams
local res out err ret _status outf errf
outf=$(mktemp) errf=$(mktemp)
eval "${cmd[@]}" > "$outf" 2> "$errf"
eval "${cmd[@]}" >| "$outf" 2>| "$errf"
_status=$?; out="$(cat "$outf")"; err="$(cat "$errf")"; rm -f "$outf" "$errf"
ret=$(sed '/^.*HTTP\/1\.[01] [0-9][0-9][0-9]/s/.*\([0-9]\)[0-9][0-9].*/\1/p; d' <<< "$err" | tail -n1)
ret=$(sed '/^.*HTTP\/[12]\(\.[01]\)\? [0-9][0-9][0-9]/s/.*\([0-9]\)[0-9][0-9].*/\1/p; d' <<< "$err" | tail -n1)

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

Expand Down

0 comments on commit f665ddf

Please sign in to comment.