aboutsummaryrefslogtreecommitdiff
path: root/bin/urlh
blob: a9ea93fde6fef46b8fd35ee85a00b1b8bfa0288d (plain) (blame)
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
#!/bin/sh
# Get values for HTTP headers for the given URL

# Check arguments
if [ "$#" -ne 2 ] ; then
    printf 'urlt: Need an URL and a header name\n'
    exit 2
fi
url=$1 header=$2

# Run cURL header request
curl -I -- "$url" |

# Unfold the headers
unf | 

# Use awk to find any values for the header case-insensitively
awk -v header="$header" '
BEGIN {
    FS=": *"
    header = tolower(header)
}
tolower($1) == header {
    sub(/^[^ ]*: */, "")
    print
}
'