lib/fetcher: Allow clients to append to User-Agent
We do already have `http-headers`, which potentially could be used to allow clients to completely override the field, but it seems like the more common use case is simply to append. Closes: #1496 Approved by: cgwalters
This commit is contained in:
1 parent
296ef25e12
commit
4e4436beec
8 files changed
+94
-9
No files matched your search
+4
-5
@@ -234,10 +234,9 @@ ostree_repo_init() {
|
||||
# The original one; use setup_fake_remote_repo2 for newer code,
|
||||
# down the line we'll try to port tests.
|
||||
setup_fake_remote_repo1() {
|
||||
mode=$1
|
||||
commit_opts=${2:-}
|
||||
args=${3:-}
|
||||
shift
|
||||
mode=$1; shift
|
||||
commit_opts=${1:-}
|
||||
[ $# -eq 0 ] || shift
|
||||
oldpwd=`pwd`
|
||||
mkdir ostree-srv
|
||||
cd ostree-srv
|
||||
@@ -263,7 +262,7 @@ setup_fake_remote_repo1() {
|
||||
mkdir ${test_tmpdir}/httpd
|
||||
cd httpd
|
||||
ln -s ${test_tmpdir}/ostree-srv ostree
|
||||
${OSTREE_HTTPD} --autoexit --log-file $(pwd)/httpd.log --daemonize -p ${test_tmpdir}/httpd-port $args
|
||||
${OSTREE_HTTPD} --autoexit --log-file $(pwd)/httpd.log --daemonize -p ${test_tmpdir}/httpd-port "$@"
|
||||
port=$(cat ${test_tmpdir}/httpd-port)
|
||||
echo "http://127.0.0.1:${port}" > ${test_tmpdir}/httpd-address
|
||||
cd ${oldpwd}
|
||||
|
||||
@@ -27,7 +27,8 @@ echo '1..4'
|
||||
. $(dirname $0)/libtest.sh
|
||||
|
||||
setup_fake_remote_repo1 "archive" "" \
|
||||
"--expected-cookies foo=bar --expected-cookies baz=badger"
|
||||
--expected-cookies foo=bar \
|
||||
--expected-cookies baz=badger
|
||||
|
||||
assert_fail (){
|
||||
if $@; then
|
||||
|
||||
@@ -25,8 +25,13 @@ echo '1..2'
|
||||
|
||||
. $(dirname $0)/libtest.sh
|
||||
|
||||
V=$($CMD_PREFIX ostree --version | \
|
||||
python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin)["libostree"]["Version"])')
|
||||
|
||||
setup_fake_remote_repo1 "archive" "" \
|
||||
"--expected-header foo=bar --expected-header baz=badger"
|
||||
--expected-header foo=bar \
|
||||
--expected-header baz=badger \
|
||||
--expected-header "User-Agent=libostree/$V dodo/2.15"
|
||||
|
||||
assert_fail (){
|
||||
set +e
|
||||
@@ -46,9 +51,22 @@ ${CMD_PREFIX} ostree --repo=repo remote add --set=gpg-verify=false origin $(cat
|
||||
# Sanity check the setup, without headers the pull should fail
|
||||
assert_fail ${CMD_PREFIX} ostree --repo=repo pull origin main
|
||||
|
||||
# without proper User-Agent, the pull should fail
|
||||
assert_fail ${CMD_PREFIX} ostree --repo=repo pull origin main \
|
||||
--http-header foo=bar \
|
||||
--http-header baz=badger
|
||||
assert_fail ${CMD_PREFIX} ostree --repo=repo pull origin main \
|
||||
--http-header foo=bar \
|
||||
--http-header baz=badger \
|
||||
--append-user-agent bar/1.2
|
||||
|
||||
echo "ok setup done"
|
||||
|
||||
# Now pull should succeed now
|
||||
${CMD_PREFIX} ostree --repo=repo pull --http-header foo=bar --http-header baz=badger origin main
|
||||
${CMD_PREFIX} ostree --repo=repo pull \
|
||||
--http-header foo=bar \
|
||||
--http-header baz=badger \
|
||||
--append-user-agent dodo/2.15 \
|
||||
origin main
|
||||
|
||||
echo "ok pull succeeded"
|
||||
Reference in new issue
Block a user