diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-10-18 14:38:07 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-10-18 14:38:07 +0200 |
commit | 7c3ea4360b64579ce63d85337fdefdbba565f312 (patch) | |
tree | 012b0991bf79576d170ff1aae4264ebaa8c273d4 /rc | |
parent | 909efb22c516c3c685159a954f164469a064e5a7 (diff) |
hpost: add -l flag to get location url after POST
Diffstat (limited to 'rc')
-rwxr-xr-x | rc/bin/hget | 9 | ||||
-rwxr-xr-x | rc/bin/hpost | 37 |
2 files changed, 32 insertions, 14 deletions
diff --git a/rc/bin/hget b/rc/bin/hget index 191646a97..bb50a899b 100755 --- a/rc/bin/hget +++ b/rc/bin/hget @@ -2,7 +2,7 @@ rfork e argv0=$0 fn usage { - echo 'usage: '$"argv0' [ -o file ] [ -p body | -P ] [ -r header ] [ -m method ] [ -b baseurl ] url' >[1=2] + echo usage: $argv0 '[ -l | -o file] [ -p body | -P ] [ -r header ] [ -m method ] [ -b baseurl ] url' >[1=2] exit usage } s=0 @@ -12,6 +12,7 @@ P=() r=() m=() b=() +l=() while(~ $1 -*){ switch($1){ case -o @@ -25,6 +26,8 @@ while(~ $1 -*){ case -r r=($r $2) shift + case -l + l=1 case -m m=$2 shift @@ -64,6 +67,10 @@ if(! ~ $s 0) } } <$d/body { + if(~ $#l 1){ + echo `{cat $d/parsed/url} + exit + } if(~ $#o 1){ l=`{cat $d/contentlength >[2]/dev/null} x=`{awk 'BEGIN{FS=" |-"}/^bytes ([0-9]+)\-/{print $2}' \ diff --git a/rc/bin/hpost b/rc/bin/hpost index 2b07ef14b..4885cb40b 100755 --- a/rc/bin/hpost +++ b/rc/bin/hpost @@ -4,24 +4,36 @@ argv0=$0 url=() at=() # text fields af=() # file fields +l=() fn usage { - echo $argv0 '[ -u ] url [ -[gpm] action ] [ field:value | field@file ... ]' >[1=2] + echo usage: $argv0 '[ -l ] [ -[gpm] action ] [ -u ] url [ field:value | field@file ... ]' >[1=2] exit usage } +while(~ $1 -*){ + switch($1){ + case -l; l=($l $1) + case -u; shift; url=$1 + case -g; shift; action=$1; method=mget + case -p; shift; action=$1; method=mpost + case -m; shift; action=$1; method=multi + case *; usage + } + shift +} + # tired of typing -u if(~ $1 http://* https://*){ url=$1 shift } +if(~ $#url 0) + usage + while(! ~ $#* 0){ switch($1){ - case -u; shift; url=$1 - case -g; shift; action=$1; method=mget - case -p; shift; action=$1; method=mpost - case -m; shift; action=$1; method=multi case *:*@*; at=($1 $at) case *@*; af=($1 $af) case *:*; at=($1 $at) @@ -30,8 +42,7 @@ while(! ~ $#* 0){ shift } -if(~ $#url 0) - usage +hpost=($argv0 $l) fn uenc { f=$1 @@ -74,17 +85,18 @@ fn menc { fn mget { a=`{uenc '?'} action=$"action$"a - hget -b $url $action + $hget -b $url $action } fn mpost { - uenc | hget -b $url -P $action + uenc | $hget -b $url -P $action } 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) $method exit } @@ -97,14 +109,13 @@ for(i in $at $af){ n=(1 $n) } a$#n='' - hget $url | uhtml | 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 # find attributes, mark with ATT name value s!([a-zA-Z][a-zA-Z0-9:_]*)=("[^"]*"?|''[^'']*''?|[ ]*[^> ]+)!\nATT \1 \2!g; -' | awk -v 'argv0='$"argv0 -v 'url='$"url ' +' | awk -v 'hpost='$"hpost -v 'url='$"url ' BEGIN{ for(i=0; ENVIRON["a"i]!=""; i++){ s=ENVIRON["a"i] @@ -133,7 +144,7 @@ function uq(s){ } function emitform(){ if(action!=""){ - printf argv0 + printf hpost if(url!="") printf " -u %s", qw(url) if(method=="post"){ if(enctype=="multipart/form-data") |