Skip to content

Commit d0235d9

Browse files
Capture headers and body for non-200s in tally section
1 parent 901d1cc commit d0235d9

1 file changed

Lines changed: 40 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,46 @@ jobs:
9090
done | xargs -n2 -P16 bash -c 'probe "$0" "$1"'
9191
9292
echo "=== Tally ==="
93-
# Re-run quickly and count status codes only.
94-
codes=$(for i in $(seq 1 100); do
93+
# Re-run quickly, count status codes, and capture headers/body for the first 5 non-200s.
94+
tally_dir=$(mktemp -d)
95+
tally_one() {
96+
local p=$1 dir=$2 hdrs body line code
97+
hdrs=$(mktemp); body=$(mktemp)
98+
line=$(curl -sS -o "$body" -D "$hdrs" -A "Java/25" \
99+
-w '%{http_code} cf_ray=%header{cf-ray} cf_cache=%header{cf-cache-status} age=%header{age}' \
100+
--max-time 30 "${BASE_URL}/${p}" 2>&1) || true
101+
code=${line%% *}
102+
echo "$code" >> "$dir/codes"
103+
if [[ "$code" != "200" ]]; then
104+
# Write each non-200 to its own file to avoid interleaving between parallel writers.
105+
{
106+
printf -- '--- non-200 sample: %s -> %s ---\n' "$p" "$line"
107+
printf ' request headers were sent with -A "Java/25"\n'
108+
printf ' response headers:\n'
109+
sed 's/^/ /' "$hdrs"
110+
printf ' response body (first 500 bytes):\n'
111+
head -c 500 "$body" | sed 's/^/ /'
112+
printf '\n--- end ---\n'
113+
} > "$(mktemp "$dir/non200.XXXXXX")"
114+
fi
115+
rm -f "$hdrs" "$body"
116+
}
117+
export -f tally_one
118+
export BASE_URL
119+
for i in $(seq 1 100); do
95120
for p in "${paths[@]}"; do
96-
curl -sS -o /dev/null -A "Java/25" -w '%{http_code}\n' --max-time 30 "${BASE_URL}/${p}" &
121+
tally_one "$p" "$tally_dir" &
97122
done
98123
wait
99-
done | sort | uniq -c | sort -rn)
100-
echo "$codes"
124+
done
125+
echo "Counts:"
126+
sort "$tally_dir/codes" | uniq -c | sort -rn
127+
shopt -s nullglob
128+
samples=("$tally_dir"/non200.*)
129+
if (( ${#samples[@]} > 0 )); then
130+
echo "Non-200 samples (showing first 5 of ${#samples[@]}):"
131+
for f in "${samples[@]:0:5}"; do cat "$f"; done
132+
else
133+
echo "No non-200 responses captured."
134+
fi
135+
rm -rf "$tally_dir"

0 commit comments

Comments
 (0)