summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share/media/http.subr
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bsdconfig/share/media/http.subr')
-rw-r--r--usr.sbin/bsdconfig/share/media/http.subr27
1 files changed, 19 insertions, 8 deletions
diff --git a/usr.sbin/bsdconfig/share/media/http.subr b/usr.sbin/bsdconfig/share/media/http.subr
index a904d01..1236c99 100644
--- a/usr.sbin/bsdconfig/share/media/http.subr
+++ b/usr.sbin/bsdconfig/share/media/http.subr
@@ -510,13 +510,15 @@ f_media_init_http()
return $http_found
}
-# f_media_get_http $device $file [$probe_only]
+# f_media_get_http $device $file [$probe_type]
#
# Returns data from $file on an HTTP server using nc(1). Please note that
# $device is unused but must be present (even if null). Information is instead
-# gathered from the environment. If $probe_only is both present and non-NULL,
+# gathered from the environment. If $probe_type is both present and non-NULL,
# this function exits after receiving the HTTP header response from the server
# (if the HTTP response code is 200, success is returned; otherwise failure).
+# If $probe_type is equal to $PROBE_SIZE, prints the content-length in bytes
+# from the response (or -1 if not found) to standard-out.
#
# The variables used to configure the connection are as follows (all of which
# are configured by f_media_set_http above):
@@ -542,10 +544,10 @@ f_media_init_http()
#
f_media_get_http()
{
- local dev="$1" file="$2" probe_only="$3" hosts=
+ local dev="$1" file="$2" probe_type="$3" hosts=
- f_dprintf "f_media_get_http: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_http: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
local http_host http_port
f_getvar $VAR_HTTP_HOST http_host
@@ -591,7 +593,7 @@ f_media_get_http()
# this is extremely quick'n dirty
#
- rv=0
+ rv=0 length=-1
while read LINE; do
case "$LINE" in
HTTP*)
@@ -599,6 +601,12 @@ f_media_get_http()
set -- $LINE; rv=$2
f_isinteger "$rv" || rv=0
;;
+ "Content-Length: "*)
+ length="${LINE% }"
+ length="${length#Content-Length: }"
+ f_dprintf "received content-length: %s" \
+ "$length"
+ ;;
*)
[ "${LINE% }" ] || break # End of headers
esac
@@ -610,14 +618,17 @@ f_media_get_http()
[ $rv -ge 300 ] && exit 3
[ $rv -eq 200 ] || exit $FAILURE
- if [ ! "$probe_only" ]; then
+ if [ ! "$probe_type" ]; then
cat # output the rest ``as-is''
+ elif [ "$probe_type" = "$PROBE_SIZE" ]; then
+ f_isinteger "$length" || length=-1
+ echo "$length"
fi
exit 200
)
local retval=$?
[ $retval -eq 200 ] && return $SUCCESS
- [ "$probe_only" ] && return $FAILURE
+ [ "$probe_type" ] && return $FAILURE
case "$retval" in
5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
OpenPOWER on IntegriCloud