-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[py]: guess mimetypes in webserver for content serving #16449
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
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
PR Code Suggestions ✨Explore these optional code suggestions:
|
good find! thanks for fixing the tests also. |
User description
🔗 Related Issues
In here - #16419 (comment), the txt and image files were getting downloaded as html. The webserver wasn't handling the mimetypes, this PR fixes it.
💥 What does this PR do?
🔧 Implementation Notes
I have used
filetype
for mimetype guessing but it isn't very good for text file mime guessing since it works on magic bytes of files. We are already usingfiletype
and it was added in this PR - #14771 as per discussion in #14765 (comment).We can also use the
mimetypes
library.💡 Additional Considerations
🔄 Types of changes
PR Type
Bug fix
Description
Add proper MIME type detection using
mimetypes
library for file servingHandle binary files (images, audio, video) separately from text files
Remove workarounds in download tests that accepted incorrect file extensions
Simplify test assertions to expect correct file types
Diagram Walkthrough
File Walkthrough
webserver.py
Implement proper MIME type detection for file serving
py/test/selenium/webdriver/common/webserver.py
mimetypes
module for MIME type detection_serve_file()
to handle binary and text files separatelybased on MIME type
do_GET()
to usemimetypes.guess_type()
instead of hardcoded.json
checkmode; text files use latin-1 encoding
remote_downloads_tests.py
Remove download test workarounds for correct file types
py/test/selenium/webdriver/remote/remote_downloads_tests.py
test_get_downloadable_files()
to assert exact file namesinstead of accepting multiple extensions
test_download_file()
to search for.txt
files directlywithout fallback extensions
_browser_downloads()
wait condition to expect correctfile_2.jpg
instead of multiple extensions