Commit 6644f4ac authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: real get_filename implementation

parent 7314c270
...@@ -710,10 +710,37 @@ url_check() ...@@ -710,10 +710,37 @@ url_check()
__wget --spider -S "$URL" 2>&1 | grep "HTTP/" | tail -n1 | grep -q "200" __wget --spider -S "$URL" 2>&1 | grep "HTTP/" | tail -n1 | grep -q "200"
} }
url_get_headers()
{
local URL="$1"
__wget --spider -S "$URL" 2>&1 | grep "^ [A-Z].*: " | sed -e 's|^ ||'
}
url_get_header()
{
local URL="$1"
local HEADER="$2"
url_get_headers "$URL" | grep "^$HEADER: " | sed -e "s|^$HEADER: ||"
}
url_get_filename() url_get_filename()
{ {
# FIXME local URL="$1"
basename "$1" # FIXME with wget
local cd="$(url_get_header "$URL" "Content-Disposition")"
if echo "$cd" | grep -q "filename=" ; then
#Content-Disposition: attachment; filename=postman-linux-x64.tar.gz
echo "$cd" | sed -e 's|.*filename=||'
return
fi
local loc="$(url_get_header "$URL" "Location" | tail -n1)"
if is_url "$loc" ; then
basename "$loc"
return
fi
basename "$URL"
} }
else else
...@@ -755,10 +782,38 @@ url_check() ...@@ -755,10 +782,38 @@ url_check()
__curl -LI "$URL" 2>&1 | grep "HTTP/" | tail -n1 | grep -q -w "200\|404" __curl -LI "$URL" 2>&1 | grep "HTTP/" | tail -n1 | grep -q -w "200\|404"
} }
url_get_headers()
{
local URL="$1"
__curl -LI "$URL" 2>&1 | grep "^[a-z].*: " | sed -e 's|\r$||'
}
# TODO: the same code in wget case, but there other header names
url_get_header()
{
local URL="$1"
local HEADER="$2"
url_get_headers "$URL" | grep "^$HEADER: " | sed -e "s|^$HEADER: ||"
}
url_get_filename() url_get_filename()
{ {
# FIXME local URL="$1"
basename "$1" # FIXME with wget
local cd="$(url_get_header "$URL" "content-disposition")"
if echo "$cd" | grep -q "filename=" ; then
#Content-Disposition: attachment; filename=postman-linux-x64.tar.gz
echo "$cd" | sed -e 's|.*filename=||'
return
fi
local loc="$(url_get_header "$URL" "location" | tail -n1)"
if is_url "$loc" ; then
basename "$loc"
return
fi
basename "$URL"
} }
...@@ -938,7 +993,6 @@ get_urls() ...@@ -938,7 +993,6 @@ get_urls()
} }
if [ -n "$CHECKURL" ] ; then if [ -n "$CHECKURL" ] ; then
#set_quiet #set_quiet
check_url_is_accessible "$1" check_url_is_accessible "$1"
......
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