-
-
Notifications
You must be signed in to change notification settings - Fork 601
Fix Content-Type for HTTP exceptions #4037
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
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts Quart exception responses to explicitly use "text/plain" for the Content-Type header instead of the default "text/html" by updating the dispatch_request implementation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
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.
Greptile Overview
Greptile Summary
Fixed incorrect Content-Type header in Quart's HTTPException responses by explicitly setting content_type="text/plain".
- Issue: Quart's
Responseclass defaults totext/htmlContent-Type, causing plain text error messages to be served with the wrong MIME type - Fix: Added
content_type="text/plain"parameter when creating Response objects for HTTPException handlers - Impact: Error messages now display correctly in browsers and API clients instead of being interpreted as HTML
- Consistency: FastAPI already uses
PlainTextResponsefor similar exceptions; this brings Quart in line with that pattern
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The change is a simple one-line fix that explicitly sets the correct Content-Type header for error responses. The fix aligns with how other frameworks (FastAPI) handle the same scenario, addresses a real bug where error messages were served with the wrong MIME type, and has no side effects on existing functionality.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| strawberry/quart/views.py | 5/5 | Added content_type="text/plain" to HTTPException Response to fix incorrect Content-Type header (was defaulting to text/html) |
Sequence Diagram
sequenceDiagram
participant Client
participant GraphQLView
participant AsyncBaseHTTPView
participant QuartResponse
Client->>GraphQLView: HTTP Request (GET/POST/WebSocket)
GraphQLView->>GraphQLView: dispatch_request()
alt Valid Request
GraphQLView->>AsyncBaseHTTPView: run(request)
AsyncBaseHTTPView->>AsyncBaseHTTPView: execute_operation()
AsyncBaseHTTPView-->>GraphQLView: GraphQLHTTPResponse
GraphQLView->>QuartResponse: Response(data, content_type="application/json")
QuartResponse-->>Client: JSON Response
else HTTPException (Invalid Request)
AsyncBaseHTTPView->>AsyncBaseHTTPView: parse/validate request
AsyncBaseHTTPView-->>GraphQLView: raise HTTPException(status, reason)
GraphQLView->>QuartResponse: Response(reason, status, content_type="text/plain")
Note over QuartResponse: Fix: Added content_type="text/plain"<br/>Previously defaulted to "text/html"
QuartResponse-->>Client: Plain Text Error Response
end
1 file reviewed, no comments
|
Looks good to me! @mgorven would you mind adding a test and a RELEASE.md file? 😊 |
HTTP exceptions are returned as a plain text message, but various HTTP framework views default to `text/html` as the Content-Type or don't set it at all. Set the Content-Type to `text/plain` so that these are displayed correctly.
Done. I also fixed the other HTTP framework views. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4037 +/- ##
=======================================
Coverage 94.42% 94.42%
=======================================
Files 536 536
Lines 35002 35008 +6
Branches 1836 1836
=======================================
+ Hits 33051 33057 +6
Misses 1656 1656
Partials 295 295 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging #4037 will not alter performanceComparing Summary
|
Ckk3
left a 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.
Looks good to me too!
Thanks for you contribuition @mgorven ❤️
About the pre-commit error we are getting in the CI, it is something that I fixed in this commit.
No need to add this in your code, I'm just talking about it so we can move foward knowing that this error has nothing related to your PR
|
What's left to get this merged? |
bellini666
left a 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.
Sorry for taking some time @mgorven . Looks good :)
I merged main here to fix pre-commit issues. Just waiting for tests to pass and I'll merge it :)
|
Thanks for contributing to Strawberry! 🎉 You've been invited to join You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67 And don't forget to join our discord server: https://strawberry.rocks/discord 🔥 |

Description
HTTP exceptions are returned as a plain text message, but various HTTP framework views default to
text/htmlas the Content-Type or don't set it at all. Set the Content-Type totext/plainso that these are displayed correctly.Types of Changes
Issues Fixed or Closed by This PR
Checklist
Summary by Sourcery
Set the Content-Type header to text/plain for Quart exception responses
Bug Fixes: