Commit 6c17b21f authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: add redirect depth limit to url_get_raw_real_url

parent 6bd6a9fb
......@@ -2031,8 +2031,15 @@ url_get_raw_real_url()
[ -n "$MADEURL" ] && [ "$MADEURL" = "$URL" ] && echo "$URL" && return
local loc base="$URL"
local redirect_count=0
local max_redirects=10
# follow redirect chain in order, updating base URL at each step
for loc in $(url_get_header "$URL" "Location" | sed -e 's| .*||') ; do
redirect_count=$(($redirect_count + 1))
if [ "$redirect_count" -gt "$max_redirects" ] ; then
echo "Warning: too many redirects (>$max_redirects) for $URL" >&2
break
fi
# add protocol if missed
if is_protocol_relative_url "$loc" ; then
loc="$(echo "$base" | sed -e 's|//.*||')$loc"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment