aboutsummaryrefslogtreecommitdiff
path: root/scripts/testurl.sh
blob: a7b49f2b617e96dd01b4d14c26f2af38b2fe27c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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

curl="curl"
echo "$URL" | grep -q \\.onion && curl="$curl -x socks4a://127.0.0.1:9050/"

function testurl() {
    family="-$1"
    response=$($curl "$family" -L -s -w "%{http_code}" "$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