-
Notifications
You must be signed in to change notification settings - Fork 3
POST requests should have no-cache headers #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds a cacheControlTripper that injects no-cache headers on POST requests and delegates to the next RoundTripper. Updates the transport construction to include this tripper before userAgentTripper and existing interceptors. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant CacheControlTripper as cacheControlTripper
participant UserAgentTripper as userAgentTripper
participant Next as next RoundTripper
participant Server
Client->>CacheControlTripper: RoundTrip(req)
alt req.Method == POST
Note right of CacheControlTripper: Inject headers<br/>Cache-Control: no-store, no-cache, must-revalidate<br/>Pragma: no-cache<br/>Expires: 0
else Other methods
Note right of CacheControlTripper: Pass-through
end
CacheControlTripper->>UserAgentTripper: RoundTrip(req)
UserAgentTripper->>Next: RoundTrip(req)
Next->>Server: HTTP request
Server-->>Next: HTTP response
Next-->>UserAgentTripper: response
UserAgentTripper-->>CacheControlTripper: response
CacheControlTripper-->>Client: response
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/uhttp/transport.go(2 hunks)
🔇 Additional comments (3)
pkg/uhttp/transport.go (3)
178-180: LGTM!The struct definition follows the established pattern of other trippers in this file.
231-231: LGTM!The tripper is appropriately placed in the chain. Cache control headers will be set after debug logging but before other header modifications, which is a sensible ordering.
183-187: Verify POST-only scope and header overwriting are intentional.
- Only POST requests get cache-control headers; consider if PUT/PATCH/DELETE should also be covered.
Set()unconditionally overwrites headers; ensure this won’t conflict with any upstream cache policies.
| if req.Method == http.MethodPost { | ||
| req.Header.Set("Cache-Control", "no-store, no-cache, must-revalidate") | ||
| req.Header.Set("Pragma", "no-cache") | ||
| req.Header.Set("Expires", "0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use RFC-compliant date format for Expires header.
The value "0" is not RFC 7234 compliant. While many caches may accept it, a proper HTTP-date format should be used.
Apply this diff to use a standards-compliant value:
- req.Header.Set("Expires", "0")
+ req.Header.Set("Expires", "Thu, 01 Jan 1970 00:00:00 GMT")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| req.Header.Set("Expires", "0") | |
| req.Header.Set("Expires", "Thu, 01 Jan 1970 00:00:00 GMT") |
🤖 Prompt for AI Agents
In pkg/uhttp/transport.go around line 186, the Expires header is set to the
non‑RFC value "0"; replace that with an RFC‑compliant HTTP-date string (e.g.,
the Unix epoch or a past date) formatted using Go's http.TimeFormat (RFC1123
with GMT) so caches interpret it correctly, and add the time import if it isn't
already present.
Summary by CodeRabbit