summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xrc/bin/hget9
-rwxr-xr-xrc/bin/hpost37
-rw-r--r--sys/man/1/hget61
3 files changed, 72 insertions, 35 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")
diff --git a/sys/man/1/hget b/sys/man/1/hget
index 393752aa6..70a094b91 100644
--- a/sys/man/1/hget
+++ b/sys/man/1/hget
@@ -4,6 +4,8 @@ hget, hpost \- retrieve, post to a web page corresponding to a url
.SH SYNOPSIS
.B hget
[
+.B -l
+|
.B -o
.I file
] [
@@ -25,10 +27,8 @@ hget, hpost \- retrieve, post to a web page corresponding to a url
.PP
.B hpost
[
-.B -u
-]
-.I url
-[
+.B -l
+] [
.B -g
.I action
] [
@@ -38,6 +38,10 @@ hget, hpost \- retrieve, post to a web page corresponding to a url
.B -m
.I action
] [
+.B -u
+]
+.I url
+[
.I name:value
|
.I name@file
@@ -48,8 +52,10 @@ hget, hpost \- retrieve, post to a web page corresponding to a url
retrieves the web page specified by the URL
.I url
and writes it, absent the
+.B -l
+and
.B -o
-option, to standard output.
+options, to standard output.
.PP
The
.I url
@@ -77,6 +83,18 @@ argument as a string or alternatively with
read from standard input.
.PP
The
+.B -l
+option causes
+.I hget
+and
+.I hpost
+to print the location URL from the transactoin response
+instead of retriving the the body data. This is usefull
+for HTTP POST transactions that redirect to a URL containing
+the prosted data so we wont refetch the data we just uploaded
+to the site.
+.PP
+The
.B -o
option is used to keep a local file in sync with a
web page. If the web page has been modified later than the
@@ -112,17 +130,6 @@ flags, then
is invoked to execute the transaction submitting the form data.
.PP
The
-.B -u
-flag sets the target URL to
-.I url.
-As the
-.I url
-parameter is always required, it can be optionally specified
-in the first argument without the
-.B -u
-flag.
-.PP
-The
.B -g
and
.B -p
@@ -133,6 +140,18 @@ flag sets the form method to POST and its enctype to
In all cases, the form action URL is set to
.I action.
.PP
+The
+.B -u
+flag sets the target URL to
+.I url.
+As the
+.I url
+parameter is always required, the
+.B -u
+flag can be omited when
+.I url
+follows directly after the last option if any.
+.PP
The remaining arguments of the form
.B name:value
are interpreted as text form field names and values to be submitted. An
@@ -152,21 +171,21 @@ Retrieve the commands needed to submit a form, which may then be
edited and sent.
.IP
.EX
-% hpost http://p.intma.in
-/bin/hpost -u http://p.intma.in -p paste.cgi text:
+% hpost -l http://p.intma.in
+/bin/hpost -l -u http://p.intma.in -p paste.cgi text:
.EE
.PP
Manually specify fields to be sent to a given
.I url.
.IP
.EX
-% hpost -u http://p.intma.in -p paste.cgi text:'test post'
+% hpost -l -u http://p.intma.in -p paste.cgi text:'test post'
.EE
.PP
-Upload a file.
+Upload a file, print the resulting URL
.IP
.EX
-% hpost http://i.intma.in file@/tmp/screen.png | rc >/dev/null
+% hpost -l http://i.intma.in file@/tmp/screen.png | rc
.EE
.SH SOURCE
.B /rc/bin/hget