Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make curl_opt local variable so it does not leak between requests #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the relevant part

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 $([ -n "$body" ] && 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