fix: HEAD no longer downloads the full body from GCS#60
Merged
Conversation
Resolves #59 (reported by @MN755). Previously, HEAD requests fell through the same code path as GET: streamObject / streamRange would open a *storage.Reader and call io.Copy(w, objr). net/http does discard the body for HEAD, but the Read side of io.Copy still pulled every byte from GCS, so a HEAD on a 1 GB object racked up the same GCS read latency, egress, and billing as a GET. Both streamObject and streamRange now short-circuit before opening a GCS reader when r.Method == http.MethodHead. Headers are derived from the object attrs we already have (Content-Encoding / -Length are reconstructed from attrs + Accept-Encoding so they match what a matching GET would produce). The full Range parsing pipeline still runs first, so HEAD with Range correctly returns 206 / 416 / falls through to 200 in the same conditions as GET. Adds focused HEAD tests next to the existing GET/Range coverage so this can't regress: plain HEAD, HEAD with -content-length, 404, HEAD + Range (206 + Content-Range only), unsatisfiable range, non-bytes unit ignored, and gzip-stored with/without Accept-Encoding: gzip. Also tightens a couple of comments in streamRange that had grown longer than they needed to be. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
d724dba to
578b371
Compare
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.
Summary
Resolves #59 (reported by @MN755).
Previously, HEAD requests fell through the same code path as GET: `streamObject` / `streamRange` would open a `*storage.Reader` and call `io.Copy(w, objr)`. `net/http` does discard the body for HEAD, but the Read side of `io.Copy` still pulled every byte from GCS — so a `HEAD` on a 1 GB object racked up the same GCS read latency, egress, and billing as a `GET`.
Fix
Both `streamObject` and `streamRange` now short-circuit before opening a GCS reader when `r.Method == http.MethodHead`. Headers are derived from the object attrs we already have:
Test plan
New focused HEAD tests sit alongside the existing GET / Range coverage:
Also tightens a couple of comments in `streamRange` that had grown longer than they needed to be.
🤖 Generated with Claude Code