feat(check): record what HTTP checks saw

With Spec.Capture, HTTP, JSON and Prometheus checks record every request
and response of the redirect chain, the time spent per phase, the remote
address, the server certificate and the first 32 KiB of the body.
Configured headers, credentials and cookie values are redacted. The
certificate is recorded before verification, which is now done in
VerifyConnection the way crypto/tls does it, because crypto/tls drops the
certificate exactly when verification fails.

Refs #79

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 12:09:42 +01:00
1 parent 94b519b421
commit 48312fc59c
4 files changed
+500 -4

No files matched your search

+13
View File
@@ -46,6 +46,8 @@ type Spec struct {
// AllowPrivate permits targets on private networks. It is false for
// shared checkers in the cloud edition.
AllowPrivate bool
// Capture records Evidence of HTTP exchanges.
Capture bool
}
// Outcome is the result of one check run.
@@ -56,6 +58,9 @@ type Outcome struct {
StatusCode int
// Error explains a failure in a form suitable for showing to customers.
Error string
// Evidence is set when Spec.Capture was and the check made HTTP
// requests.
Evidence *Evidence
}
// ErrInvalid is wrapped by Validate errors. Its message is the code shown to
@@ -115,6 +120,11 @@ func Run(ctx context.Context, s Spec) Outcome {
}
ctx, cancel := context.WithTimeout(ctx, s.Timeout)
defer cancel()
var rec *recorder
if s.Capture {
rec = newRecorder()
ctx = context.WithValue(ctx, recorderKey{}, rec)
}
start := time.Now()
o := im.run(ctx, s)
if o.Latency == 0 {
@@ -126,6 +136,9 @@ func Run(ctx context.Context, s Spec) Outcome {
if errors.Is(ctx.Err(), context.DeadlineExceeded) && !o.OK {
o.Error = "timeout after " + s.Timeout.String()
}
if rec != nil {
o.Evidence = rec.evidence(o)
}
return o
}