1 ########################################################################
3 # This software is part of the ast package #
4 # Copyright (c) 1994-2016 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Eclipse Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
9 # A copy of the License is available at #
10 # http://www.eclipse.org/org/documents/epl-v10.html #
11 # (with md5 checksum b35adb5213ca9657e911e9befb180842) #
13 # Information and Software Systems Research #
17 # Glenn Fowler <glenn.s.fowler@gmail.com> #
19 ########################################################################
20 ########################################################################
22 # This software is part of the ast package #
23 # Copyright (c) 1994-2011 AT&T Intellectual Property #
24 # and is licensed under the #
25 # Eclipse Public License, Version 1.0 #
26 # by AT&T Intellectual Property #
28 # A copy of the License is available at #
29 # http://www.eclipse.org/org/documents/epl-v10.html #
30 # (with md5 checksum b35adb5213ca9657e911e9befb180842) #
32 # Information and Software Systems Research #
36 # Glenn Fowler <glenn.s.fowler@gmail.com> #
38 ########################################################################
42 agent
="$command/2009-01-20 (AT&T Research)"
46 case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
47 0123) ARGV0
="-a $command"
50 @(#)$Id: hurl (AT&T Research) 2009-01-20 $
53 [+NAME?hurl - copy http url data]
54 [+DESCRIPTION?\bhurl\b copies the data for the \bhttp\b \aurl\a operand
55 to the standard output. The \aurl\a must be of the form
56 \b[http://]]\b\ahost\a[\b:\b\aport\a]]\b/\b\apath\a. The default
58 [+?\bhurl\b is a shell script that attempts to access the \aurl\a by
60 [+/dev/tcp/\ahost\a\b/80\b?Supported by \bksh\b(1) and recent
62 [+wget -nv -O - \aurl\a?]
63 [+lynx -source \aurl\a?]
64 [+curl -s -L -o - \aurl\a?]
66 [a:authorize?The url authorization user name and password, separated
67 by \b:\b (one colon character.)]:[user::password]
68 [s:size?Terminate the data transmission after \abytes\a have been
70 [v:verbose?Verbose trace.]
74 [+SEE ALSO?\bcurl\b(1), \blynx\b(1), \bwget\b(1)]
85 getopts $ARGV0 "$USAGE" OPT
'-?'
89 integer limit
=0 total
=0 block
=8*1024
91 while getopts $ARGV0 "$USAGE" OPT
93 a
) authorize
=$OPTARG ;;
98 shift `expr $OPTIND - 1`
106 do test 0 != $verbose && echo "$command: url=$url" >&2
108 *://*/*)prot
=${url%%:*}
125 test 0 != $verbose && echo "$command: prot=$prot host=$host port=$port path=$path" >&2
127 http
) if (eval "exec >" ||
exit 0) 2>/dev
/null
&&
128 eval "exec 8<> /dev/tcp/\$host/$port" 2>/dev
/null
129 then test 0 != $verbose && echo "$command: using /dev/tcp/$host/$port" >&2
130 if ! echo "GET $path HTTP/1.0
132 User-Agent: $agent
${AUTHORIZE}
134 then echo "$command: $host: write error"
138 if ! read prot code text
139 then echo "$command: $host: read error" >&2
145 test 0 != $verbose && echo "$command: prot=$prot code=$code $text" >&2
147 do if ! read head data
148 then echo "$command: $host: read error" >&2
151 test 0 != $verbose && echo "$command: head=$head $data" >&2
173 then (( limit
= (limit
+ block
- 1) / block
))
174 dd bs
=$block count
=$limit silent
=1
180 if [[ $AUTHORIZE ||
$type != Basic
]]
181 then print authorization failed
184 if [[ ! $authorize ]]
186 then print authorization failed
189 print
-n "Enter user name for $realm: "
191 print
-n "Password: "
192 trap 'stty echo <&9' 0 1 2 3 15
198 authorize
=$user:$password
200 AUTHORIZE
=$
'\nAuthorization: '$type' '$
(print
-n -r -- "$authorize" |
uuencode -h -x base64
)$
'\r'
204 *) echo "$0: $url: $code: $text" >&2
209 elif wget
${authorize:+--http-user="${authorize%:*}"} ${password:+--http-passwd="${password##*:}"} -nv -O - $url 2>/dev
/null
210 then test 0 != $verbose && echo "$command: using wget" >&2
212 elif lynx
${authorize:+-auth "$authorize"} -source $url 2>/dev
/null
213 then test 0 != $verbose && echo "$command: using wget" >&2
215 elif curl
${authorize:+-u "$authorize"} -s -L -o - $url 2>/dev
/null
216 then test 0 != $verbose && echo "$command: using curl" >&2
218 else echo "$command: $url: { /dev/tcp/$host/$port wget curl } failed" >&2
222 *) echo "$command: $prot: protocol not supported" >&2