Skip to content

Commit de49ff0

Browse files
committed
fix file serving
1 parent b2e14e9 commit de49ff0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

py/test/selenium/webdriver/common/webserver.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,20 @@ def _serve_page(self, page_number):
7171

7272
def _serve_file(self, file_path):
7373
"""Serve a file from the HTML root directory."""
74-
with open(file_path, encoding="latin-1") as f:
75-
return f.read().encode("utf-8")
74+
content_type, _ = mimetypes.guess_type(file_path)
75+
76+
if content_type and (
77+
content_type.startswith("image/")
78+
or content_type.startswith("application/")
79+
or content_type.startswith("video/")
80+
or content_type.startswith("audio/")
81+
):
82+
with open(file_path, "rb") as f:
83+
return f.read()
84+
else:
85+
# text files
86+
with open(file_path, encoding="latin-1") as f:
87+
return f.read().encode("utf-8")
7688

7789
def _send_response(self, content_type="text/html"):
7890
"""Send a response."""

0 commit comments

Comments
 (0)