Expose fetch observation metadata - #58
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “observed fetch” API to the fetch package so callers can retain successful response metadata (requested/final URL, status, timing, allow-listed headers, declared size/media type) and verify the downloaded content via streaming SHA-256/SHA-512 digests that are only finalized at EOF (so partial reads remain distinguishable). This extends the same API through the circuit-breaker wrapper and documents usage.
Changes:
- Introduces
FetchObservation,ObservedArtifact, and anobservedBodywrapper that counts bytes and computes SHA-256/SHA-512 only on EOF. - Adds
FetchObserved/FetchObservedWithHeaderstoFetcherand wires observation through the shared fetch path. - Extends
CircuitBreakerFetcherand adds documentation/tests for the new observed fetch behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents how to call FetchObserved and what metadata/headers are retained. |
| fetch/observation.go | Adds observation types, allow-listed header copier, and streaming digest/body wrapper. |
| fetch/observation_test.go | Adds tests for redirects, allow-listed headers, EOF-complete semantics, and incomplete reads. |
| fetch/fetcher.go | Implements observed fetch methods and plumbs observation through request execution. |
| fetch/circuit_breaker.go | Adds circuit-breaker wrappers for observed fetch methods. |
| fetch/circuit_breaker_test.go | Adds a success test for FetchObserved via the circuit breaker. |
Suppressed comments (1)
fetch/observation_test.go:54
ResponseTimecan be legitimately0for very fast localhttptestresponses (timer resolution / scheduling), which can make this assertion flaky. Consider allowing zero and only rejecting negative durations.
if observation.ResponseTime <= 0 {
t.Errorf("ResponseTime = %v, want a positive duration", observation.ResponseTime)
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+3
to
+27
| import ( | ||
| "context" | ||
| "crypto/sha256" | ||
| "crypto/sha512" | ||
| "encoding/hex" | ||
| "io" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestFetchObserved(t *testing.T) { | ||
| content := []byte("observed artifact content") | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| switch r.URL.Path { | ||
| case "/artifact": | ||
| http.Redirect(w, r, "/download", http.StatusFound) | ||
| case "/download": | ||
| w.Header().Set("Cache-Control", "public, max-age=3600") | ||
| w.Header().Set("Content-Disposition", `attachment; filename="artifact.tgz"`) | ||
| w.Header().Set("Content-Type", "application/gzip") | ||
| w.Header().Set("ETag", `"abc123"`) | ||
| w.Header().Set("Set-Cookie", "session=secret") | ||
| w.Header().Set("X-Response-Secret", r.Header.Get("Authorization")) | ||
| _, _ = w.Write(content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds opt-in
FetchObservedandFetchObservedWithHeadersmethods that retain requested and final URLs, response timing and status, declared size and media type, and an allow-list of response headers.The observed body calculates SHA-256 and SHA-512 while streaming. Byte counts and digests are only set after EOF, which leaves incomplete reads unverified. The circuit breaker wrapper supports the same API.
Closes #57