-
Notifications
You must be signed in to change notification settings - Fork 322
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
No content-type on no body response code #1011
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes introduce a new function, Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant GzipResponseWriter
Client->>Server: Request
Server->>GzipResponseWriter: Write response
GzipResponseWriter->>GzipResponseWriter: Check status code
alt Body allowed
GzipResponseWriter->>GzipResponseWriter: Set Content-Type
else No body allowed
GzipResponseWriter->>GzipResponseWriter: Do not set Content-Type
end
GzipResponseWriter->>Server: Close response
Server->>Client: Send response
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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
📒 Files selected for processing (2)
- gzhttp/compress.go (2 hunks)
- gzhttp/compress_test.go (2 hunks)
🔇 Additional comments (3)
gzhttp/compress.go (2)
327-339
: LGTM: Well-implemented function following RFC 7230The
bodyAllowedForStatus
function is a great addition. It correctly implements the rules specified in RFC 7230, section 3.3, for determining whether a response body is allowed for a given HTTP status code. The function is concise, easy to understand, and follows best practices.
352-352
: Excellent improvement in Content-Type handlingThis change significantly improves the handling of responses without bodies. By using the
bodyAllowedForStatus
function, the code now correctly determines whether to set the Content-Type header based on the response status code. This ensures compliance with HTTP specifications and resolves the issue of setting Content-Type headers for responses that should not have a body (e.g., 204 No Content, 304 Not Modified).The modification aligns perfectly with the PR objectives and enhances the overall correctness of the response handling mechanism.
gzhttp/compress_test.go (1)
1601-1618
: LGTM! Important test case added.This new test function
TestNoContentTypeWhenNoContent
is a valuable addition. It ensures that the gzip middleware correctly handles responses with HTTP 204 No Content status, specifically checking that no Content-Type header is set. This adheres to HTTP specifications and covers an important edge case.
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.
Let's keep the internal part as-is, but skip setting the header on these types.
44ebb0d
to
71a1e13
Compare
Thanks for the contribution! |
This PR addresses an issue where the Content-Type was being automatically detected and set, even for responses that are not allowed to have a body (e.g., status codes 204 No Content, 304 Not Modified, etc.).
Summary by CodeRabbit
New Features
Bug Fixes
Content-Type
header is absent for204 No Content
status responses.Tests
Content-Type
header is sent for204 No Content
responses, ensuring compliance with HTTP specifications.