Skip to content

fix(context): clear cached query parameters when replacing requests - #3252

Open
Twiink wants to merge 1 commit into
labstack:masterfrom
Twiink:fix/set-request-query-cache-20261126
Open

Twiink wants to merge 1 commit into
labstack:masterfrom
Twiink:fix/set-request-query-cache-20261126

Conversation

@Twiink

@Twiink Twiink commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

When middleware calls QueryParams() and later rewrites or replaces the request through SetRequest, the parsed query cache still belongs to the old request. QueryString() reports the new URL, while QueryParam(), QueryParams() and query binding continue using the old values.

Invalidate the cached query parameters in SetRequest. Add full ServeHTTP regressions for both a request clone and an in-place URL rewrite, covering changed, removed and repeated parameters plus the bound response. Both cases fail before the fix.

Validation passed: full race suites on Go 1.27.4, 1.27.3 and 1.25.0, go vet ./..., golint -set_exit_status ./..., staticcheck ./..., and govulncheck ./... with patched Go 1.27.4. The test processes use direct local connections because the environment HTTP proxy returned 502 for wildcard-address test servers.

Summary by CodeRabbit

  • Bug Fixes
    • Query parameter lookups now reflect the updated URL when a request is replaced, including repeated values and defaults.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Request query refresh

Layer / File(s) Summary
Invalidate cached query parameters and verify access
context.go, context_test.go
Context.SetRequest resets the cached query map. Tests cover changes to the existing request and replacement with a clone, including updated query access and binding.

Suggested reviewers: vishr

Change: Bug fix

Merge Risk: Minimal · up to 447bc

Replacing a request in middleware now refreshes query parameters, so handlers and query binding see the updated URL. The change is small and tested, and no merge-blocking risk was found.

Security architecture risk: Minimal · up to 447bc

After middleware replaces a request, subsequent query reads and binding use the replacement URL instead of stale values. The change adds no new endpoint or privilege and does not expand the scope beyond the current request.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed behavior is limited to downstream query consumers on the same context after application code calls SetRequest. The separate reset path already discards the cache between requests.

Trust Boundaries and Controls

  • inferred — HTTP query data still reaches the same accessors and binder. The change aligns their reads with the URL selected by existing application middleware; it does not change who can replace the request or how RealIP derives client identity.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 83fbede7-2ad3-4a90-b6c5-45fce646a0a7
Commits

Reviewing files that changed from the base of the PR and between 59aacdd and 447bc3a.

Files selected for processing: 2

  • context.go
  • context_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.23%. Comparing base (dcb05f0) to head (447bc3a).
⚠️ Report is 64 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3252      +/-   ##
==========================================
+ Coverage   93.34%   96.23%   +2.88%     
==========================================
  Files          43       46       +3     
  Lines        4735     4431     -304     
==========================================
- Hits         4420     4264     -156     
+ Misses        192      167      -25     
+ Partials      123        0     -123     

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant