Repository navigation
perf(proxy): avoid deep header copies in transparent forwarding - #199
Merged
Merged
Conversation
Greptile SummaryThe PR optimizes transparent forwarding by replacing deep header cloning with a private header map that borrows capacity-capped, read-only value slices.
Confidence Score: 5/5The PR appears safe to merge, with no concrete correctness, security, or compatibility failures identified. The forwarded request receives an independent header map, changed headers receive private value slices, unchanged values remain read-only, and the relevant forwarding and benchmark paths do not mutate shared slices or retain contaminating state. Important Files Changed
Reviews (1): Last reviewed commit: "perf: borrow unchanged header values for..." | Re-trigger Greptile |
|
🎉 This PR is included in version 1.21.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Transparent forwarding currently deep-clones every inbound header map and value slice before adding proxy headers. That repeats the full header copy on each uncached S3 operation.
The forwarded request now gets a private shallow header map. Unchanged value slices are reused read-only with their capacity capped, while proxy, date, and content-encoding entries are set on the private map. This keeps client headers intact and prevents generated proxy headers from appearing on the inbound request. Tests cover header ownership, open response bodies, transport errors, forwarding variants, and append isolation.
make lint-ci,make build,make test,make test-integration,make test-race, andmake test-coveragepass.Workload:
authenticated transparent passthrough for a small uncached S3 GET with typical AWS SDK headersns/opB/opallocs/opGenerated by Perfloop. Measurements and checks.
Note
Medium Risk
Request forwarding and header aliasing are subtle; incorrect sharing could leak proxy credentials onto the inbound request or corrupt client headers, though coverage is extensive.
Overview
Transparent forwarding no longer deep-clones every inbound header on each upstream request.
buildTransparentRequestnow usesshallowHeaderCopy: a private header map for the outbound request while reusing unchanged value slices from the client (with slice capacity capped so appends on the forwarded request cannot mutate the inbound map).Proxy headers, synthesized
X-Amz-Date, andContent-Encodingtweaks still apply only on the forwarded request, so client-visible headers stay unchanged. New unit tests cover borrowing, append isolation, and header privacy acrossForward,ForwardWithCapture,DoRequestWithCreds, open response bodies, and transport errors; a benchmark tracks authenticated passthrough setup cost (~15% fewer allocs/time in the PR description).Reviewed by Cursor Bugbot for commit 50991f7. Bugbot is set up for automated code reviews on this repo. Configure here.