-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Check Accept-Encoding quality #3493
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
Conversation
- Add a custom header that returns the Redoc/swagger-ui version. - Make parameter non-optional.
Do not respond with gzip if the quality is zero.
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.
Pull Request Overview
This PR enhances how Accept-Encoding quality values are handled—specifically preventing gzip when its quality is zero—and exposes the Swagger UI and ReDoc versions via custom response headers.
- Skip gzip encoding when its quality is explicitly set to zero.
- Add
x-swagger-ui-versionandx-redoc-versionheaders to responses. - Convert a ReDoc middleware test to a parameterized theory covering various
Accept-Encodingscenarios.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| test/Swashbuckle.AspNetCore.IntegrationTests/ReDocIntegrationTests.cs | Converted the test to a [Theory] with multiple Accept-Encoding inputs and built a custom request message. |
| src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs | Renamed cache-header method, added Swagger UI version header, and updated ETag handling. |
| src/Swashbuckle.AspNetCore.ReDoc/ReDocMiddleware.cs | Renamed cache-header method, added ReDoc version header, and updated ETag handling. |
| src/Shared/EmbeddedResourceProvider.cs | Updated IsGZipAccepted to check the Quality property before accepting gzip. |
Comments suppressed due to low confidence (2)
test/Swashbuckle.AspNetCore.IntegrationTests/ReDocIntegrationTests.cs:206
- The test only asserts the status code but does not verify that the response content was correctly decompressed or matches the expected asset. Consider adding assertions to validate the response body against the original uncompressed asset.
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
test/Swashbuckle.AspNetCore.IntegrationTests/ReDocIntegrationTests.cs:197
- The empty array literal '[]' is not valid C# syntax for an empty enumerable. Consider replacing 'encodings ?? []' with 'encodings ?? Array.Empty()' to ensure compilation and clarity.
foreach (var encoding in encodings ?? [])
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #3493 +/- ##
==========================================
+ Coverage 93.88% 94.28% +0.39%
==========================================
Files 110 110
Lines 3812 3816 +4
Branches 724 722 -2
==========================================
+ Hits 3579 3598 +19
+ Misses 233 218 -15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Accept-Encodingvalue is zero. See FixAccept-Encodingparsing #3492 (comment).