fix: return correct WebChat image MIME types#9319
Conversation
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request updates the ChatService to map supported image extensions to their specific MIME types using a dictionary, replacing the previous list-based approach. This ensures that resolve_webchat_file returns the correct MIME type (such as image/png or image/gif) instead of defaulting to image/jpeg for all supported image formats. A new parameterized unit test has also been added to verify this behavior. I have no feedback to provide on these changes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- To avoid extension/MIME mismatches in future edits, consider centralizing the
supported_img_mime_typesmapping (e.g., as a module-level constant) and reusing it in the test parametrization instead of duplicating the list of extensions and MIME types.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- To avoid extension/MIME mismatches in future edits, consider centralizing the `supported_img_mime_types` mapping (e.g., as a module-level constant) and reusing it in the test parametrization instead of duplicating the list of extensions and MIME types.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
|
Addressed the Sourcery feedback in
Validation after the update: Remote GitHub checks are passing as well, including format-check, CodeQL, unit tests, dashboard build, Sourcery review, and the full smoke-test matrix. |
Fixes WebChat file responses so PNG, GIF, and WebP files are served with their real image MIME types instead of always using
image/jpeg.Modifications / 改动点
What Problem This Solves
ChatService.resolve_webchat_file()treated every supported WebChat image extension as JPEG:That meant files such as
photo.png,photo.gif, andphoto.webpcould be resolved successfully but then passed toFileResponse(media_type="image/jpeg"). The file bytes and filename stayed unchanged, but the HTTPContent-Typeno longer matched the actual image format.Changes
WEBCHAT_IMAGE_MIME_TYPES, then reused that same mapping for runtime lookup and test parametrization..wavhandling, basename normalization, attachments directory lookup, WebChat fallback image directory lookup, and path boundary checks unchanged.ChatServiceand verifies each supported image extension resolves to the expected MIME type.Possible call chain / impact
This only changes the MIME header selected for WebChat image file responses. It does not change upload behavior, authentication, filename sanitization, path traversal protection, attachment database records, audio handling, or unknown-file fallback behavior.
Screenshots or Test Results / 运行截图或测试结果
Evidence
Before this change, a minimal local reproduction showed a
.pngfile being resolved as JPEG:After this change, the regression test covers all supported WebChat image extensions:
[ ("photo.jpg", "image/jpeg"), ("photo.jpeg", "image/jpeg"), ("photo.png", "image/png"), ("photo.gif", "image/gif"), ("photo.webp", "image/webp"), ]Validation
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👖 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤸 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确认没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😷 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Correct WebChat file resolution to return accurate MIME types for supported image formats and cover the behavior with tests.
Bug Fixes:
Tests: