Skip to content

fix: Prevent _prepare_request_call from mutating caller's headers dict#746

Merged
vdusek merged 1 commit intomasterfrom
fix/prepare-request-call-mutates-headers
Apr 21, 2026
Merged

fix: Prevent _prepare_request_call from mutating caller's headers dict#746
vdusek merged 1 commit intomasterfrom
fix/prepare-request-call-mutates-headers

Conversation

@vdusek
Copy link
Copy Markdown
Contributor

@vdusek vdusek commented Apr 21, 2026

Summary

_prepare_request_call in HttpClientBase was mutating the caller's headers dict in place — the if not headers: headers = {} guard only allocated a new dict when the caller passed None/empty, so a non-empty caller-owned dict was mutated directly. Users of the documented custom HttpClient / HttpClientAsync extension points that reuse a shared headers dict across call() invocations would see stale Content-Type / Content-Encoding headers leak into subsequent requests (e.g. a bodyless GET carrying Content-Encoding: gzip from a prior POST).

Fix: copy up-front with headers = dict(headers) if headers else {}. Added a regression test covering the aliased-dict case.

Copy the caller-provided `headers` up-front so `Content-Type`/`Content-Encoding`
additions do not leak back into a shared dict reused across HTTP calls.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Apr 21, 2026
@vdusek vdusek self-assigned this Apr 21, 2026
@github-actions github-actions bot added this to the 139th sprint - Tooling team milestone Apr 21, 2026
@github-actions github-actions bot added the tested Temporary label used only programatically for some analytics. label Apr 21, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.29%. Comparing base (6c3b84d) to head (3e9bbae).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #746      +/-   ##
==========================================
- Coverage   95.36%   95.29%   -0.08%     
==========================================
  Files          45       45              
  Lines        5118     5117       -1     
==========================================
- Hits         4881     4876       -5     
- Misses        237      241       +4     
Flag Coverage Δ
integration 95.29% <100.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek requested a review from Pijukatel April 21, 2026 08:23
@vdusek vdusek merged commit d553162 into master Apr 21, 2026
26 checks passed
@vdusek vdusek deleted the fix/prepare-request-call-mutates-headers branch April 21, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants