#!/bin/rc
rfork e
url=()
+headers=()
+action=()
+method=()
at=() # text fields
af=() # file fields
l=()
fn usage {
- echo 'usage: hpost [ -l ] [ -[gpm] action ] [ -u ] url [ field:value | field@file ... ]' >[1=2]
+ echo 'usage: hpost [ -l ] [ -[gpm] action ] [ -r header ] [ -u ] url [ field:value | field@file ... ]' >[1=2]
exit usage
}
switch($1){
case -l; l=($l $1)
case -u; shift; url=$1
+ case -r; shift; headers=($headers -r $1)
case -g; shift; action=$1; method=mget
case -p; shift; action=$1; method=mpost
case -m; shift; action=$1; method=multi
}
for(i in $af){
k=`{sed 's!@.*$!!; q' /env/i}
- v=`{sed 's!^[^@]+@!!' /env/i}
+ ifs='
+' v=`{sed 's!^[^@]+@!!' /env/i}
t=`{file -m $v}
n=`{basename $v}
echo '--'$"f$"cr
menc $"f | $hget -r 'Content-Type: multipart/form-data; boundary='$"f -b $url -P $action
}
+
if(! ~ $action ''){
- hget=(hget $l)
+ hget=(hget $headers $l)
$method
exit
}