Skip to content

fix(net): cap response body reads via configurable size limit#41

Merged
pgagnidze merged 2 commits intomainfrom
fix/response-body-limit
Apr 21, 2026
Merged

fix(net): cap response body reads via configurable size limit#41
pgagnidze merged 2 commits intomainfrom
fix/response-body-limit

Conversation

@pgagnidze
Copy link
Copy Markdown
Member

Summary

  • Caps HTTP probe response bodies via http.MaxBytesReader with a new NetworkConfig.BodySizeLimit field (0 = unlimited; net.DefaultBodySizeLimit = 1 MiB applied by all current callers).
  • Surfaces ResponseTruncated on HTTPResponse and WebsiteCheckResult, and logs a warning when the cap is hit, so assertion failures against truncated bodies are traceable.
  • Pattern and field naming mirror prometheus/blackbox_exporter, including the math.MaxInt64 clamp that works around a known overflow bug in http.MaxBytesReader.

Replaces #38.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./... (all packages pass)
  • New TestCheckWebsiteBodyLimit covers: body under limit, body equals limit, body exceeds limit (truncation + warning), 0 = unlimited, and DefaultBodySizeLimit caps at 1 MiB
  • Manual: run updo monitor against a target that returns a >1 MiB response and confirm the warning fires without breaking the probe

@pgagnidze pgagnidze merged commit 522fe48 into main Apr 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant