]> git.lizzy.rs Git - plan9front.git/blobdiff - rc/bin/hpost
Remove ap(1)
[plan9front.git] / rc / bin / hpost
index cab9c0be58c0f13fb910ca686011d10d53104fd7..4a43516b6bb5368709c26f073c7b58ff47f49c4e 100755 (executable)
@@ -1,12 +1,15 @@
 #!/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
 }
 
@@ -14,6 +17,7 @@ while(~ $1 -*){
        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
@@ -58,16 +62,17 @@ fn menc {
        f=$1
        cr=`{echo x | tr x \015}
        for(i in $at){
-               k=`{sed 's!:.*$!!' /env/i}
+               k=`{sed 's!:.*$!!; q' /env/i}
                echo '--'$"f$"cr
                echo 'Content-Disposition: form-data; name="'$"k'"'$"cr
                echo $"cr
                i=$"i$"cr
-               sed 's!^[^:]+:!!' /env/i
+               sed '1s!^[^:]+:!!' /env/i
        }
        for(i in $af){
-               k=`{sed 's!@.*$!!' /env/i}
-               v=`{sed 's!^[^@]+@!!' /env/i}
+               k=`{sed 's!@.*$!!; q' /env/i}
+       ifs='
+'      v=`{sed 's!^[^@]+@!!' /env/i}
                t=`{file -m $v}
                n=`{basename $v}
                echo '--'$"f$"cr
@@ -90,11 +95,12 @@ fn mpost {
 }
 fn multi {
        f='HJBOUNDARY'
-       menc $"f | $hget -r 'Content-Type: multipart/form-data, boundary='$"f -b $url -P $action
+       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
 }
@@ -107,7 +113,8 @@ for(i in $at $af){
        n=(1 $n)
 }
 a$#n=''
-hget $url | uhtml | sed '
+hget $url | uhtml | tr '>' '
+' | sed '
 s!^(TAG|ATT)! \1!g;            # escape our inline signaling
 s!<[   ]*!\nTAG !g;            # find starttags, mark with TAG name ...
 s!>[^>"'']*$!!g;               # remove garbage after the tag