Files
flatpak/tests/test-webserver.sh
Owen W. Taylor 951aed561a Add flatpak_cache_http_uri: cache downloads based on HTTP headers
Add a new function, flatpak_cache_http_uri() that when passed an URL and
a local destination location, either a) downloads the content and stores
it at the destination location, storing HTTP cache header information
like Last-Modified, Etag into user xattrs (if available) or a separate
file or b) if the downloaded content is already present, checks the
header information to decide whether the downloaded content can be used
or needs to be revalidated witha conditional request.

Tests are added that use a special case test server that adds HTTP caching
headers and reacts to them based on query parameters. A small test binary
'httpcache' is added for the tests to use.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00

33 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
dir=$1
cmd=${2:-python -m SimpleHTTPServer 0}
test_tmpdir=$(pwd)
[ "$dir" != "" ] && cd ${dir}
env PYTHONUNBUFFERED=1 setsid $cmd >${test_tmpdir}/httpd-output &
child_pid=$!
echo "Web server pid: $child_pid" >&2
for x in $(seq 300); do
echo "Waiting for web server ($x/300)..." >&2
# Snapshot the output
cp ${test_tmpdir}/httpd-output{,.tmp}
sed -ne 's/^/# httpd-output.tmp: /' < ${test_tmpdir}/httpd-output.tmp >&2
echo >&2
# If it's non-empty, see whether it matches our regexp
if test -s ${test_tmpdir}/httpd-output.tmp; then
sed -e 's,Serving HTTP on 0.0.0.0 port \([0-9]*\) \.\.\.,\1,' < ${test_tmpdir}/httpd-output.tmp > ${test_tmpdir}/httpd-port
if ! cmp ${test_tmpdir}/httpd-output.tmp ${test_tmpdir}/httpd-port 1>/dev/null; then
# If so, we've successfully extracted the port
break
fi
fi
sleep 0.1
done
port=$(cat ${test_tmpdir}/httpd-port)
echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
echo "$child_pid" > ${test_tmpdir}/httpd-pid