2012-01-11 15:17:54 +00:00
|
|
|
#!/bin/rc
|
2012-05-26 19:18:41 +00:00
|
|
|
rfork e
|
2012-01-11 15:17:54 +00:00
|
|
|
argv0=$0
|
|
|
|
fn usage {
|
2014-03-23 17:47:59 +00:00
|
|
|
echo usage: $argv0 '[ -l | -o file] [ -p body | -P ] [ -r header ] [ -m method ] [ -b baseurl ] url' >[1=2]
|
2012-01-11 15:17:54 +00:00
|
|
|
exit usage
|
|
|
|
}
|
|
|
|
s=0
|
|
|
|
o=()
|
|
|
|
p=()
|
2012-09-15 05:07:19 +00:00
|
|
|
P=()
|
2012-01-11 15:17:54 +00:00
|
|
|
r=()
|
|
|
|
m=()
|
|
|
|
b=()
|
2012-10-18 12:38:07 +00:00
|
|
|
l=()
|
2012-01-11 15:17:54 +00:00
|
|
|
while(~ $1 -*){
|
|
|
|
switch($1){
|
|
|
|
case -o
|
|
|
|
o=$2
|
|
|
|
shift
|
|
|
|
case -p
|
|
|
|
p=$2
|
|
|
|
shift
|
2012-09-15 05:07:19 +00:00
|
|
|
case -P
|
|
|
|
P=1
|
2012-01-11 15:17:54 +00:00
|
|
|
case -r
|
|
|
|
r=($r $2)
|
|
|
|
shift
|
2012-10-18 12:38:07 +00:00
|
|
|
case -l
|
|
|
|
l=1
|
2012-01-11 15:17:54 +00:00
|
|
|
case -m
|
|
|
|
m=$2
|
|
|
|
shift
|
|
|
|
case -b
|
|
|
|
b=$2
|
|
|
|
shift
|
|
|
|
case *
|
|
|
|
usage
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
if(! ~ $#* 1)
|
|
|
|
usage
|
|
|
|
if(! ~ $#o 0){
|
|
|
|
if(! ~ $#o 1)
|
|
|
|
usage
|
|
|
|
if(test -s $o)
|
|
|
|
s=`{ls -l $o | awk '{print $6}'}
|
|
|
|
}
|
2012-09-15 05:07:19 +00:00
|
|
|
<[3=0] <>/mnt/web/clone {
|
2012-01-11 15:17:54 +00:00
|
|
|
d=/mnt/web/^`{sed 1q}
|
|
|
|
if(~ $#b 1)
|
|
|
|
echo -n baseurl $b >[1=0]
|
|
|
|
echo -n url $1 >[1=0]
|
2018-10-10 00:45:11 +00:00
|
|
|
if(! ~ $s 0 && ~ $#p 0 && ~ $#P 0 && ~ $#m 0){
|
|
|
|
for(i in $r)
|
|
|
|
echo -n headers $i >[1=0]
|
|
|
|
echo -n request HEAD >[1=0]
|
|
|
|
<$d/body {
|
|
|
|
if(~ $s `{cat $d/contentlength >[2]/dev/null})
|
|
|
|
exit ''
|
|
|
|
}
|
|
|
|
if(~ $#b 1)
|
|
|
|
echo -n baseurl $b >[1=0]
|
|
|
|
echo -n url $1 >[1=0]
|
|
|
|
r=($r 'Range: bytes='^$s^'-')
|
|
|
|
}
|
2012-01-11 15:17:54 +00:00
|
|
|
for(i in $r)
|
|
|
|
echo -n headers $i >[1=0]
|
|
|
|
if(~ $#m 1)
|
|
|
|
echo -n request $m >[1=0]
|
2012-09-15 05:07:19 +00:00
|
|
|
if(! ~ $#p 0 || ! ~ $#P 0){
|
|
|
|
>$d/postbody {
|
|
|
|
if(! ~ $#p 0)
|
|
|
|
echo -n $"p
|
|
|
|
if(! ~ $#P 0)
|
|
|
|
cat <[0=3]
|
|
|
|
}
|
|
|
|
}
|
2012-01-11 15:17:54 +00:00
|
|
|
<$d/body {
|
2012-10-18 12:38:07 +00:00
|
|
|
if(~ $#l 1){
|
|
|
|
echo `{cat $d/parsed/url}
|
|
|
|
exit
|
|
|
|
}
|
2012-01-11 15:17:54 +00:00
|
|
|
if(~ $#o 1){
|
|
|
|
l=`{cat $d/contentlength >[2]/dev/null}
|
|
|
|
x=`{awk 'BEGIN{FS=" |-"}/^bytes ([0-9]+)\-/{print $2}' \
|
|
|
|
$d/contentrange >[2]/dev/null}
|
|
|
|
if(~ $s $l && ~ $#x 0)
|
|
|
|
exit
|
|
|
|
if(~ $s $x)
|
|
|
|
exec cat >>$o
|
|
|
|
exec cat >$o
|
|
|
|
}
|
2013-10-12 00:22:57 +00:00
|
|
|
c=`{cat $d/contentencoding >[2]/dev/null}
|
|
|
|
switch($c){
|
|
|
|
case *gzip*
|
2015-05-14 12:12:28 +00:00
|
|
|
~ `{cat $d/contenttype >[2]/dev/null} *gzip* || exec gunzip
|
2013-10-12 00:22:57 +00:00
|
|
|
case *bzip2*
|
2015-05-14 12:12:28 +00:00
|
|
|
~ `{cat $d/contenttype >[2]/dev/null} *bzip2* || exec bunzip2
|
2013-10-12 00:22:57 +00:00
|
|
|
case *compress*
|
2015-05-14 12:12:28 +00:00
|
|
|
~ `{cat $d/contenttype >[2]/dev/null} *compress* || exec uncompress
|
2013-10-12 00:22:57 +00:00
|
|
|
}
|
2012-01-11 15:17:54 +00:00
|
|
|
exec cat
|
|
|
|
}
|
|
|
|
}
|