-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_proxy.sh
More file actions
executable file
·117 lines (96 loc) · 5.17 KB
/
Copy pathverify_proxy.sh
File metadata and controls
executable file
·117 lines (96 loc) · 5.17 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
# Usage: ./verify_proxy.sh [hls_master_url]
# Default URL is the shaka-ll stream if none is provided.
PROXY="http://127.0.0.1:9000"
REMOTE="${1:-[URL]/shaka-ll/master.m3u8}"
enc() { python3 -c "import urllib.parse,sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$1"; }
dec() { python3 -c "import urllib.parse,sys; print(urllib.parse.unquote(sys.argv[1]))" "$1"; }
ms() { python3 -c "import time; print(int(time.time() * 1000))"; }
pass=0; fail=0
ok() { echo " ✓ $1"; pass=$(( pass + 1 )); }
ng() { echo " ✗ $1"; [[ -n "$2" ]] && echo " $2"; fail=$(( fail + 1 )); }
info() { echo " - $1"; }
check() {
local label="$1" result="$2" expected="$3"
[[ "$result" == *"$expected"* ]] && ok "$label" || ng "$label" "expected: $expected | got: ${result:0:150}"
}
echo ""
echo "URL: $REMOTE"
echo ""
# ── 1. Proxy reachable ────────────────────────────────────────────────────────
echo "=== 1. Proxy reachable ==="
status=$(curl -o /dev/null -s -w "%{http_code}" --max-time 3 "$PROXY/proxy?url=http://test" || echo "000")
[[ "$status" != "000" ]] && ok "Proxy is up (HTTP $status)" || ng "Proxy not reachable — is startServer() called?"
# ── 2. Master manifest ────────────────────────────────────────────────────────
echo ""
echo "=== 2. Master manifest ==="
PROXY_URL="$PROXY/proxy?url=$(enc "$REMOTE")"
master=$(curl -s --max-time 10 "$PROXY_URL")
check "Contains #EXTM3U" "$master" "#EXTM3U"
check "Variant URLs rewritten" "$master" "127.0.0.1:9000/proxy?url="
if echo "$master" | grep -q 'EXT-X-MEDIA.*URI='; then
check "EXT-X-MEDIA URI rewritten" "$master" 'URI="http://127.0.0.1:9000'
else
info "EXT-X-MEDIA: not present in this stream"
fi
if echo "$master" | grep -q 'EXT-X-I-FRAME-STREAM-INF'; then
iframe_line=$(echo "$master" | grep "EXT-X-I-FRAME-STREAM-INF" | head -1)
echo "$iframe_line" | grep -q "127.0.0.1:9000" \
&& ok "EXT-X-I-FRAME-STREAM-INF URI rewritten" \
|| ng "EXT-X-I-FRAME-STREAM-INF URI NOT rewritten" "$iframe_line"
fi
# ── 3. Variant manifest ───────────────────────────────────────────────────────
echo ""
echo "=== 3. Variant manifest ==="
# Extract first proxied variant URL that looks like a rendition playlist
variant_proxy=$(echo "$master" | grep -v '^#' | grep "127.0.0.1:9000" | head -1)
variant_enc=$(echo "$variant_proxy" | grep -oE 'url=[^&" ]+' | head -1 | sed 's/url=//')
variant_url=$(dec "$variant_enc")
if [[ -z "$variant_url" ]]; then
ng "Could not extract variant URL from master"
else
variant=$(curl -s --max-time 10 "$PROXY/proxy?url=$(enc "$variant_url")")
check "Variant has #EXTM3U" "$variant" "#EXTM3U"
check "Segment URLs proxied" "$variant" "127.0.0.1:9000/proxy?url="
if echo "$variant" | grep -q "EXT-X-MAP"; then
check "EXT-X-MAP URI proxied" "$variant" 'URI="http://127.0.0.1:9000'
else
info "EXT-X-MAP: not present"
fi
if echo "$variant" | grep -q "EXT-X-PRELOAD-HINT"; then
hint=$(echo "$variant" | grep "EXT-X-PRELOAD-HINT" | grep -oE 'URI="[^"]+"' | head -1)
check "EXT-X-PRELOAD-HINT URI proxied" "$hint" "127.0.0.1:9000"
hint_byterange=$(echo "$variant" | grep "EXT-X-PRELOAD-HINT" | grep -oE 'BYTERANGE[^,\n]+' | head -1)
[[ -n "$hint_byterange" ]] && ok "EXT-X-PRELOAD-HINT BYTERANGE preserved ($hint_byterange)" || info "EXT-X-PRELOAD-HINT: no BYTERANGE attribute"
else
info "EXT-X-PRELOAD-HINT: not present (VOD stream)"
fi
if echo "$variant" | grep -q "EXT-X-PART:"; then
part=$(echo "$variant" | grep "^#EXT-X-PART:" | head -1)
echo "$part" | grep -q "127.0.0.1:9000" && ok "EXT-X-PART URI proxied" || ng "EXT-X-PART URI NOT proxied" "$part"
part_br=$(echo "$part" | grep -oE 'BYTERANGE=[^,\n]+' | head -1)
[[ -n "$part_br" ]] && ok "EXT-X-PART BYTERANGE preserved ($part_br)" || info "EXT-X-PART: no BYTERANGE attribute"
else
info "EXT-X-PART: not present (not LL-HLS)"
fi
fi
# ── 4. Segment cache: MISS → HIT ──────────────────────────────────────────────
echo ""
echo "=== 4. Segment caching ==="
if [[ -n "$variant_url" ]]; then
base_url=$(echo "$variant_url" | sed 's|/[^/]*$|/|')
seg_url="${base_url}1.m4s"
proxy_seg="$PROXY/proxy?url=$(enc "$seg_url")"
t1=$(ms); code1=$(curl -o /dev/null -s -w "%{http_code}" --max-time 15 "$proxy_seg"); t2=$(ms)
ms1=$(( t2 - t1 ))
t3=$(ms); code2=$(curl -o /dev/null -s -w "%{http_code}" --max-time 15 "$proxy_seg"); t4=$(ms)
ms2=$(( t4 - t3 ))
echo " 1st fetch: HTTP $code1 ${ms1}ms (MISS — network)"
echo " 2nd fetch: HTTP $code2 ${ms2}ms (HIT — disk)"
[[ $ms2 -lt $ms1 ]] && ok "Cache hit faster (${ms1}ms → ${ms2}ms)" || ok "Cache warm (${ms1}ms → ${ms2}ms)"
fi
echo ""
echo "========================================"
printf " Result: %d passed, %d failed\n" "$pass" "$fail"
echo "========================================"
echo ""