aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2022-03-31 12:40:05 +0200
committerLinus Nordberg <linus@nordberg.se>2022-03-31 12:40:05 +0200
commit30bc3f64d6fa449e8046e9b62ccacc2076944364 (patch)
treeeef263e76545a3ba34150c72458d7af4bff36cae
parent3cece097ef738b5d954b57684b221ee52e39dfe8 (diff)
add script for testing a HTTP(s) URL
-rwxr-xr-xscripts/testurl.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/testurl.sh b/scripts/testurl.sh
new file mode 100755
index 0000000..0607bae
--- /dev/null
+++ b/scripts/testurl.sh
@@ -0,0 +1,31 @@
+#! /usr/bin/env bash
+set -eu
+
+# Test fetching a HTTP(S) URL and complain if the response code is not
+# 200.
+
+# Example usage:
+# for proto in http https; do
+# for url in er3n3jnvoyj2t37yngvzr35b6f4ch5mgzl3i6qlkvyhzmaxo62nlqmqd.onion www.sigsum.org sigsum.org; do
+# ~/src/testurl.sh $proto://$url/
+# done; done
+
+URL="$1"; shift
+
+torconf=
+echo "$URL" | grep -q \\.onion && torconf="-x socks4a://127.0.0.1:9050/"
+
+function testurl() {
+ family="-$1"
+ response=$(curl "$family" -L -s -w "%{http_code}" "$torconf" "$URL")
+ http_code=$(tail -n1 <<< "$response")
+
+ if [[ "$http_code" != 200 ]]; then
+ echo "$URL: $http_code"
+ false
+ fi
+}
+
+for fam in 4 6; do
+ testurl $fam
+done